keepalived_nginx实现discuz负载均衡和高可用
前言:上回讲到,《lvs-dr模型负载均衡高可用Discuz》,但是由于lvs过于重量级,小公司使用有点不合时宜,本回咱们使用nginx实现此功能。望各位博友笑纳。
此次试验使用nginx代替lvs作为前端调度器,使用keepalived对nginx做双主模型高可用,向后做反向代理。RS服务器使用httpd+php来处理php页面请求,httpd和php以模块形式结合。暂时不考虑会话保持和动静资源分离的问题。我们下一篇博客会做补充。一次写太多会影响品质!!!
规划:
前端使用两台nginx服务器作为前端调度器,使用keepalived对nginx做双主模型高可用,两台RS服务器,后端一台共享存储提供mariadb和NFS服务,因为不再使用LVS调度,而是通过nginx反代来实现,所以两台RS服务器不需要在本地回环接口的别名上配置VIP
各个主机的IP地址
Host VS1
eno16777736 10.0.0.201/8 (DIP)
gateway: 10.0.0.254
Host VS2
eno16777736 10.0.0.203/8(DIP)
gateway: 10.0.0.254
Host RS1
eno16777736 10.0.0.101/8 (RIP1)
gateway: 10.0.0.254
Host RS2
eno16777736 10.0.0.102/8 (RIP2)
gateway: 10.0.0.254
Host DB
eno16777736 10.0.0.202/8
gateway: 10.0.0.254
时间同步:
# ntpdate cn.pool.ntp.org
# hwclock --sysohc
安装软件:
HostDB
安装二进制mariadb-5.5.46
详细配置请入传送门:http://wscto.blog.运维网.com/11249394/1783131
安装NFS
# yum install -y nfs-utils
HostRS1
安装nginx,注意nginx属于epel源
# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb
HostRS2
安装nginx,注意nginx属于epel源
# yum install-y nginx php-fpm php-mbstring php-mysql nfs-utils mariadb
Host VS1
安装keepalived是为了实现高可用,nginx实现反代 nfs-utils
# yum install -y keepalived nfs-utils
#wget http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.8.1-1.el6.ngx.x86_64.rpm
#rpm -ivh nginx-1.8.1-1.el6.ngx.x86_64.rpm注意:CentOS 6中nginx版本,比较低,所以可以这样下载,在7中无需考虑
Host VS2
安装keepalived是为了实现高可用,nginx实现反代 nfs-utils
# yum install -y keepalived nfs-utils
#wget http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.8.1-1.el6.ngx.x86_64.rpm
#rpm -ivh nginx-1.8.1-1.el6.ngx.x86_64.rpm
HostDB
完成安全初始化后,创建discuz数据库和discuz用户,并授权其可以远程操作数据库
# mysql_secure_installation
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.46-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user 'discuz'@'localhost' identified by 'magedu';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on discuz.* to 'discuz'@'%' identified by 'magedu';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
配置NFS
# mkdir /nfshare/
# ls -dl /nfshare/
drwxr-xr-x 2 root root 6 May 9 17:01 /nfshare/
# echo "/nfshare/ 10.0.0.101(rw,no_root_squash,async) 10.0.0.102(rw,no_root_squash,async)" > /etc/exports
# systemctl start rpcbind
页:
[1]