haproxy+keepalived搭建web群集
一、实验环境
haproxy+keepalived 1配置
IP:192.168.1.10
#yum -y install pcre-devel zlib-devel bzip2-devel kernel-devel openssl-devel popt-devel zlib-devel
#tar zxf keepalived-1.2.13.tar.gz 解压源码包
#cd keepalived-1.2.13
#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.e16.x86_64
#make && make install
#chkconfig --add keepalived 添加为系统服务
#chkconfig keepalived on 设置为开机自启动
#cd /etc/keeplived/
#cp keepalived.conf keepalived.conf.bak 备份一份以防万一
#vim keepalived.conf 编辑主配置文件
#service keepalived start 启动keepalved服务
#ip addr show eth0 查看漂移地址
配置haproxy 1
#tar zxf haproxy-1.4.24.tar.gz
#cd haproxy-1.4.24
#make TARGET=linux26 64位系统
#make install
#mkdir /etc/haproxy 创建配置文件目录
#cp examples/haproxy.cfg /etc/haproxy/ 将haproxy.cfg文件复制到配置文件目录
#vim /etc/haproxy/haproxy.cfg
#cp /usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy
#ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
#chmod +x /etc/init.d/haproxy
#service haproxy start
#service iptables stop
haproxy+keepalived 2配置
IP:192.168.1.20
#yum -y install pcre-devel zlib-devel bzip2-devel kernel-devel openssl-devel popt-devel zlib-devel
#tar zxf keepalived-1.2.13.tar.gz
#cd keepalived-1.2.13
#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.e16.x86_64
#make && make install
#chkconfig --add keepalived
#chkconfig keepalived on
#scp root@192.168.1.10:/etc/keepalived/keepalived.conf /etc/keepalived/
#scp root@192.168.1.10:/etc/keepalived/keepalived.conf.bak /etc/keepalived/ 远程复制一份主的配置
#vim /etc/keepalived/keepalived.conf 做简单修改即可
#service keepalived restart
#ip addr show dev eth0
#tar zxf haproxy-1.4.24.tar.gz 使用源码编译安装
#cd haproxy-1.4.24
#make TARGET=linux26 64位系统
#make install
#mkdir /etc/haproxy 创建配置文件目录
#cp examples/haproxy.cfg /etc/haproxy/ 将haproxy.cfg文件复制到配置文件目录
#scp root@192.168.1.10:/etc/haproxy/haproxy.cfg /etc/haproxy/haproxy/
从主复制到从一份此处不用修改
#cp /usr/src/haproxy-1.4.24/examples/haproxy.init /etc/init.d/haproxy
#ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
#chmod +x /etc/init.d/haproxy 给一个执行权限
#service haproxy start
#service iptables stop
WEB 1配置
IP:vmnet 1:192.168.1.30
vmnet 2:192.168.2.20
#yum -y install pcre-devel zlib-devel rpcbind nfs-utils
#chkconfig rpcbind on
# chkconfig nfs on
#service rpcbind start
#service nfs start
#useradd -M -s /sbin/nologin nginx
#tar zxf nginx-1.6.2.tar.gz
#cd nginx-1.6.2
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install
#echo 11111111 > /usr/local/nginx/html/index.html
#/usr/local/nginx/sbin/nginx
#netstat -anpt | grep nginx
IP:vmnet 1:192.168.1.40
vmnet 2:192.168.2.10
#yum -y install pcre-devel zlib-devel rpcbind nfs-utils
#chkconfig rpcbind on
# chkconfig nfs on
#service rpcbind start
#service nfs start
#useradd -M -s /sbin/nologin nginx
#tar zxf nginx-1.6.2.tar.gz
#cd nginx-1.6.2
#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install
#echo 11111111 > /usr/local/nginx/html/index.html
#/usr/local/nginx/sbin/nginx
#netstat -anpt | grep nginx
客户机windows 7 访问http://192.168.1.254
把haproxy+keepalived 1宕掉
客户机测试访问http://192.168.1.254
NFS共享存储配置
IP:vmnet 2:192.168.2.30
#yum -y install rpcbind nfs-utils
#chkconfig rpcbind on
# chkconfig nfs on
#mkdir -p /opt/wwwroot
#vim /etc/exports
/opt/wwwroot 192.168.2.0/24(rw,sync,no_root_squash)
#service rpcbind start
#service nfs start
#echo www.itdby.com > /opt/wwwroot/index.html
各节点服务器
mount 192.168.2.30:/opt/wwwroot /usr/local/nginx/html/
客户机测试访问http://192.168.1.254
本文出自 “IT大本营” 博客,转载请与作者联系!
原文地址:http://itdby.blog.51cto.com/13153042/1958416