负载均衡会话保持
下面用到的包在这里
↓↓↓↓↓↓↓↓↓↓↓↓
链接:https://pan.baidu.com/s/1SwbJsdqqj-I2Tp8kUCWPUg
提取码:6666
内网IP | 外网IP | |
web01 | 172.16.1.7 | 10.0.0.7 |
web02 | 172.16.1.8 | 10.0.0.8 |
db01 | 172.16.1.51 | 10.0.0.51 |
lb01 | 172.16.1.4 | 10.0.0.4 |
[root@web01 ~]# mkdir /code
[root@web01 ~]# cd /code/
[root@web01 /code]# rz phpMyAdmin-4.9.0.1-all-languages.zip
[root@web01 /code]# unzip phpMyAdmin-4.9.0.1-all-languages.zip
[root@web01 /code]# mv phpMyAdmin-4.9.0.1-all-languages php
[root@web01 /code]# cp php/config.sample.inc.php php/config.inc.php [root@web01 /code]# vim php/config.inc.php $cfg['Servers'][$i]['host'] = '172.16.1.51';
[root@web01 /code]# vim /etc/nginx/conf.d/linux.php.com.conf
server {
listen 80;
server_name linux.php.com;
root /code/php;
location / {
index index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@web01 /code]# 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 /code]# systemctl restart nginx
#配置hosts
10.0.0.7 linux.php.com
#报错
session_start(): open(SESSION_FILE, O_RDWR) failed: Permission denied (13)
session_start(): Failed to read session data: files (path: /var/lib/php/session)
#解决:
[root@web01 /code]# chown -R www.www /var/lib/php/session
[root@db01 ~]# yum install -y mariadb-server #下载数据库
[root@db01 ~]# systemctl start mariadb #启动数据库
[root@db01 ~]# mysqladmin -uroot password 123 #设置数据库密码
[root@db01 ~]# mysql -uroot -p123 #进入数据库
MariaDB [(none)]> create database blog; #创建blog表
MariaDB [(none)]> create database zh; #创建zh表
MariaDB [(none)]> grant all on *.* to root@'172.16.1.%' identified by '123456'; #授权
[root@web01 ~]#scp -r /code/php 172.16.1.8:/code/
[root@web01 ~]#scp /etc/nginx/conf.d/linux.php.com.conf 172.16.1.8:/etc/nginx/conf.d/
[root@web02 ~]# systemctl restart nginx
[root@web02 /code]# chown -R www.www /var/lib/php/session
#配置本地hosts
10.0.0.8 linux.php.com
[root@lb01 ~]# vim /etc/nginx/conf.d/php.conf
upstream php {
server 172.16.1.7:80;
server 172.16.1.9:80;
}
server {
listen 80;
server_name linux.php.com;
location / {
proxy_pass http://php;
include /etc/nginx/proxy_params;
}
}
[root@lb01 ~]# systemctl restart nginx #重启nginx
#配置本地hosts
10.0.0.4 linux.php.com
[root@db01 ~]# yum install -y redis
[root@db01 ~]# vim /etc/redis.conf
bind 127.0.0.1 172.16.1.51
[root@db01 ~]# systemctl start redis
#检查启动
[root@db01 ~]# netstat -lntp
tcp 0 0 172.16.1.51:6379 0.0.0.0:* LISTEN 29104/redis-server
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 29104/redis-server
[root@web01 ~]# vim /etc/php.ini
session.save_handler = redis
session.save_path = "tcp://172.16.1.51:6379"
[root@web01 /code]# vim /etc/php-fpm.d/www.conf
#最下面几行注释
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session
[root@web01 /code]# systemctl restart php-fpm
[root@db01 ~]# yum install -y redis
[root@db01 ~]# vim /etc/redis.conf
bind 127.0.0.1 172.16.1.51
[root@db01 ~]# systemctl start redis
[root@web02 /code]# vim /etc/php.ini
session.save_handler = redis
session.save_path = "tcp://172.16.1.51:6379"
[root@web02 /code]# vim /etc/php-fpm.d/www.conf
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session
[root@web02 /code]# systemctl restart php-fpm
[root@db01 ~]# redis-cli
127.0.0.1:6379> keys *
本文来自博客园,作者:六月OvO,转载请注明原文链接:https://www.cnblogs.com/chenlifan/p/13598463.html