澳门在线威尼斯官方 > 电脑操作 > 【澳门在线威尼斯官方】web服务的安装,8编译安

原标题:【澳门在线威尼斯官方】web服务的安装,8编译安

浏览次数:184 时间:2020-01-01

1.2.7.7  启动服务后查看监听端口

netstat -lntup|grep 80

lsof -i :80

7.4、修改网页测试内容

 

[root@webserver ~]# cd /var/www/html/
[root@webserver html]# ll
total 12
drwxr-xr-x 2 www www 4096 Dec 18 13:36 web1
drwxr-xr-x 2 www www 4096 Dec 18 13:43 web2
drwxr-xr-x 2 www www 4096 Dec 18 13:44 web3
[root@webserver html]# 
[root@webserver html]# cat web1/index.php 
<?php
echo "web1";
phpinfo();
?>
[root@webserver html]# cat web1/index.php >web2/index.php 
[root@webserver html]# cat web1/index.php >web3/index.php 
[root@webserver html]# sed -i 's/web1/web2/' web2/index.php 
[root@webserver html]# sed -i 's/web1/web3/' web3/index.php
[root@webserver html]# cat web2/index.php 
<?php
echo "web2";
phpinfo();
?>
[root@webserver html]# cat web3/index.php 
<?php
echo "web3";
phpinfo();
?>
[root@webserver html]# 

 

3.1.2 检查端口及启动情况

[root@web01 ~]# netstat -lntup |egrep "3306|80"

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      51971/mysqld       

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      50047/nginx

3.10、全库备份脚本

 

vim /root/all_backup_db.sh
#!/bin/bash
'/usr/local/mysql/bin/mysqldump -uroot -p'mysql2017pwd' -P3312 -R -E --triggers -e --max_allowed_packet=16777216 --net_buffer_length=16384  --master-data=2 --single-transaction --all-databases --quick | gzip >/root/all_database_bak_`date +%Y-%m-%d_%H_%M_%S`.sql.gz'

 

4.1 第一步配置Nginx与PHP的关联

cd /application/nginx/conf/extra

vim blog.conf

server {

        listen       80;

        server_name  blog.chrishg.net;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

#添加以下这一段代码

        location ~ .*.(php|php5)?$ {

            root   html/blog;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

    }

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

1.7、时间同步服务

cat >/root/ntp.sh <<EOF
#!/bin/bash
# ntp.sh
#NTP服务器数组列表
ntpServer=(
[0]=1.cn.pool.ntp.org
[1]=2.cn.pool.ntp.org
[2]=3.cn.pool.ntp.org
[3]=0.cn.pool.ntp.org
)

#校验#
serverNum=`echo ${#ntpServer[*]}`
NUM=0
for ((i=0; i<=$serverNum; i++)); do
    echo -n "正在和NTP服务器:${ntpServer[$NUM]}校验中..."
    /usr/sbin/ntpdate ${ntpServer[$NUM]} >> /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo -e "e[1;32mt[成功]e[0m"
        echo -e "e[1;32m同步成功,退出......e[0m"
        break
    else
        echo -e "e[1;31mt[失败]e[0m"
        echo -e "e[1;31m继续同步下一个!!!!!e[0m"
        let NUM++
    fi
    sleep 2
done
EOF
chmod +x /root/ntp.sh
sh /root/ntp.sh

2.14.1 设置密码、登陆、改密码

mysqladmin -uroot password "123456"  #设置密码

mysql -uroot -p123456              #用密码登陆

mysqladmin -uroot -p123456 password 654321   #改密码

2.1、下载源码包

# 上Nginx官网,复制最新稳定版的下载地址过来,然后用wget下载
cd /usr/local/src
wget https://nginx.org/download/nginx-1.12.2.tar.gz
[root@webserver ~]# cd /usr/local/src
[root@webserver src]# wget https://nginx.org/download/nginx-1.12.2.tar.gz

1.2.7.11    配置nginx配置文件

egrep -v "^$|#" nginx.conf.default >nginx.conf

1.2、防火墙设置

 

cp /etc/sysconfig/iptables /root/iptables.bak
cat >/etc/sysconfig/iptables <<EOF 
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
# 重启
/etc/init.d/iptables  restart

 

3.1.7 安装libmcrypt 库

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum install libmcrypt-devel -y

3.5、创建my.cnf配置文件

 

# 排除干扰因素
if [ -f "/etc/my.cnf" ]; then
    mv /etc/my.cnf /etc/my.cnf.bak
fi

cat > /usr/local/mysql/my_3310.cnf <<EOF
[client]
port = 3310
socket=/usr/local/mysql/mysqld_3310.sock
#character_set_server = utf8
#default-character-set = utf8mb4
#default-character-set = utf8

[mysqld]
basedir=/usr/local/mysql
datadir=/home/data/mysql_3310/
socket=/usr/local/mysql/mysqld_3310.sock
user = mysql
port = 3310

#character_set_server = utf8mb4
#init-connect = 'SET NAMES utf8'
character_set_server = utf8
init-connect = 'SET NAMES utf8'

#skip-name-resolve
#skip-networking
back_log = 512

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 1024
max_allowed_packet = 32M
binlog_cache_size = 32M
max_heap_table_size = 32M
tmp_table_size = 32M

read_buffer_size = 8M
read_rnd_buffer_size =32M
sort_buffer_size = 16M
join_buffer_size = 16M
key_buffer_size = 16M

thread_cache_size = 256

query_cache_type = 0
query_cache_size = 0
#query_cache_limit = 2M

server_id = 1503310
log-bin = /home/data/mysql_3310/mysql-bin
log_bin_index = /home/data/mysql_3310/binlog.index
binlog_format = row
expire_logs_days = 60

lower_case_table_names = 1
#binlog_ignore_db = mysql
#replicate-do-db = mysql
sql_mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"

performance_schema = 0
explicit_defaults_for_timestamp=1

log_error = /home/data/mysql_3310/err_mysql_3310.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /home/data/mysql_3310/mysql-slow.log

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 1024
innodb_buffer_pool_size = 2G
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


[mysql.server]
character_set_server = utf8
socket=/usr/local/mysql/mysqld_3310.sock

[mysqld_safe]
log-error=/home/data/mysql_3310/err_mysql_3310.log
pid-file=/home/data/mysql_3310/mysql_3310.pid
character_set_server = utf8

[mysql]
socket=/usr/local/mysql/mysqld_3310.sock
default-character-set = utf8

[mysqldump]
socket=/usr/local/mysql/mysqld_3310.sock
default-character-set = utf8
[mysqladmin]
socket=/usr/local/mysql/mysqld_3310.sock
character_set_server = utf8" 
EOF

 

# 具体执行如下
[root@webserver mysql-5.7.20]# rm -rf /etc/my.cnf
[root@webserver mysql-5.7.20]# cat /usr/local/mysql/my_3310.cnf
[client]
port = 3310
socket=/usr/local/mysql/mysqld_3310.sock
#character_set_server = utf8
#default-character-set = utf8mb4
#default-character-set = utf8

[mysqld]
basedir=/usr/local/mysql
datadir=/home/data/mysql_3310/
socket=/usr/local/mysql/mysqld_3310.sock
user = mysql
port = 3310

#character_set_server = utf8mb4
#init-connect = 'SET NAMES utf8'
character_set_server = utf8
init-connect = 'SET NAMES utf8'

#skip-name-resolve
#skip-networking
back_log = 512

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 1024
max_allowed_packet = 32M
binlog_cache_size = 32M
max_heap_table_size = 32M
tmp_table_size = 32M

read_buffer_size = 8M
read_rnd_buffer_size =32M
sort_buffer_size = 16M
join_buffer_size = 16M
key_buffer_size = 16M

thread_cache_size = 256

query_cache_type = 0
query_cache_size = 0
#query_cache_limit = 2M

server_id = 1503310
log-bin = /home/data/mysql_3310/mysql-bin
log_bin_index = /home/data/mysql_3310/binlog.index
binlog_format = row
expire_logs_days = 60

lower_case_table_names = 1
#binlog_ignore_db = mysql
#replicate-do-db = mysql
sql_mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"

performance_schema = 0
explicit_defaults_for_timestamp=1

log_error = /home/data/mysql_3310/err_mysql_3310.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /home/data/mysql_3310/mysql-slow.log

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 1024
innodb_buffer_pool_size = 2G
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


[mysql.server]
character_set_server = utf8
socket=/usr/local/mysql/mysqld_3310.sock

[mysqld_safe]
log-error=/home/data/mysql_3310/err_mysql_3310.log
pid-file=/home/data/mysql_3310/mysql_3310.pid
character_set_server = utf8

[mysql]
socket=/usr/local/mysql/mysqld_3310.sock
default-character-set = utf8

[mysqldump]
socket=/usr/local/mysql/mysqld_3310.sock
default-character-set = utf8
[mysqladmin]
socket=/usr/local/mysql/mysqld_3310.sock
character_set_server = utf8" 
[root@webserver mysql-5.7.20]# 

第3章 安装PHP服务

3.9、mysql快捷登陆方式

 

# 快捷登陆方式 
alias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &'
alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin -uroot -p'mysql2017pwd' shutdown'
alias mysql.3310.login='/usr/local/mysql/bin/mysql -uroot -p'mysql2017pwd''


cat >>/root/.bashrc <<EOF
alias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &'
alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin -uroot -p'mysql2017pwd' shutdown'
alias mysql.3310.login='/usr/local/mysql/bin/mysql -uroot -p'mysql2017pwd''
EOF

source  /root/.bash_profile

[root@webserver mysql-5.7.20]# # 快捷登陆方式 
[root@webserver mysql-5.7.20]# alias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &'
[root@webserver mysql-5.7.20]# alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin -uroot -p'mysql2017pwd' shutdown'
[root@webserver mysql-5.7.20]# alias mysql.3310.login='/usr/local/mysql/bin/mysql -uroot -p'mysql2017pwd''
[root@webserver mysql-5.7.20]# alias mysql.3310.all_dump='/usr/local/mysql/bin/mysqldump -uroot -p'mysql2017pwd' -P3312 -R -E --triggers -e --max_allowed_packet=16777216 --net_buffer_length=16384  --master-data=2 --single-transaction --all-databases --quick | gzip >/root/all_database_bak_`date +%Y-%m-%d_%H_%M_%S`.sql.gz'

[root@webserver mysql-5.7.20]# cat /root/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
alias nginx.start='/usr/sbin/nginx'
alias nginx.stop='/usr/sbin/nginx -s stop'
alias nginx.reload='/usr/sbin/nginx -s reload'
alias nginx.config_test='/usr/sbin/nginx -t'
alias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &'
alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin -uroot -p'mysql2017pwd' shutdown'
alias mysql.3310.login='/usr/local/mysql/bin/mysql -uroot -p'mysql2017pwd''
[root@webserver mysql-5.7.20]# 
[root@webserver mysql-5.7.20]# source  /root/.bash_profile 

 

4.1.2 第二步:测试PHP与mysql是否连接成功

cd /application/nginx/html/blog/

在这个目录里代添测试文件

vim test_mysql.php

<?php

        $link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();

        if($link_id){

                echo "mysql successful by oldboy !";

        }else{

                echo mysql_error();

        }

?>

2.2、编译安装

 

tar xvf nginx-1.12.2.tar.gz
cd /usr/local/src/nginx-1.12.2
./configure 
--prefix=/usr/local/nginx 
--sbin-path=/usr/sbin/nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/home/log/nginx/error.log 
--http-log-path=/home/log/nginx/access.log 
--pid-path=/var/run/nginx.pid 
--lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/home/tmp/nginx/client 
--http-proxy-temp-path=/home/tmp/nginx/proxy 
--http-fastcgi-temp-path=/home/tmp/nginx/fcgi 
--http-uwsgi-temp-path=/home/tmp/nginx/uwsgi 
--http-scgi-temp-path=/home/tmp/nginx/scgi 
--user=nginx 
--group=nginx 
--with-pcre 
--with-http_v2_module 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_addition_module 
--with-http_sub_module 
--with-http_dav_module 
--with-http_flv_module 
--with-http_mp4_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_random_index_module 
--with-http_secure_link_module 
--with-http_stub_status_module 
--with-http_auth_request_module 
--with-mail 
--with-mail_ssl_module 
--with-file-aio 
--with-http_v2_module 
--with-threads 
--with-stream 
--with-stream_ssl_module

 

#  完成后执行编译:
#  make && make install
make -j `grep processor /proc/cpuinfo | wc -l` 
make -j `grep processor /proc/cpuinfo | wc -l`  install

5.2.2 nginx配置文件中添加如下

server {

        listen       80;

        server_name  blog.chrishg.net;

            root   html/blog;

            index  index.php index.html index.htm;

        location / {

        if (-f $request_filename/index.html){

            rewrite (.*) $1/index.html break;

         }

        if (-f $request_filename/index.php){

            rewrite (.*) $1/index.php;

         }

        if (!-f $request_filename){

            rewrite (.*) /index.php;

         }

        }

        location ~ .*.(php|php5)?$ {

            root   html/blog;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

}



注:以下这行,也可以实现以上多行的功能

 try files $url/  /index.php?q=$uri%args;

4.6、添加nginx对fastcgi的支持

# 首先备份默认的配置文件。
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
rm -rf /etc/nginx/nginx.conf
cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

[root@webserver ~]# cat  /etc/nginx/nginx.conf
user  www;
worker_processes  8;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [] "$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  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8123;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html;
            index index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
       # location ~ .php$ {
       #     #root           html;
       #    try_files      $uri =404;
       #   fastcgi_pass   127.0.0.1:9000;
       #   fastcgi_index  index.php;
       #   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       #   include        fastcgi_params;
       #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
##################################
server{
     charset utf-8;
     listen 80;
        server_name localhost;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        index index.php index.html index.htm ;
     location / {
            root /var/www/html/;
            #    allow 172.16.100.12;
            #   deny all;
                         }
    location ~ .php$ {
            root           /var/www/html/;
            try_files      $uri =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
##################################
}
[root@webserver ~]# 

5.1.3 hosts解释,浏览安装博客

浏览器输入网址:

澳门在线威尼斯官方 1

配置***

mysql -uwordpress -p123456

use wordpress;

show tables;

7.2.3、web3的配置

 

[root@webserver html]# cat web3 
server{
     charset utf-8;
     listen 80;
        server_name localhost;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        index index.php index.html index.htm ;
     location / {
            root /var/www/html/web3/;
            #   allow 172.16.100.12;
            #  deny all;
                         }
    location ~ .php$ {
            root           /var/www/html/web3;
            try_files      $uri =404;
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
[root@webserver html]# 

 

1.2.7 开始编译安装nginx

7.2、在/usr/local/nginx/html/目录下创建子配置文件

 

[root@webserver html]# pwd
/usr/local/nginx/html
[root@webserver html]# ll
total 12
-rw-r--r-- 1 www www 1028 Dec 18 12:03 web1
-rw-r--r-- 1 www www 1028 Dec 18 13:42 web2
-rw-r--r-- 1 www www 1028 Dec 18 13:42 web3
[root@webserver html]# 

 

6.1.1 一键安装mysql脚本 (在独立数据库安装好mysql)

#创建用户

useradd -s /sbin/nologin mysql -M

#创建目录、解压、授权

cd /home/chrishg/tools

tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz

mkdir /application/

mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49

ln -s /application/mysql-5.5.49 /application/mysql

chown -R mysql.mysql /application/mysql/data/

#初始化数据库

cd /application/mysql/

./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

#复制配置文件

cp /application/mysql/support-files/my-small.cnf /etc/my.cnf

cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld

#替换配置路径

sed -i  's#/usr/local/#/application/#g'  /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

#授权配置文件

chmod +x /etc/init.d/mysqld

#配置环境变量

PATH="/application/mysql/bin/:$PATH"

echo 'PATH="/application/mysql/bin/:$PATH"' >>/etc/rc.local

#启动并查端口

/etc/init.d/mysqld start

lsof -i :3306

netstat -lntup |grep 3306

3.2、数据库存放目录及权限修改

 

mkdir -p /home/data/mysql
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin mysql
id mysql
# 更改数据目录权限。
chown -R mysql:mysql /home/data/mysql

[root@webserver ~]# mkdir -p /home/data/mysql
[root@webserver ~]# groupadd -r mysql
[root@webserver ~]# useradd -r -g mysql -s /sbin/nologin mysql
[root@webserver ~]# id mysql
uid=497(mysql) gid=497(mysql) groups=497(mysql)
[root@webserver ~]# chown -R mysql:mysql /home/data/mysql

 

第6章 LNMP组件分离

我们这里的IP地址是:172.16.1.51  db01

2.3、创建相应的目录

 

mkdir -p /home/tmp/nginx/client
mkdir -p /home/log/nginx
chmod 777 /home/tmp/
chmod 777 /home/log/
[root@webserver nginx-1.12.2]# mkdir -p /home/tmp/nginx/client
[root@webserver nginx-1.12.2]# mkdir -p /home/log/nginx
[root@webserver nginx-1.12.2]# chmod 777 /home/tmp/
[root@webserver nginx-1.12.2]# chmod 777 /home/log/

 

1.2.7.14     单网卡多IP

 server {

        listen       10.0.0.102:80;

        server_name  bbs.chrishg.net;

        location / {

            root   html/bbs;

            index  index.html index.htm;

1.6、Centos最小化安装推荐常用依赖包

#    Centos最小化安装推荐常用依赖包
yum  clean all
yum -y update
yum -y install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel wget telnet   
yum -y install curl-devel libxslt-devel pcre-devel libjpeg libpng libcurl4-openssl-dev 
yum -y install libcurl-devel libcurl freetype-config freetype freetype-devel unixODBC libxslt 
yum -y install gcc automake autoconf libtool openssl-devel bison vim gcc-g77
yum -y install perl-devel perl-ExtUtils-Embed libcurl-devel.x86_64 zip unzip
yum -y install cmake ncurses-devel.x86_64  openldap-devel.x86_64 lrzsz  openssh-clients    
yum -y install libmcrypt libmcrypt-devel mhash mhash-devel bzip2 bzip2-devel
yum -y install ntpdate rsync svn  patch  iptables iptables-services
yum -y install libevent libevent-devel  cyrus-sasl cyrus-sasl-devel libcurl.x86_64
yum -y install gd-devel libmemcached-devel memcached git libssl-devel libyaml-devel auto make
yum -y install gcc.x86_64 libxml2.x86_64 libxml2-devel.x86_64 openssl.x86_64 openssl-devel.x86_64   
yum -y install gd.x86_64 gd-devel.x86_64  gcc-c++.x86_64 readline.x86_64 readline-devel.x86_64 
yum -y groupinstall "Server Platform Development" "Development tools"
yum -y groupinstall "Development tools" 

2.12 查看错误日志

/application/mysql/data/ 机器名.err   如:

cat /application/mysql/data/web01.err

4.5、创建web存放目录

useradd -s /sbin/nologin -M www
mkdir -p /var/www/html/
chown -R www.www/var/www/html/
chmod -R 775 /var/www/html/

2.6 主机名要做解释

在cat /etc/hosts 文件里添加解释:

172.16.1.8      web01

1.1、关闭SELINUX

# 修改配置文件,重启服务后永久生效。

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 命令行设置立即生效

setenforce 0

[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

[root@localhost ~]# setenforce 0

[root@localhost ~]# 

6.2.1 创建跟web01上nginx使用一样的系统用户www

useradd -u 503  www

id www

Centos 6.8编译安装LNMP环境

参考资料:

http://www.jb51.net/article/107429.htm

https://phperzh.com/articles/1360

2.13 错误排查

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

上面问题有3种可能原因及其解决方法如下:

1、删除并重新初始化数据库,出现此问题一般都是因为数据库初始货有问题,

2、或者是MySQL数据文件损坏了,也可能是MySQL数据目录权限有问题。

3、检查主机名对应主机IP解析是否正确。

MySQL安装完成后,默认情况下,管理员账号root是无密码的,这个必须设置。

show databases;      #查看当前所有数据库

select user();       #查看当前的登录用户

七、多路径配置测试

1.2.7.17    检查配置文件语法

/application/nginx/sbin/nginx  -t

3.8、登陆修改默认账号

 

#  登陆后修改默认账号
/usr/local/mysql/bin/mysql
alter user 'root'@'localhost' identified by 'mysql2017pwd';
delete from mysql.user where Host='::1';
delete from mysql.user where Host='localhost.localdomain';
delete from mysql.user where User='';
flush privileges;
exit;

[root@webserver mysql-5.7.20]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.20-log Source distribution

Copyright (c) 2000, 2017, 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> alter user 'root'@'localhost' identified by 'mysql2017pwd';
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where Host='::1';
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where Host='localhost.localdomain';
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where User='';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye
[root@webserver mysql-5.7.20]# 

 

1.2.7.9  查看nginx的版本

[root@web01 ~]# ls /application/

nginx  nginx-1.6.3

[root@web01 ~]# /application/nginx/sbin/nginx  -V

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)

TLS SNI support enabled

configure arguments: --user=www --group=www --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module

5.1、多路径配置

 

在vim /etc/nginx/nginx.conf 增加如下内容
include  vhosts/*;

环境:

系统:CentOS6.5 

软件:nginx-1.6.3     mysql-5.5.49    php-5.5.32

 

3.4、修改目录权限

 

chown -R mysql:mysql /usr/local/mysql/
[root@webserver mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/

 

6.2.5 备份共亨目录里的文件再挂载

cd /application/nginx/html/blog/wp-content/uploads

mv 2016 /tmp

mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/

echo " mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/" >> /etc/rc.local

cp -a /tmp/2016/ /application/nginx/html/blog/wp-content/uploads

3.3、下载解压安装

下载并解压编译官网下载的稳定版的源码包。在下载的时候注意一下版本,下载对应的版本。我们源码编译,要下载长这样的安装包:同时在安装的时候我们需要boost库,5.7需要1.59版本的库;你可以下载boost库然后编译boost库,或者像我一样,下载带有boost库的mysql版本,再开始解压编译。

 

################# 报错处理说明开始################
## 报错信息,原因是网络问题,导致无法下载boost_1_59_0.tar.gz,可以手工下载,
# 然后拷贝到对应的目录下,重新解压mysql,进入目录编译
#  -- Packaging as: mysql-5.7.20-Linux-x86_64
#  -- Downloading boost_1_59_0.tar.gz to /usr/local/mysql/boost/boost_1_59_0
#  -- Download failed, error: 22;"HTTP response code said error"
#  CMake Error at cmake/boost.cmake:194 (MESSAGE):
#    You can try downloading
#    http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
#    manually using curl/wget or a similar tool
#  Call Stack (most recent call first):
#    CMakeLists.txt:491 (INCLUDE)
#  [root@php1 ~]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
#  [root@php1 ~]# cp boost_1_59_0.tar.gz /usr/local/mysql/boost/boost_1_59_0/
#  [root@php1 ~]# ll /usr/local/mysql/boost/boost_1_59_0/
#  total 81756
#  drwx------ 8 mysql mysql     4096 Dec  8 10:04 boost_1_59_0
#  -rw-r--r-- 1 mysql mysql 83709983 Dec  8 10:04 boost_1_59_0.tar.gz
#  [root@php1 ~]# 
cd /usr/local/mysql/boost/boost_1_59_0/
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
# cp boost_1_59_0.tar.gz /usr/local/mysql/boost/boost_1_59_0 
cd /usr/local/src/
rm -rf mysql-5.7.20/
tar xvf mysql-boost-5.7.20.tar.gz -C /usr/local/src
cd /usr/local/src/mysql-5.7.20
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/home/data/mysql_3310  
-DSYSCONFDIR=/etc 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_READLINE=1 
-DWITH_SSL=system 
-DWITH_ZLIB=system 
-DWITH_LIBWRAP=0 
-DMYSQL_TCP_PORT=3310 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld_3310.sock 
-DDEFAULT_CHARSET=utf8 
-DWITH_EXTRA_CHARSETS=all 
-DDEFAULT_COLLATION=utf8_general_ci 
-DDOWNLOAD_BOOST=1 
-DWITH_BOOST=/usr/local/mysql/boost/boost_1_59_0 

#  make && make install
make -j `grep processor /proc/cpuinfo | wc -l` &&
make -j `grep processor /proc/cpuinfo | wc -l`  install
#  参考资料: https://my.oschina.net/Kilar/blog/540856

################# 报错处理说明结束################

 

cd /usr/local/src/
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
tar xvf mysql-boost-5.7.20.tar.gz -C /usr/local/src
cd /usr/local/src/mysql-5.7.20
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/home/data/mysql 
-DSYSCONFDIR=/etc 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_READLINE=1 
-DWITH_SSL=system 
-DWITH_ZLIB=system 
-DWITH_LIBWRAP=0 
-DMYSQL_TCP_PORT=3310 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld_3310.sock 
-DDEFAULT_CHARSET=utf8 
-DWITH_EXTRA_CHARSETS=all 
-DDEFAULT_COLLATION=utf8_general_ci 
-DDOWNLOAD_BOOST=1 
-DWITH_BOOST=/usr/local/mysql/boost/boost_1_59_0 

#  make && make install
make -j `grep processor /proc/cpuinfo | wc -l` 
make -j `grep processor /proc/cpuinfo | wc -l`  install
#  参考资料: https://my.oschina.net/Kilar/blog/540856

1.2.7.8  测试结果:

windows下连接输入 

linux下可以用 wget 127.0.0.1显示200K就是正常的。

[root@web01 conf]# wget 127.0.0.1

--2016-08-26 03:28:39--  http://127.0.0.1/

Connecting to 127.0.0.1:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 4 [text/html]

Saving to: “index.html”



100%[======================================>] 4           --.-K/s   in 0s     



2016-08-26 03:28:39 (630 KB/s) - “index.html” saved [4/4]

4.1、到官网下载源码包后,开始编译安装

 

cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.2.0.tar.bz2
tar -xvf php-7.2.0.tar.bz2 -C /usr/local/src
cd /usr/local/src/php-7.2.0
# 执行下面的配置文件:
./configure --prefix=/usr/local/php 
--with-config-file-scan-dir=/etc/php.d 
--with-config-file-path=/etc 
--with-mysqli=/usr/local/mysql/bin/mysql_config 
--enable-fpm 
--enable-opcache 
--disable-fileinfo 
--with-jpeg-dir 
--with-iconv-dir=/usr/local 
--with-freetype-dir 
--with-png-dir 
--with-zlib 
--with-libxml-dir=/usr 
--enable-xml 
--enable-bcmath 
--enable-shmop 
--enable-exif 
--with-curl 
--enable-sysvsem 
--enable-inline-optimization 
--enable-mbregex 
--enable-inline-optimization 
--enable-mbstring 
--with-gd 
--with-openssl 
--with-mhash 
--enable-pcntl 
--enable-sockets 
--with-xmlrpc 
--enable-ftp 
--with-gettext 
--enable-zip 
--enable-soap 
--with-bz2

make -j `grep processor /proc/cpuinfo | wc -l`  
make -j `grep processor /proc/cpuinfo | wc -l`  install

 

# 执行以上的配置,如果出现下面这样的license,才是正确的,才可以开始编译,如果出问题,就解决,一般是少了什么库。
# 执行编译:configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
# collect2: ld returned 1 exit status
# make: *** [sapi/cli/php] Error 1
# make && make install

#  出现上述错误的解决办法: 
#  参考资料: http://www.ithov.net/linux/1127.html
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
make ZEND_EXTRA_LIBS='-liconv' 
make install 

#make -j `grep processor /proc/cpuinfo | wc -l`  &&
#make -j `grep processor /proc/cpuinfo | wc -l`  install
# make test


[root@webserver ~]# cd /usr/local/src/
[root@webserver src]# wget http://cn2.php.net/distributions/php-7.2.0.tar.bz2
[root@webserver src]# tar -xvf php-7.2.0.tar.bz2 -C /usr/local/src
[root@webserver src]# cd /usr/local/src/php-7.2.0
[root@webserver php-7.2.0]# ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --enable-opcache --disable-fileinfo --with-jpeg-dir --with-iconv-dir=/usr/local --with-freetype-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-exif --with-curl --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-inline-optimization --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --with-bz2
[root@webserver php-7.2.0]# ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
[root@webserver php-7.2.0]# make ZEND_EXTRA_LIBS='-liconv' 

3.2.2.2  防止make报错先创建以下文件

touch ext/phar/phar.phar

如果在PHP编译时使用--with-mysql=mysqlnd替代--with-mysql=/application/mysql则没有上述2点的错误发生。

make    #说明如果在物理机多核可以用make -j 8  指定核心数

make install

四、安装php-fpm

6.1.3 在db01机器上创建用户密码、解压备份的数据并还原到数据库

mysqladmin -uroot password 123456

cd /tmp

gzip -d bak.sql.gz

mysql -uroot -123456 </tmp/bak.sql   #还原



mysql -uroot -123456 -e "show datablwes like 'wordpress';"     #还原后查看

mysql -uroot -123456   #登录数据库

grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';

flush privileges;

#创建wordpress数据管理员并刷新

select user,host from mysql.user;   #查看用户表

4.2、添加php和php-fpm配置文件

cp  /usr/local/src/php-7.2.0/php.ini-production /etc/php.ini  
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf

 

第2章 mysql二进制包的安装

4.4、添加php-fpm至服务列表并设置开机自启

chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on

Nginx增加错误日志(error_log)配置

日志记录属于核心功能模块(ngx_core_module)的参数,该参数名字是error.log,针对自己来说最好定义在Main全局区块中,当然也可以放置不同的虚拟主机中单独记录。

error_log    file    level[debug|info|notice|warn|error|crit|alert|emerg];

关键字    日志文件  错误日志级别

error_log默认配置:

#default:error_log logs/error.log error;

可以放置的标签段:

#context:main,http,server,location

3.7、启动数据库

 

#  启动数据库
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &
ps -ef| grep -v 'grep' | grep mysql

[root@webserver mysql-5.7.20]# #  启动数据库
[root@webserver mysql-5.7.20]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &
[1] 4774
[root@webserver mysql-5.7.20]# ps -ef| grep -v 'grep' | grep mysql
root      4773  1665  0 17:31 pts/1    00:00:00 tail -f /home/data/mysql_3310/err_mysql_3310.log
root      4774  1625  0 17:32 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf
[root@webserver mysql-5.7.20]# 
[root@webserver mysql-5.7.20]# 2017-12-15T09:33:00.906941Z mysqld_safe Logging to '/home/data/mysql_3310/err_mysql_3310.log'.
2017-12-15T09:33:00.966304Z mysqld_safe Starting mysqld daemon with databases from /home/data/mysql_3310

[root@webserver mysql-5.7.20]# ps -ef| grep -v 'grep' | grep mysql
root      4773  1665  0 17:31 pts/1    00:00:00 tail -f /home/data/mysql_3310/err_mysql_3310.log
root      4774  1625  0 17:32 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf
mysql     5590  4774  2 17:33 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my_3310.cnf --basedir=/usr/local/mysql --datadir=/home/data/mysql_3310 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/home/data/mysql_3310/err_mysql_3310.log --open-files-limit=65535 --pid-file=/home/data/mysql_3310/mysql_3310.pid --socket=/usr/local/mysql/mysqld_3310.sock --port=3310
[root@webserver mysql-5.7.20]# 

 

2.10 设置环境变量

PATH="/application/mysql/bin/:$PATH"

[root@web01 bin]# echo $PATH

/application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@web01 bin]# which mysql

/application/mysql/bin/mysql

编辑vim /etc/profile

添加PATH="/application/mysql/bin/:$PATH" 到最后,实现环境变量永久生效

. /etc/profile    #添加完后重读配置文件。

4.3、添加php-fpm启动脚本

 

cp /usr/local/src/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

 

3.2.2.1  防止编译报错。

方法一: (5.3版本有共享库的报错)

ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/

方法二:找出这个文件将路径添加到 /etc/ld.so.conf

find /  -name "libmysqlclient.so.18"

/application/mysql-5.5.49-linux2.6-x86_64/lib/libmysqlclient.so.18

vim /etc/ld.so.conf

添加内容如下:

/application/mysql/lib/

然后用以下命令保存:

ldconfig

7.5、访问网页

澳门在线威尼斯官方 2

澳门在线威尼斯官方 3

澳门在线威尼斯官方 4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[root@webserver ~]# cat /etc/nginx/nginx.conf

user  www;

worker_processes  8;

 

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

#pid        logs/nginx.pid;

 

 

events {

    worker_connections  1024;

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    #log_format  main  '$remote_addr - $remote_user [] "$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  0;

    keepalive_timeout  65;

 

    #gzip  on;

 

    server {

        listen       8123;

        server_name  localhost;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        location / {

            root   /usr/local/nginx/html;

            index index.php index.html index.htm;

        }

 

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

 

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ .php$ {

        #    proxy_pass   ;

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

       # location ~ .php$ {

       #     #root           html;

       #    try_files      $uri =404;

       #   fastcgi_pass   127.0.0.1:9000;

       #   fastcgi_index  index.php;

       #   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

       #   include        fastcgi_params;

       #}

 

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /.ht {

        #    deny  all;

        #}

    }

 

 

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

 

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

 

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

 

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

##################################

server{

     charset utf-8;

     listen 80;

        server_name localhost;

        autoindex on;

        autoindex_exact_size off;

        autoindex_localtime on;

        index index.php index.html index.htm ;

     location / {

            root /var/www/html/;

            #    allow 58.71.118.58;

            #    allow 116.93.118.106;

            #    allow 203.192.188.54;

            #    allow 119.93.245.137;

            #    allow 119.93.247.77;

            #    allow 203.192.160.250;

            #    allow 112.199.70.114;

            #    allow 112.199.70.113;

            #    allow 122.54.195.193;

            #    allow 119.93.241.250;

            #   deny all;

                         }

    location ~ .php$ {

            root           /var/www/html/;

            try_files      $uri =404;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

    }

##################################

include  /usr/local/nginx/html/*;

}

[root@webserver ~]# 

6.2 从web01上共亨目录挂载到nfs

机器IP:172.16.1.31  nfs01

二、安装mysql

3.2.5 启动PHP服务(FastCGI方式)

/application/php/sbin/php-fpm

ps -ef |grep php-fpm

lsof -i :9000

7.3、测试nginx的配置是否正确

 

[root@webserver html]# nginx.config_test 
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@webserver html]# 

 

Nginx访问日志(access_log)

此功能由ngx_http_log_module模块负责

控制日志的参数
参数 说明
log_format 用来定义记录日志的格式(可以定义多种日志格式,取不同的名字即可)
access_log 用来指定日志文件的路径及使用何种日志格式记录日志
Nginx日志变量说明
Nginx日志变量 说明
$remote_addr 记录访问网站的客户端地址

$http_x_forwarded_for

当前端有代理服务器时,设置Web节点记录客户端地址的配置,此参数生效的前提是代理服务器上也进行了相关的x_forwarded_for设置
$remote_user 远程客户端名称
$time_local 记录访问时间与时区
$request 用户的http请求起始行信息
$status http状态码,记录请求返回的状态,例如200,404,301
$body_bytes_sents 服务器发送给客户端的响应body字节数
$http_referer 记录此次请求是从哪个链接访问过来的,可以根据referer进行防盗链设置
$http_user_agent 记录客户端访问信息,例如浏览器手机客户端等

 

buffer=size            #存放访问日志的缓冲区大小

flush=time             #将缓冲区的日志刷到磁盘的时间

gzip[=level]              #表示压缩级别

[if=condition]           #表示其他条件(一般的场景中这些都无需配置,极端优化                                                              #时才可能会考虑这些参数)

默认的配置:

access_log    logs/access.log     combined;

日志内容配置:

log_format main '$remote_addr - $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

1.5、修改dns

#  修改dns
cat >/etc/resolv.conf <<EOF
nameserver 172.16.110.11
nameserver 8.8.8.8
EOF

[root@webserver ~]# cat >/etc/resolv.conf <<EOF
> nameserver 172.16.110.11
> nameserver 8.8.8.8
> EOF
[root@webserver ~]# 

6.1.4 更改web01配置文件

cd /application/nginx/html/blog/

vim wp-config.php

修改第32行

sed -i 's#DB_HOST', 'localhost#DB_HOST', '172.16.1.51#g' wp-config.php

7.2.1、web1的配置

 

[root@webserver html]# cat web1 
server{
     charset utf-8;
     listen 80;
        server_name localhost;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        index index.php index.html index.htm ;
     location / {
            root /var/www/html/web1/;
            #   allow172.16.100.12;
            #  deny all;
                         }
    location ~ .php$ {
            root           /var/www/html/web1;
            try_files      $uri =404;
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
[root@webserver html]# 

2.8 启动数据库并查看端口

/application/mysql/bin/mysqld_safe --user=mysql &

lsof -i :3306

netstat -lntup |grep 3306

1.4、修改网卡ip信息

cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.16.210.126
NETMASK=255.255.255.0
GATEWAY=172.16.210.250
EOF

#  重启网卡服务
/etc/init.d/network restart

2.9 默认登录mysql

 [root@web01 bin]# /application/mysql/bin/mysql

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 1

Server version: 5.5.49 MySQL Community Server (GPL)



Copyright (c) 2000, 2016, 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>            #这样代表成功安装了

2.5、设置nginx快捷方式

 

alias nginx.start='/usr/sbin/nginx'
alias nginx.stop='/usr/sbin/nginx -s stop'
alias nginx.reload='/usr/sbin/nginx -s reload'
alias nginx.config_test='/usr/sbin/nginx -t'

cat >>/root/.bashrc <<EOF
alias nginx.start='/usr/sbin/nginx'
alias nginx.stop='/usr/sbin/nginx -s stop'
alias nginx.reload='/usr/sbin/nginx -s reload'
alias nginx.config_test='/usr/sbin/nginx -t'

EOF
cat /root/.bashrc
source  /root/.bash_profile 

[root@webserver ~]# alias nginx.start='/usr/sbin/nginx'
[root@webserver ~]# alias nginx.stop='/usr/sbin/nginx -s stop'
[root@webserver ~]# alias nginx.reload='/usr/sbin/nginx -s reload'
[root@webserver ~]# alias nginx.config_test='/usr/sbin/nginx -t'
[root@webserver ~]# cat /root/.bashrc 
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
alias nginx.start='/usr/sbin/nginx'
alias nginx.stop='/usr/sbin/nginx -s stop'
alias nginx.reload='/usr/sbin/nginx -s reload'
alias nginx.config_test='/usr/sbin/nginx -t'
[root@webserver ~]#
[root@webserver ~]# source  /root/.bash_profile 

 

1.2.6 添加系统用户:

useradd www -s /sbin/nologin -M

1.3、修改主机名称

hostname webserver
sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME=webserver/g' /etc/sysconfig/network
sed -n '/HOSTNAME/p' /etc/sysconfig/network
[root@localhost ~]# hostname webserver
[root@localhost ~]# sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME=webserver/g' /etc/sysconfig/network
[root@localhost ~]# sed -n '/HOSTNAME/p' /etc/sysconfig/network
HOSTNAME=webserver
[root@localhost ~]# 

2.4 mysql目录授权

chown -R mysql.mysql /application/mysql/data/

2.4、启动nginx服务

 

cd /root/
useradd -s /sbin/nologin -M nginx
/usr/sbin/nginx
ps -ef|grep nginx
curl http://172.16.210.126

[root@webserver ~]# cd /root/
[root@webserver ~]# useradd -s /sbin/nologin -M nginx
[root@webserver ~]# /usr/sbin/nginx
[root@webserver ~]# ps -ef|grep nginx
root     19206     1  0 15:41 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx    19207 19206  0 15:41 ?        00:00:00 nginx: worker process
root     19209  1625  0 15:41 pts/0    00:00:00 grep nginx
[root@webserver ~]# 
[root@webserver ~]# curl http://172.16.210.126
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@webserver ~]# 

 

Nginx status结果详解

Active connections: 1         #Nginx正处理的活动连接数有1个
server accepts handled requests   #第一个server表示Nginx启动到现在共处理20个连接

                    #第二个accepts表示Nginx启动到现在共成功创建20次握                                                                #手

                   #第三个handled requests表示共处理了23次请求

20 20 23 
Reading: 0 Writing: 1 Waiting: 0    #Reading为Nginx读取到客户端的Header信息数

                   #Writing为Nginx返回给客户端的Header数

                                                                #Waiting为Nginx已经处理完正等候下一次请求指令的驻                                                                  #留连接。在开启keepalive的情况下

                                                                #这个值等于active-(reading+writing)

五、重启nginx服务测试

mkdir -p /usr/local/nginx/logs
chown -R nginx.nginx /usr/local/nginx/
chown -R 777 /usr/local/nginx/logs/
/usr/sbin/nginx -s reload 

rm -rf /var/www/html/*
cat >/var/www/html/index.php <<EOF
<?php
phpinfo();
?>
EOF

澳门在线威尼斯官方 5

3.1 PHP(FastCGI方式)服务的安装准备

3.6、初始化数据库

#需要注意这里是mysql5.7的初始化命令,而5.7以下的都是用:

#/usr/local/mysql/scripts/mysql_install_db –user=mysql –datadir=/home/data/mysql_3310/

#在初始化成功之后,5.7的initial命令会产生一个随机的root登录密码,你要用这个密码登录,

#然后修改(必须修改生成的随机密码不然无法后续操作)。在最后有一个类似这样的密码:root@localhost : QAEwfe@dvs!

 

# /usr/local/mysql/bin/mysqld –-initialize –user=mysql –-basedir=/usr/local/mysql –-datadir=/home/data/mysql_3310/
# /usr/local/mysql/bin/mysqld --initialize-insecure –-user=mysql –-basedir=/usr/local/mysql –-datadir=/home/data/mysql_3310/ --defaults-file=/usr/local/mysql/my_3310.cnf
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my_3310.cnf --initialize-insecure &

[root@webserver mysql-5.7.20]# /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my_3310.cnf --initialize-insecure &
[1] 4717
[root@webserver mysql-5.7.20]#

 

6.2.4 检查挂载

[root@web01 html]# showmount -e 172.16.1.31

Export list for 172.16.1.31:

/backup 172.16.1.0/24

/data   172.16.1.0/24

[root@web01 html]# /etc/init.d/rpcbind status

rpcbind (pid  1314) is running...

六、快捷方式

cat >> /etc/rc.local <<EOF
##### mysql快捷方式 #####

#alias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my_3310.cnf &'
#alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin -uroot -p'mysql2017pwd' shutdown'
#alias mysql.3310.login='/usr/local/mysql/bin/mysql -uroot -p'mysql2017pwd''

##### php快捷方式 ######

# alias php.start='/etc/init.d/php-fpm start'
# alias php.stop='/etc/init.d/php-fpm stop'
# alias php.restart='/etc/init.d/php-fpm restart'
# alias php.reload='/etc/init.d/php-fpm reload'
# alias php.status='/etc/init.d/php-fpm status'
# alias php.configtest='/etc/init.d/php-fpm  configtest'

##### nginx快捷方式 #####
# alias nginx.start='/usr/sbin/nginx'
# alias nginx.stop='/usr/sbin/nginx -s stop'
# alias nginx.reload='/usr/sbin/nginx -s reload'
# alias nginx.configtest='/usr/sbin/nginx -t'
EOF

source  /root/.bash_profile

2.3 创建mysql用户及目录

mkdir /application/

useradd -s /sbin/nologin mysql -M

id mysql

一 准备工作

 

环境介绍:

 

OS:Centos 6.8 最小化安装

 

Nginx:nginx-1.12.2.tar.gz

 

mysql:mysql-boost-5.7.20.tar.gz

 

php:php-7.2.0.tar.bz2

 

1.2.3 下载源码包:

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

参数:-q 下载不提示。

3.1、版本选择

在安装之前必须明白一件事情,mysql有很多种安装方式,每种不一样,不要弄混了。比如源码编译安装和二进制安装这里我们用源码自己编译安装。

2.14.2 清空history

history -c  #清空全部历史记录

history -d 1024  #清除第1024条历史记录

二、安装Nginx

第1章 安装Nginx

7.2.2、web2的配置

 

[root@webserver html]# cat web2
server{
     charset utf-8;
     listen 80;
        server_name localhost;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        index index.php index.html index.htm ;
     location / {
            root /var/www/html/web2/;
            #   allow 172.16.100.12;
            #  deny all;
                         }
    location ~ .php$ {
            root           /var/www/html/web2;
            try_files      $uri =404;
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
[root@webserver html]# 

 

3.1.6 安装yum无法安装的 libiconv库

cd /home/chrishg/tools

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar -zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

7.1、主配置文件

[root@webserver ~]# cat /etc/nginx/nginx.conf
user  www;
worker_processes  8;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [] "$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  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8123;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html;
            index index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
       # location ~ .php$ {
       #     #root           html;
       #    try_files      $uri =404;
       #   fastcgi_pass   127.0.0.1:9000;
       #   fastcgi_index  index.php;
       #   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       #   include        fastcgi_params;
       #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
##################################
server{
     charset utf-8;
     listen 80;
        server_name localhost;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
        index index.php index.html index.htm ;
     location / {
            root /var/www/html/;
            #    allow 172.16.100.12;
            #   deny all;
                         }
    location ~ .php$ {
            root           /var/www/html/;
            try_files      $uri =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
##################################
include  /usr/local/nginx/html/*;
}
[root@webserver ~]# 

3.2.6 make报错排查

3.1.8 安装mhash 和mcrypt加密扩展库

yum install -y mhash mcrypt

1.2.7.19    重启服务

/application/nginx/sbin/nginx  -s reload

6.2.6 现在可以去测试网页了。

6.1 数据库mysql的分离

3.1.1 检查Nginx 及Mysql的安装情况

ls -ld /application/mysql/

ls -ld /application/nginx

3.2.6.1  make 结束有以下报错

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot set any files or directories in magic ".phar" directory' in /home/oldboy/tools/php-5.5.32/ext/phar/phar.php:1173

Stack trace:

#0 /home/chrishg/tools/php-5.5.32/ext/phar/phar.php(1173): Phar->offsetSet('.phar', '')

#1 /home/chrishg/tools/php-5.5.32/ext/phar/phar.php(1139): PharCommand::phar_add_file(Object(Phar), 0, '.phar', Object(SplFileInfo), NULL, true)

#2 /home/chrishg/tools/php-5.5.32/ext/phar/phar.php(1077): PharCommand::phar_add(Object(Phar), 0, '/home/oldboy/to...', NULL, '/\.svn/', Object(SplFileInfo), NULL, true)

#3 [internal function]: PharCommand->cli_cmd_run_pack(Array)

#4 /home/chrishg/tools/php-5.5.32/ext/phar/phar.php(225): call_user_func(Array, Array)

#5 /home/chrishg/tools/php-5.5.32/ext/phar/phar.php(2089): CLICommand->__construct(19, Array)

#6 {main}

  thrown in /home/chrishg/tools/php-5.5.32/ext/phar/phar.php on line 1173

make: *** [ext/phar/phar.phar] Error 255

原因是上面1.2.2.2在touch ext/phar/phar.phar 时变成了touch ext/phar/phar/.phar

解决:

cd ext/phar/phar/  #进入目录中

mv .phar /tmp     #删除创建错的文件

touch ext/phar/phar.phar    #重新创建文件

make   #重新make,这次的时间很短

本文由澳门在线威尼斯官方发布于电脑操作,转载请注明出处:【澳门在线威尼斯官方】web服务的安装,8编译安

关键词:

上一篇:没有了

下一篇:没有了