8编译安装LNMP环境,web服务的安装

作者: 金沙澳门官网网址  发布:2019-10-18

第1章 安装Nginx

Centos 6.8编写翻译安装LNMP情形

参谋资料:

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

https://phperzh.com/articles/1360

环境:

系统:CentOS6.5 

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

 

一 筹划干活

 

条件介绍:

 

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.1 Nginx官网

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 ~]# 

1.2 安装nginx

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

 

1.2.1 安装Nginx所需的pcre库

效果:完结伪静态的功用

yum install pcre pcre-devel -y

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 ~]# 

1.2.2 安装编写翻译注重包:

yum install gcc gcc-devel -y

yum install openssl openssl-devel -y

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

1.2.3 下载源码包:

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

参数:-q 下载不晋升。

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 ~]# 

1.2.4 解压

tar xf nginx-1.6.3.tar.gz

cd nginx-1.6.3

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" 

1.2.5 查询yum仓库有未有rpm包

yum list |grep nginx 或yum list *nginx*

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

1.2.6 加多系统客户:

useradd www -s /sbin/nologin -M

二、安装Nginx

1.2.7 带头编写翻译安装nginx

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.1  配置编写翻译参数

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

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

1.2.7.2  检查铺排重返值

echo $?    #返回值为0 则正确

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.3  编译&安装

make

make install

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 ~]# 

 

1.2.7.4  配置软链接,方便以往升迁版本。开垦不用修改程序

ln -s /application/nginx-1.6.3/ /application/nginx

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.7.5  nginx运营前的检讨语法

[root@web01 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful

二、安装mysql

1.2.7.6  启动nginx服务

/application/nginx/sbin/nginx

3.1、版本选取

在装置在此之前必需理解一件事情,mysql有很三种安装情势,每个不均等,不要弄混了。举个例子源码编写翻译安装和二进制安装这里大家用源码本身编写翻译安装。

1.2.7.7  运维服务后翻看监听端口

netstat -lntup|grep 80

lsof -i :80

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

 

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]

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.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

3.4、修改目录权限

 

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

 

1.2.7.10    查看错误日志

cat /application/nginx/logs/error.log

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]# 

1.2.7.11    配置nginx配置文件

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

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]#

 

1.2.7.12    配置文件内容表达

[root@web01 conf]# vim nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;  #可改的监听端口

        server_name  www.chrishg.net;  #可改为的域名

autoindex on; #允许客户端浏览我的目录

        location / {

            root   html/www;  #对应的目录

            index  index.html index.htm;

        }

}

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]# 

 

1.2.7.13    增多虚构主机

增加虚构主机在http{ } 模块里扩张下边代码:多虚构主机就添增多组以下内容。

server {

        listen       80;

        server_name  bbs.chrishg.net;

        location / {

            root   html/bbs;

            index  index.html index.htm;

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.14     单网卡多IP

 server {

        listen       10.0.0.102:80;

        server_name  bbs.chrishg.net;

        location / {

            root   html/bbs;

            index  index.html index.htm;

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 

 

1.2.7.15    多域名

server {

        listen       10.0.0.102:80;

        server_name  bbs.chrishg.net chrishg.net;

        location / {

            root   html/bbs;

            index  index.html index.htm;

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'

 

1.2.7.16    增多状态监察和控制页面

##status

server {

        listen       80;

        server_name  status.chrishg.net;

        location / {

          stub_status on;

          access_log off;

        }

    }

加多后,张开网页交易会示如下:

Active connections: 2                  #活动的连接

server accepts handled requests       

 4 4 17                                #

Reading: 0 Writing: 1 Waiting: 1       #  

四、安装php-fpm

1.2.7.17    检查布置文件语法

/application/nginx/sbin/nginx  -t

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' 

1.2.7.18    运维服务

/application/nginx/sbin/nginx

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

 

1.2.7.19    重启服务

/application/nginx/sbin/nginx  -s reload

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

 

1.2.7.20    关闭服务

/application/nginx/sbin/nginx  -s stop

4.4、增多php-fpm至服务列表并安装开机自启

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

1.3 公司中重启nginx后的战略

在店堂运转实践场中,每一种布局操作管理实现后都应有实行快速有效的检讨,那是二个及格运维职员的优秀习贯。尽量使得在Nginx运转的同不常间,还大概会调用脚本通过获取header消息或模拟顾客访问钦赐UCR-VL(wget等方法)来机关检查Nginx是或不是健康,最大限度的管教服务重启后,能便捷鲜明网址景况,而无须手工业敲命令查看。那样假使布署有标题就能够不慢采纳上一本子备份配置文件覆盖回来。

[root@localhost conf]# cat check_url.sh 
#!/bin/bash
#author:chenfu 2017-10-22 QQ532088799
#--------function split--------
. /etc/rc.d/init.d/functions
function checkURL()
{
checkUrl=$1
echo 'check url start ...'
judge=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1 | tr " " "n"))
if [[ "${judge[1]}" == '200' && "${judge[2]}" == 'OK' ]]
then
action "${checkUrl}" /bin/true
else
action "${checkUrl}" /bin/false
echo -n "retrying again...";sleep 3;
judgeagain=($(curl -I -s --connect-timeout 2 ${checkUrl}| head -1| tr "r" "n"))
if [[ "${judgeagain[1]}" == '200' && "${judgeagain[2]}" == 'OK' ]]
then
action "${chekcUrl}, retried again" /bin/true 
else
action "${chekcUrl}, retried again" /bin/false
fi
fi
sleep 1;
}
# usage method
checkURL http://www.etiantian.org

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/

Nginx status结果详解

Active connections: 1         #Nginx正管理的位移连接数有1个
server accepts handled requests   #首先个server表示Nginx运维到近些日子共拍卖十九个一而再

                    #第3个accepts表示Nginx运维到未来共成功创设贰十四次握                                                                #手

                   #其几个handled requests表示共拍卖了22遍呼吁

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

                   #Writing为Nginx重返给顾客端的Header数

                                                                #Waiting为Nginx已经管理完正等候下一遍呼吁指令的驻                                                                  #留连接。在展开keepalive的状态下

                                                                #其一值等于active-(reading writing)

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 ~]# 

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

五、重启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

图片 1

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"';

5.1、多路线配置

 

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

Nginx访问日志轮询切割

[root@localhost nginx]# cat /server/script/cut_nginx_log.sh 
#!/bin/bash
Dateformat=`date %Y%m%d`
Basedir="/application/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1
[ -f ${Logname}.log ] || exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload

Nginx常用的日志收罗分析工拥有rsyslog、awstats、flume、ELK、storm等

六、飞速格局

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

1.4 yum安装nginx的方法

wget -q http://mirrors.utc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.narch.rpm

yum install nginx

亿级PV超大型网址集群框架结构图形化深度揭秘批注 - CSDN大学 - CSDN.NET

 

七、多路径配置测验

第2章 mysql二进制包的设置

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 ~]# 

2.1 安装包下载:

法定地址:

cd /home/chrishg/tools

wget http://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz

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]# 

 

2.2 解压并mv到统一目录 /application/

cd /home/chrishg/tools

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

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

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

ls /application/

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.3 创造mysql顾客及目录

mkdir /application/

useradd -s /sbin/nologin mysql -M

id mysql

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]# 

 

2.4 mysql目录授权

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

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]# 

 

2.5 开端化mysql(如生成内部客商、库 等)

cd /application/mysql/

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

ll data/

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]# 

 

2.6 主机名要做解释

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

172.16.1.8      web01

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]# 

 

2.7 修改运转文件里的路线并复制到/etc/init.d/目录下并授权

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

cp 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

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 ~]# 

2.8 运营数据库并查看端口

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

lsof -i :3306

netstat -lntup |grep 3306

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.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    #添加完后重读配置文件。

2.11 实现stop|start|restart|开机自运维

/etc/init.d/mysqld stop

/etc/init.d/mysqld start

/etc/init.d/mysqld restart

chkconfig --add mysqld

chkconfig --list mysql

chkconfig mysql on

2.12 查看错误日志

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

cat /application/mysql/data/web01.err

2.12.1 故障点

2.12.1.1    /tmp目录权限必得为以下权限(1777)

[root@web01 mysql]# ls -ld /tmp

drwxrwxrwt. 4 root root 4096 Aug 30 01:22 /tmp

本文由金沙澳门官网发布于金沙澳门官网网址,转载请注明出处:8编译安装LNMP环境,web服务的安装

关键词: 金沙澳门官网