码迷,mamicode.com
首页 > 其他好文 > 详细

haproxy+keepalived

时间:2017-08-22 21:46:45      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:haproxy   keepalived   

haproxy+keepalived搭建web群集

一、实验环境

技术分享二、实验步骤

haproxy+keepalived 1配置

IP192.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配置

IP192.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

技术分享配置haproxy  2

#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配置

IPvmnet 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

技术分享WEB 2配置

IPvmnet 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共享存储配置

IPvmnet 2192.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大本营” 博客,转载请与作者联系!

haproxy+keepalived

标签:haproxy   keepalived   

原文地址:http://itdby.blog.51cto.com/13153042/1958416

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!