参照链接:http://blog.csdn.net/bravemelon/article/details/64925499

centOS  下安装 Nginx

yum -y groupinstall "Development Tools"
yum -y install wget
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof .直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html .使用wget命令下载(推荐)。 wget -c https://nginx.org/download/nginx-1.10.1.tar.gz 解压 依然是直接命令: tar -zxvf nginx-1.10..tar.gz
cd nginx-1.10. 配置 .使用默认配置(推荐) ./configure .自定义配置(不推荐) ./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi 注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录 编译安装 make
make install 查找安装路径: whereis nginx 启动、停止nginx cd /usr/local/nginx/sbin/
./nginx [root@ecs---jenjins sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] still could not bind() 问题描述:地址已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。 解决:
kill -
kill -
或者 killall - nginx 从新载入配置文件启动 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 二、修改配置文件 、以下的配置文件没用的都删除 [root@ecs---jenjins conf]# cat nginx.conf #user nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name www.jenjins_1.com;
access_log logs/hongfa1.access.log main;
location / {
root /web/hongfa1;
index index.html index.htm;
}
} server {
listen ;
server_name www.jenjins_2.com;
access_log logs/hongfa3.access.log main;
location / {
root /web/hongfa3;
index index.html index.htm;
}
} server {
listen ;
server_name www.jenjins_3.com;
access_log logs/hongfa3.access.log main;
location / {
root /web/hongfa5;
index index.html index.htm;
}
} } 、没有搭建本地DNS,就配置hosts解析文件,都是一样的效果 [root@ecs---jenjins ~]# cat /etc/hosts
127.0.0.1 ecs---jenjins
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost
117.78.44.225 www.jenjins_1.com
117.78.44.225 www.jenjins_2.com
117.78.44.225 www.jenjins_3.com
117.78.44.225 www.jenjins_4.com 、配置html虚拟机文件 在根目录下创建这几个文件
/web/hongfa4/index.html hongfa4
/web/hongfa5/index.html <h1>www.hongfa2.com</h1>
/web/hongfa1/index.html <h1>www.hongfa1.com</h>
/web/hongfa3/index.html <h1>www.hongfa3.com</h1> 、设置防火墙,把80端口映射到 ,, ,8080不能用,因为nginx首页已经占用,而80 端口要占一个, [root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport -j ACCEPT 这句话非常重要,下面两句可以不执行,要多执行几次
[root@localhost ]# /etc/init.d/iptables save
[root@localhost ]# /etc/init.d/iptables restart ---如果不行,用下面的。
[root@ecs---jenjins hongfa1]# systemctl restart firewalld 至此,主机已可访问虚拟机的nginx服务。 下面可以不执行,好像是,不能访问,执行试试,也可以写到iptables配置文件里 iptables -A INPUT -p tcp -m tcp --dport -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport -j ACCEPT 、开始访问 5.1 http://117.78.44.225:80 www.hongfa1.com 5.2 http://117.78.44.225:8081 hongfa4 5.3 http://117.78.44.225:8083 www.hongfa2.com 5.4 http://117.78.44.225:8084 www.hongfa3.com 三、搭建mysql http://www.jianshu.com/p/95a103add722 Centos 7.2 编译安装 MySQL 5.7. 一、环境准备
、查看系统版本 [root@lnmp ~]# cat /etc/redhat-release
CentOS Linux release 7.2. (Core)
[root@lnmp ~]# uname -r
3.10.-327.28..el7.x86_64 、卸载系统自带的mysql/mariadb数据库及boost旧版本
复制代码
rpm -qa | grep mysql
rpm -qa | grep mariadb
rpm -e --nodeps boost-system-1.53.-.el7.x86_64
rpm -e --nodeps boost-thread-1.53.-.el7.x86_64
rpm -e mariadb-libs-5.5.-.el7_2.x86_64
rpm -e --nodeps mariadb-libs-5.5.-.el7_2.x86_64
boost官网http://www.boost.org/ ,yum -y install boost boost-devel boost-doc安装的是boost1.53版本 、准备安装文件
复制代码
[root@lnmp mysql]# ll
total
drwx------ games Aug : boost_1_59_0
-rw-r--r-- root root Aug boost_1_59_0.tar.gz
drwxr-xr-x Aug : mysql-5.7.
-rw-r--r-- root root Aug : mysql-5.7..tar.gz 说明:mysql5.7系列指定boost版本为boost_1_59_0。
资源下载地址:
[root@snails ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@snails ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz 、依赖包安装
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools 二、安装boost/mysql
、安装boost
tar xvf boost_1_59_0
cd boost_1_59_0
./bootstrap.sh --with-libraries=system,filesystem,log,thread --with-toolset=gcc
./b2 toolset=gcc cxxflags="-std=c++11"
./b2 install --prefix=/usr/local/boost
#备注:上面红色字体的内容,参考如下配置;上面绿色字体内容代表使用c++11标准,编译的库要使用统一标准。不使用,去掉绿色字体内容。
   复制代码
Component configuration:
- atomic : not building
- chrono : not building
- context : not building
- coroutine : not building
- date_time : not building
- exception : not building
- filesystem : building
- graph : not building
- graph_parallel : not building
- iostreams : not building
- locale : not building
- log : building
- math : not building
- mpi : not building
- program_options : not building
- python : not building
- random : not building
- regex : not building
- serialization : not building
- hongfa4nals : not building
- system : building
- test : not building
- thread : building
- timer : not building
- wave : not building #默认安装在/usr/local/lib目录下;头文件在/usr/local/include/boost目录下;install后面可以加参数 --prefix=/usr 来设置安装路径
#如果提示boost版本不对应则卸载boost安装对应版本boost 新建MySQL用户和用户组 [root@snails ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql 预编译 [root@snails ~]# tar -zxvf boost_1_59_0.tar.gz [root@snails data]# md5sum mysql-5.7..tar.gz 8fab75dbcafcd1374d07796bff88ae00 mysql-5.7..tar.gz [root@snails ~]# tar -zxvf mysql-5.7..tar.gz [root@snails data]# mkdir -p /data/mysql [root@snails data]# cd mysql-5.7. [root@snails data]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=../boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DWITH_FEDERATED_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DENABLED_LOCAL_INFILE= \
-DENABLE_DTRACE= \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER= 编译安装 [root@snails mysql-5.7.]# make -j `grep processor /proc/cpuinfo | wc -l`
#编译很消耗系统资源,小内存可能编译通不过make install [root@snails mysql-5.7.]# make install 三、配置mysql
、创建用户,初始化数据库 
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql 、授权mysql数据库目录
chown -R mysql:mysql /usr/local/mysql 、初始化mysql数据库
/usr/local/mysql/bin/mysqld \
--initialize \
--user=mysql \
--datadir=/usr/local/mysql/data/ 、拷贝配置文件,修改配置文件
复制代码,按照下面的修改一下,修改之后无法加载配置文件,没关系,可能编译有问题
cp support-files/my-default.cnf /etc/my.cnf
[root@lnmp ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M
character_set_server=utf8
init_connect='SET NAMES utf8'
#skip-grant-tables
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
#datadir = /usr/local/mysql/data
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
default-character-set=utf8
复制代码 root@ecs---jenjins www.test.com]# source /etc/my.cnf -------------没关系,没有影响
bash: [mysqld]: command not found... 、拷贝启动文件,并授权
、cp support-files/mysql.server /etc/init.d/mysqld
、chmod /etc/init.d/mysqld 、启动数据库
  
/etc/init.d/mysqld start 三、更改初始化生成的数据库密码
注:由于5.7版本会初始化设置密码,需要自己修改,跟之前的数据库版本更改方式不一样。
完整的更改MySQL密码的方式如下: vim /etc/my.cnf 加入skip-grant-tables,免密码登录数据库 [root@ecs---jenjins mysql-5.6.]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M
character_set_server=utf8
init_connect='SET NAMES utf8'
skip-grant-tables -------------加上这句话,免密登陆,登陆完再删掉。
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = ..... # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
default-character-set=utf8 重启MySQL数据库
[root@lnmp ~]# /etc/init.d/mysqld restart ----------或者service mysqld start
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS! 登录数据,修改密码即可,注5.7的password字段改为authentication_string
MySQL
update mysql.user set authentication_string=password('pwd123') where user='root' ; 改完后,注释掉my.cnf里面的skip-grant-tables 这一行,重启MySQL登录验证即可,然后就可以登录数据库进行一些简单的操作了。 [root@lnmp ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Source distribution
Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
rows in set (0.00 sec) 四、授权所有用户登陆
mysql> grant all privileges on *.* to 'root'@'%' identified by 'pwd123';
Query OK, rows affected (0.00 sec)
mysql> flush privileges;
Query OK, rows affected (0.00 sec) 四、安装php7 Centos7 安装 PHP7最新版的详细教程 http://www.jb51.net/article/109228.htm 方法一、简单安装(通过yum) .安装epel-release rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm .安装PHP7的rpm源 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm .安装PHP7 yum install php70w 放法二、编译安装 .下载php7 wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror .解压php7 tar -xvf php7.tar.gz .进入php目录
cd php-7.1./ .安装依赖包 yum install epel-release gcc gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel -y .编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致) 编译前做一下这些,防止出错
[root@ecs---jenjins ~]# cd /usr/local/
[root@ecs---jenjins local]# mkdir php
[root@ecs---jenjins ]# mount
[root@ecs---jenjins ]# umount /run/user//gvfs ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache .正式安装 make && make install 编译最后出现错误:collect2: error: ld returned exit status 解决:
[root@ecs---jenjins php-7.1.]# make ZEND_EXTRA_LIBS='-liconv'
[root@ecs---jenjins php-7.1.]# ln -s /usr/local/lib/libiconv.so. /usr/lib64/
[root@ecs---jenjins php-7.1.]# make && make install .配置环境变量 vi /etc/profile 在末尾追加
export PATH=$PATH:/usr/local/php/bin 执行命令使得改动立即生效
source /etc/profile sed -i '$a\export PATH=$PATH:/usr/local/php/bin' /etc/profile && source /etc/profile .配置php-fpm cp /usr/local/php-7.1./php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 如果报错按照下面做 [root@ecs---jenjins ~]# find / -name php-fpm.conf.default
find: ‘/run/user//gvfs’: Permission denied
[root@ecs---jenjins ]# mount 看最后一行
[root@ecs---jenjins ]# umount /run/user//gvfs cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php-7.1./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm .启动php-fpm /etc/init.d/php-fpm start 错误:
Starting php-fpm [-Aug- ::] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use ()
[-Aug- ::] ERROR: FPM initialization failed
failed 解决方法: netstat -lntup | grep killall php-fpm [root@www ~]# service php-fpm start
Starting php-fpm done 启动成功 下面的错误不用管,没有影响
[root@ecs---jenjins www.test.com]# source /etc/php.ini -----------------不用管,没有影响
bash: [PHP]: command not found...
-bash: /etc/php.ini: line : syntax error near unexpected token `;;'
-bash: /etc/php.ini: line : `;;;;;;;;;;;;;;;;;;;' 五、测试访问 [root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport -j ACCEPT -----------------无法访问就执行这句话
root@localhost ]# /etc/init.d/iptables save
[root@localhost ]# /etc/init.d/iptables restart
[root@ecs---jenjins hongfa1]# systemctl restart firewalld 一、全部删了配置文件,赋值下面的。
root@ecs---jenjins html]# cat /usr/local/nginx/conf/nginx.conf
user root root;
worker_processes ;
events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; server {
listen ;
server_name www.test.com;
charset utf-;
location / {
root /var/www/www.test.com;
index index.php index.html index.htm;
} location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/www.test.com$fastcgi_script_name;
include fastcgi_params;
}
} } [root@ecs---jenjins ~]# mkdir -p /var/www/www.test.com/
[root@ecs---jenjins ~]# cd /var/www/www.test.com/
[root@ecs---jenjins ~]#touch index.php
[root@ecs---jenjins ~]#vi index.php <?php
phpinfo();
?> [root@ecs---jenjins www.test.com]# chown -R /var/www/www.test.com/ [root@ecs---jenjins www.test.com]# vi /etc/hosts 127.0.0.1 ecs---jenjins
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost
117.78.44.225 www.test.com [root@ecs---jenjins www.test.com]# curl http://117.78.44.225/index.php 二、测试mysql连接是否成功 [root@ecs---jenjins ~]# cd /var/www/www.test.com/
[root@ecs---jenjins ~]#touch index.php
[root@ecs---jenjins ~]#vi index.php [root@ecs---jenjins www.test.com]# cat index.php
<?php
$conn=mysqli_connect("127.0.0.1","root","");
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?> [root@ecs---jenjins www.test.com]# curl http://117.78.44.225/index.php
连接mysql数据库成功 报错: 原因: centos php7怎么添加mysql支持 php7可以通过pod_mysql或者mysqli来开启mysql的支持php5中mysql扩展,在php7中已经不支持了。 一、正确做法 <?php
$conn=mysqli_connect("127.0.0.1","root","pwd123"); 注意mysqli_connect 多个i
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?> 错误的 <?php
$conn=mysql_connect("127.0.0.1","root","pwd123"); 注意mysql_connect 少个i
if($conn){
echo "连接mysql数据库成功";
}else{
echo "连接数据库失败";
}
?> 六:上传web网站 http://www.2cto.com/net/201612/577868.html
05-15 21:16