1、搭建一套LVS-DR模型的高性能集群,并实现以下功能:
(1)、wordpress程序通过nfs共享给各个realserver;
(2)、后端realserver中的nginx和php分离
Centos7系统 |
地址 |
安装程序 |
LVS主机 |
VIP:192.168.1.110 |
ipvsadm |
DIP:192.168.1.106 |
||
Nginx 1 |
192.168.1.112 |
nginx,nfs-utils |
Nginx 2 |
192.168.1.116 |
nginx,nfs-utils |
PHP/NFS |
192.168.1.114 |
php-fpm,php-mysql,nfs-utils |
Mysql |
192.168.1.117 |
mariadb-server |
1.在两台nginx主机上安装nginx,nfs-utils,没有nginx用户、用户组时,需自行创建
yum仓库
[my]
name=myrepo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
enabled=1
gpgcheck=0
[root@localhost ~]# yum install -y nginx
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
location / {
root /data/www;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /data/www;
fastcgi_pass 192.168.1.114:9000;
fastcgi_index index.php;
fastcgi_param
SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
创建挂载目录,修改权限
[root@localhost ~]# mkdir /data/www/ -p
[root@localhost ~]# chowm -R nginx.nginx /data/www
2.在php/nfs主机
安装PHP与nfs服务
[root@ www]# yum install -y php-fpm php-mysql
nfs-utils
配置NFS服务
[root@localhost /]# mkdir -p /data/www
listen = 192.168.1.114:9000
[root@localhost /]# chowm -R nginx.nginx /data/www
[root@localhost /]# vim /etc/exports
/data/www 192.168.1.0/24(rw,no_root_squash)
[root@localhost
/]# systemctl start nfs.service
配置php-fpm服务
[root@localhost /]# vim /etc/php-fpm.d/www.conf
listen = 192.168.1.114:9000
#listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
[root@localhost /]# systemctl start php-fpm.service
3.在两台nginx主机上挂载nfs,建立存放目录
[root@ ~]# mount -t nfs 192.168.1.114:/data/www
/data/www
4.在php/nfs服务器的/data/www目录下,创建php测试
[root@localhost /]# vim /data/www/index.php
<?php
phpinfo();
?>
5.在mysql主机安装mariadb-server
[root@localhost /]# yum install -y mariadb-server
[root@localhost /]# mkdir /mydata
[root@localhost /]# chown mysql.mysql /mydata
[root@localhost /]# vim /etc/my.cnf
datadir=/mydata
innodb_file_per_table=ON
skip_name_resolve=ON
[root@l /]# mysql_install_db –user=mysql
–datadir=/mydata
[root@/]# systemctl start mariadb.service
6.测试mariadb与php联动
在mariadb主机上进行授权
MariaDB [(none)]> grant all on *.* to
‘root’@’192.168.1.%’ identified by ‘mageedu’;
在php/nfs主机上创建测试页
[root@localhost /]# vim /data/www/index.php
<?php
$conn=mysql_connect (“192.168.1.117”,’root’,’mageedu’);
if ($conn)
echo
“OK !!!”;
else
echo
“FAILURE”;
?>
7.Mysql数据库建立WordPress数据库和用户
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on *.* to
‘root’@’192.168.1.%’ identified by ‘mageedu’;
MariaDB [(none)]> flush privileges;
8.在php/nfs主机上部署wordpress
[root@localhost /]# cd /data/www
[root@localhost www]# unzip wordpress-4.7.4-zh_CN.zip
[root@localhost www]# cd wordpress/
[root@wordpress]# cp wp-config-sample.php
wp-config.php
在mysql主机创建数据
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to
‘wpuser’@’192.168.1.%’ identified by ‘mageedu’;
在php/nfs主机修改wordpress配置文件(内容要与mysql数据库中一致)
[root@localhost wordpress]# vim wp-config.php
/** WordPress数据库的名称 */
define(‘DB_NAME’, ‘wpdb’);
/** MySQL数据库用户名 */
define(‘DB_USER’, ‘wpuser’);
/** MySQL数据库密码 */
define(‘DB_PASSWORD’, ‘mageedu’);
/** MySQL主机 */
define(‘DB_HOST’, ‘192.168.1.114’);
9.在LVS主机安装lvs
[root@CentOS7 /]# yum insatll ipvsadm -y
在lvs的物理网卡配置VIP
[root@CentOS7
/]# ifconfig eno16777736:0 netmask 255.255.255.255 broadcast 192.168.1.110
[root@CentOS7
/]# route add -host 192.168.1.110 dev eno16777736:0
10.在两台nginx主机对IP进行配置,添加路由,修改内核参数,
[root@CentOS7
/]#ifconfig lo:0 192.168.1.110 netmask 255.255.255.255 broadcast 192.168.1.110
[root@CentOS7]#route add -host 192.168.1.110 dev lo:0
[root@CentOS7]#echo 1
>/proc/sys/net/ipv4/conf/all/arp_ignore
[root@CentOS7]#echo 1
>/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@CentOS7]#echo 2
>/proc/sys/net/ipv4/conf/lo/arp_announce
[root@CentOS7]#echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
在LVS主机设置规则
[root@CentOS7 ]#ipvsadm -A -t 192.168.1.110:80 -s rr
[root@CentOS7/]#ipvsadm -a -t 192.168.1.110:80 -r 192.168.1.112 -g -w 1
[root@CentOS7]#ipvsadm -a -t 192.168.1.110:80 -r 192.168.1.116 -g -w 1
[root@CentOS7]# ipvsadm -Ln
[root@CentOS7]#systemctl status ipvsadm
11.浏览器测试(192.168.1.110/wordpress)
原创文章,作者:ning407631632,如若转载,请注明出处:http://www.178linux.com/84846