💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
环境: 服务器操作系统:centos7.3 * haproxy: 外网IP: 10.2.13.220/24 内网IP:192.168.20.131/24 * WEB server: node7.51yuki.cn: 外网IP:10.2.13.219/24 内网IP:192.168.20.132/24 node8.51yuki.cn: 外网IP:10.2.13.217/24 内网IP:192.168.20.133/24 * Database Server master_mysql.51yuki.cn: 内网IP:192.168.20.135/24 第一步:分别在node7.51yuki.cn和node8.51yuki.cn的机器上安装nginx和php 版本: nginx: nginx-1.12.2 php: php-5.6.33 安装脚本: https://gitee.com/louis1986/shell_scripts/blob/master/Software_Install/install_lnmp_centos7.sh 把nginx和php-fpm添加到开机自动启动 [root@node8 ~]# chkconfig --add php-fpm [root@node8 ~]# echo “/usr/local/nginx-1.12.2/sbin/nginx ">>/etc/rc.local 第二步:在master_mysql.51yuki.cn机器上安装mysql服务 版本:mysql-5.6.38(安装mysql二进制包) 查看博客地址 http://www.cnblogs.com/51yuki/p/mysql01.html 第三步:登录mysql,创建数据库 mysql> create database discuz; Query OK, 1 row affected (0.01 sec) mysql> grant all on discuz.* to discuz@'192.168.20.%' identified by 'discuz&0611'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 第四步:在2台web服务器上安装discuz(以node8.51yuki.cn为例) 1)网站目录 [root@node7 ~]# mkdir -p /opt/web/discuz 下载软件,然后解压,把upload目录里的所有文件拷贝到/opt/web/discuz [root@node8 ~]# cd /usr/local/src/ [root@node8 src]# wget http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip [root@node8 src]# unzip Discuz_X3.1_SC_UTF8.zip [root@node8 src]# cp -r upload/* /opt/web/discuz/ 2)配置虚拟主机 [root@node8 discuz]# cd /usr/local/nginx-1.12.2/conf/ [root@node8 conf]# mkdir conf.d [root@node8 conf.d]# vim ../nginx.conf 增加如下 include conf.d/*.conf; 配置虚拟主机 [root@node8 conf.d]# vim discuz.conf server { listen 8080; server_name localhost; location / { root /opt/web/discuz; index index.php index.html index.htm; } location ~ \.php$ { root /opt/web/discuz; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 3)改变文件及目录权限 [root@node8 discuz]# chmod -R 777 ./config/ ./data/ ./uc_client/ ./uc_server/ 4)安装 http://10.2.13.217:8080/install/ 最后,更改两台服务器的监听地址,让其监听内网的ip地址 listen 192.168.20.133:8080; [root@node8 conf.d]# /usr/local/nginx-1.12.2/sbin/nginx -s stop [root@node8 conf.d]# /usr/local/nginx-1.12.2/sbin/nginx [root@node8 conf.d]# ss -tunlp|grep 8080 tcp LISTEN 0 128 192.168.20.133:8080 *:* users:(("nginx",pid=1339,fd=7),("nginx",pid=1338,fd=7)) 最后node7.51yuki.cn机器上操作方式类似 第五步:配置haproxy 1)先安装haproxy [root@proxy01 ~]# yum -y install haproxy 2)配置haproxy.cfg ~~~ [root@proxy01 haproxy]# cat haproxy.cfg #--------------------------------------------------------------------- # Example configuration for a possible web application. See the # full configuration options online. # # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt # #--------------------------------------------------------------------- #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend main 10.2.13.220:80 #acl url_static path_beg -i /static /images /javascript /stylesheets #acl url_static path_end -i .jpg .gif .png .css .js #use_backend static if url_static default_backend websrvs #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- #backend static # balance roundrobin # server static 127.0.0.1:4331 check #--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- backend websrvs balance roundrobin server node7.51yuki.cn 192.168.20.132:8080 check server node8:51yuki.cn 192.168.20.133:8080 check ~~~ 最后测试: ![](https://box.kancloud.cn/d550504f3e28e9f1affeb5b50d3b9f8a_1321x630.png) 第六步:模拟node7.51yuki.cn机器故障