(1) 修改hostname
10.7 hostname lb01 -> logout
rz -y 上传已经下好的pcre 和 nginx
wget https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz ( perl 兼容的正则表达式,伪静态,url...)
wget nginx-1.6.2.tar.gz
tar -zxvf nginx-1.6.2.tar.gz , pcre-8.37.tar.gz
yum install gcc yum install gcc-c++ -y (安装编译c和c++ 环境,不然编译pcre 会保存)
ed /home/skinglzw/Downloads/pcre-8.37
./configure make make install
cd ../ cd nginx-1.6.2
yum install pcre-devel -y
yum install openssl-devel -y
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module
make make install
ln -s /usr/local/nginx-1.6.2 /usr/local/nginx (创建软连接)
useradd nginx -s /sbin/nologin -M(不登录,不放进home 目录)
/usr/local/nginx/sbin/nginx (启动) lsof -i :80
/usr/local/nginx/sbin/nginx -s stop (停止)
cd /usr/local/nginx/conf
egrep -v "#|^$" nginx.conf.default >nginx.conf (把#号空行给删除,定向到配置文件里)
除了有热备,还有节点故障判断功能
vim nginx.conf

upstream web_pools {
ip_hash; (适用于回话session保持)
server 10.0.0.9:80 weight=5;
#server backend2.example.com:8080;
server 10.0.0.10:80 weight=5;

server 10.0.0.11:80 weight=5   backup;(web服务器的热备9或者10宕机了,11就启动服务,web 服务器自身支持的高可用)

}

server {
listen 80;
server_name www.etiantian.org;
location / {
root html;
index index.html index.htm;
proxy_pass http://web_pools;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /name/ {
proxy_pass http://192.168.1.135;
}
}
../sbin/nginx -t (检查配置文件语法是否正确)
../sbin/nginx -s reload

vim /etc/hosts
10.0.0.7 www.etiantian.org bbs.etiantian.org (本机ip)
yum install telnet nmap dos2unix -y
telnet 10.0.0.9 (No route to host ping 通了,报这个错误,是防火墙问题,关闭它)
cat /etc/httpd/conf/fastcgi_params 查看nginx 支持的变量

10.8 hostname lb02 -> logout ( 同样 lb01 的操作)

10.9 hostname web01 yum install httpd -y
/etc/init.d/httpd start lsof -i :80 查看端口的进程
curl 192.168.1.134 有数据说明安装完成
echo 192.168.1.134 >/var/www/html/index.html

/etc/init.d/iptables stop   (关闭防火墙)
systemctl stop firewalld.service  (centos 7 关闭防火墙)

cd /etc/httpd/conf
虚拟主机配置
vim httpd.conf
:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/bbs"
ServerName bbs.etiantian.org
ErrorLog "logs/bbs-error.log"
CustomLog "logs/bbs-access.log" common

:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/www"
ServerName www.etiantian.org
ErrorLog "logs/www-error.log"
CustomLog "logs/www-access.log" common

/usr/sbin/httpd -t (检查配置语法)
/usr/sbin/httpd -k graceful (优雅的重启)
echo bbs >/var/www/bbs/index.html
echo www >/var/www/www/index.html
scp httpd.conf 192.168.24.136:/etc/httpd/conf/
scp -rp /var/www/bbs 192.168.24.136:/var/www
scp -rp /var/www/www 192.168.24.136:/var/www
日志格式
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined (改下,就可以记录客户端ip,这个变量名跟nginx 配置传的header 变量名一样,这样nginx 负载给web服务器,才能记录到真实客户端ip)
10.10 hostname web02 yum install httpd -y (同样web01 的操作)