1、mariadb、nfs服务器的设置 (centos 7)
[root@localhost ~]# rpm -q rpcbind rpcbind-0.2.0-32.el7.x86_64 [root@localhost ~]# rpm -q nfs-utils (默认nfs已经安装的) nfs-utils-1.3.0-0.21.el7.x86_64 [root@localhost ~]# yum -y install mariadb-server [root@localhost ~]# systemctl start mariadb [root@localhost ~]# mysql (创建一个数据库给web服务器使用) MariaDB [(none)]> CREATE DATABASE wordpress; MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wordpress'@'192.168.116.%' IDENTIFIED BY '123456'; MariaDB [(none)]> FLUSH PRIVILEGES; [root@localhost ~]# systemctl start nfs [root@localhost ~]# mkdir /wordpress [root@localhost ~]# vim /etc/exports (创建共享目录) /wordpress 192.168.116.0/24(rw,no_root_squash) [root@localhost ~]# tar xf wordpress-4.5.3-zh_CN.tar.gz [root@localhost ~]# cd wordpress/ [root@localhost wordpress]# mv ./* /wordpress/ [root@localhost wordpress]# cp wp-config-sample.php wp-config.php (此目录为/wordpress) [root@localhost wordpress]# vim wp-config.php 修改如下配置 define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpress'); define('DB_PASSWORD', '123456'); define('DB_HOST', '192.168.116.114'); define('DB_CHARSET', 'utf8'); [root@localhost ~]# chown -R apache:apache /wordpress
2、web1的配置(centos6)
(1)网卡配置
1)修改内核参数来限制arp响应和通告
先限制通告再设置ip [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
2)网卡配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 网卡名和MAC地址每台虚拟机都不同的,可使用 ip a 命令查看再设置 DEVICE=eth1 HWADDR=00:0c:29:9f:12:63 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.116.6 NETMASK=255.255.255.0 先重启网络服务再配置下面lo0网络 [root@localhost ~]# ifconfig lo:0 192.168.116.254 netmask 255.255.255.255 broadcast 192.168.116.254 up [root@localhost ~]# route add -host 192.168.116.254 dev lo:0
3)挂载nfs共享目录
[root@localhost ~]# mkdir /web [root@localhost ~]# mount -t nfs 192.168.116.114:/wrodpress /web
4)安装httpd php php-mysql
[root@localhost ~]# yum -y install httpd php php-mysql [root@localhost ~]# vim /etc/httpd/conf.d/web.conf NameVirtualHost *:80 <Virtualhost *:80> ServerName www.wordpress.com DocumentRoot "/web" </Virtualhost> [root@localhost ~]# service httpd start
3、web2的配置(centos7)
1)修改内核参数来限制arp响应和通告
先限制通告再设置ip [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
2)网卡配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno33554984 DEVICE=eno33554984 ONBOOT=yes BOOTPROTO=none IPADDR=192.168.116.7 NETMASK=255.255.255.0 HWADDR=00:0c:29:e8:7c:c6 先重启网络服务再配置下面lo0网络 [root@localhost ~]# ifconfig lo:0 192.168.116.254 netmask 255.255.255.255 broadcast 192.168.116.254 up (临时设置网卡,重启网络服务时效) [root@localhost ~]# route add -host 192.168.116.254 dev lo:0
3)挂载nfs共享目录
[root@localhost ~]# mkdir /web [root@localhost ~]# mount -t nfs 192.168.116.114:/wrodpress /web
4)安装httpd php php-mysql
[root@localhost ~]# yum -y install httpd php php-mysql [root@localhost ~]# vim /etc/httpd/conf.d/web.conf <Virtualhost *:80> DocumentRoot "/web" ServerName www.wrodpress.com <Directory "/web"> AllowOverride none Options none Require all granted </Directory> </Virtualhost> [root@localhost ~]# systemctl start httpd
4、director的设置
1)网卡配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 DEVICE=eno16777736 HWADDR= 00:0c:29:0e:27:cd IPADDR=192.168.116.1 NETMASK=255.255.255.0 BOOTPROTO=none ONBOOT=yes 先重启网络服务再配置下面lo0网络 [root@localhost ~]# ifconfig eno16777736:0 192.168.116.254 netmask 255.255.255.255 broadcast 192.168.116.254 up
2)ipvs的配置
[root@localhost ~]# yum -y install ipvsadm [root@localhost ~]# ipvsadm -A -t 192.168.116.254:80 -s rr [root@localhost ~]# ipvsadm -a -t 192.168.116.254:80 -r 192.168.116.6 -g -w 1 [root@localhost ~]# ipvsadm -a -t 192.168.116.254:80 -r 192.168.116.7 -g -w 1
5、客户端测试
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 DEVICE=eno16777736 HWADDR= 00:0c:29:0e:27:cu IPADDR=192.168.116.110 NETMASK=255.255.255.0 BOOTPROTO=none ONBOOT=yes [root@localhost ~]# vim /etc/hosts 192.168.116.254 www.wordpress.com
在浏览器中输入www.wordpress.com,按提示安装WordPress并登陆。
新建一个网页,并上传一个图片,发布后多次刷新,如果显示页面都一样,则实验完成
原创文章,作者:pao,如若转载,请注明出处:http://www.178linux.com/56455