部署反向代理:
1.配置仓库
[root@lb01 ~]# scp 10.0.0.7:/etc/yum.repos.d/nginx.repo /etc/yum.repos.d/
2.安装nginx
[root@lb01 ~]# yum -y install nginx
3.配置nginx
[root@lb01 conf.d]# cat proxy.conf
server {
listen 80;
server_name zh.test.com;
location / {
proxy_pass http://10.0.0.7:80;
include parames;
}
}
server {
listen 80;
server_name wordpress.test.com;
location / {
proxy_pass http://10.0.0.8:80;
include parames;
}
}
4.配置携带的参数
[root@lb01 conf.d]# cat ../parames
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
负载均衡
1.负载均衡配置
[root@lb01 conf.d]# cat proxy.conf
upstream webs {
server 172.16.1.7:80;
server 172.16.1.8:80;
}
server {
listen 80;
server_name test.proxy.com;
location / {
proxy_pass http://webs;
include parames;
}
}
2.web01配置nginx
[root@web01 conf.d]# cat test.conf
server {
listen 80;
server_name test.proxy.com;
location / {
root /code;
index index.html;
}
}
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# systemctl restart nginx
[root@web01 conf.d]# echo web01..... > /code/index.html
[root@web01 conf.d]# cat /code/index.html
web01.....
3.web02配置nginx
[root@web02 conf.d]# cat test.conf
server {
listen 80;
server_name test.proxy.com;
location / {
root /code;
index index.html;
}
}
[root@web02 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web02 conf.d]# systemctl restart nginx
[root@web02 conf.d]# echo web02.... > /code/index.html
[root@web02 conf.d]# cat /code/index.html
web02....
会话保持
1.配置nginx
[root@web01 conf.d]# cat myadmin.conf
server {
listen 80;
server_name admin.test.com;
root /code/admin;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.重新启动
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# systemctl restart nginx
3.创建代码目录
[root@web01 conf.d]# mkdir /code/admin
4.下载代码到admin目录
[root@web01 admin]# wget https://files.phpmyadmin.net/phpMyAdmin/4.8.4/phpMyAdmin-4.8.4-all-languages.zip --no-check-certificate
5.解压代码
[root@web01 admin]# unzip phpMyAdmin-4.8.4-all-languages.zip
[root@web01 admin]# mv phpMyAdmin-4.8.4-all-languages/* .
修改session的属主属组为www 因为phpmyadmin业务需要往下面的目录中写入session
[root@web01 admin]# chown www.www /var/lib/php/session
6.将数据库的信息写入到PHPmyadmin的配置文件中
[root@web01 admin]# cp config.sample.inc.php config.inc.php
修改数据库信息
[root@web01 admin]# grep 172.16.1.51 config.inc.php -n
31:$cfg['Servers'][$i]['host'] = '172.16.1.51';
6.hosts解析访问
web02部署phpmyadmin 将web01数据同步给web02
[root@web01 ~]# rsync -avz --delete /etc/nginx/ 10.0.0.8:/etc/nginx/
同步代码目录
[root@web01 ~]# rsync -avz --delete /code/ 10.0.0.8:/code/
同步完成重启
[root@web02 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web02 conf.d]# systemctl restart nginx
集成到负载均衡测试session会话
[root@lb01 conf.d]# cat proxy.conf
upstream webs {
server 172.16.1.7:80 max_fails=2 fail_timeout=10s;
server 172.16.1.8:80 max_fails=2 fail_timeout=10s;
}
server {
listen 80;
server_name test.proxy.com;
location / {
proxy_pass http://webs;
include parames;
}
}
server {
listen 80;
server_name admin.test.com;
location / {
proxy_pass http://webs;
include parames;
}
}
[root@lb01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 conf.d]# systemctl restart nginx
hosts解析到10.0.0.5测试
1.在10.0.0.51服务器部署redis服务器
[root@db01 ~]# yum -y install redis
2.修改监听地址 默认只监听127.0.0.1
[root@db01 ~]# grep -n 51 /etc/redis.conf
61:bind 127.0.0.1 172.16.1.51
3.启动redis
[root@db01 ~]# systemctl start redis
[root@db01 ~]# systemctl enable redis
3.修改WEB01服务器的php配置/etc/php.ini
[root@web01 ~]# grep redis -n /etc/php.ini
1231:session.save_handler = redis
[root@web01 ~]# grep 172.16 -n /etc/php.ini
1264:session.save_path = "tcp://172.16.1.51:6379"
修改www.conf 将395 396注释使用分号
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
395 ;php_value[session.save_handler] = files
396 ;php_value[session.save_path] = /var/lib/php/session
[root@web01 ~]# systemctl restart php-fpm
web02服务器修改php配置
[root@web01 ~]# rsync -avz --delete /etc/php.ini 172.16.1.8:/etc/php.ini
[root@web01 ~]# rsync -avz --delete /etc/php-fpm.d/www.conf 172.16.1.8:/etc/php-fpm.d/www.conf
重启php-fpm
[root@web02 conf.d]# systemctl restart php-fpm
评论区