jiay 发表于 2018-12-29 14:26:45

haproxy+keepalived-IT@彦小疯

  haproxy+keepalived搭建web群集
  一、实验环境
https://s2.运维网.com/wyfs02/M01/00/B4/wKiom1mb-TLSCCT1AAFMpasu4gE254.png二、实验步骤
  haproxy+keepalived 1配置
  IP:192.168.1.10
  #yum   -yinstall pcre-develzlib-devel bzip2-devel kernel-developenssl-devel popt-develzlib-devel
  #tar zxfkeepalived-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添加为系统服务
  #chkconfigkeepalivedon设置为开机自启动
  #cd /etc/keeplived/
  #cpkeepalived.conf   keepalived.conf.bak备份一份以防万一
  #vim keepalived.conf编辑主配置文件
https://s3.运维网.com/wyfs02/M02/00/B4/wKiom1mb-Vyj5wd3AAB7DoP9fK8945.png
  #service keepalived start启动keepalved服务
  #ipaddr show eth0查看漂移地址
https://s1.运维网.com/wyfs02/M00/9F/64/wKioL1mb-WOAguTfAABzxB0KP0M153.png
  配置haproxy1
  #tarzxfhaproxy-1.4.24.tar.gz
  #cdhaproxy-1.4.24
  #make TARGET=linux26                  64位系统
  #make install
  #mkdir/etc/haproxy                   创建配置文件目录
  #cpexamples/haproxy.cfg   /etc/haproxy/   将haproxy.cfg文件复制到配置文件目录
  #vim/etc/haproxy/haproxy.cfg
https://s3.运维网.com/wyfs02/M01/00/B4/wKiom1mb-Z6wi-cqAAChLoCdufI095.png
https://s2.运维网.com/wyfs02/M02/00/B4/wKiom1mb-azjZmSyAABHCZnnTjg002.png#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
  #serviceiptablesstop
  haproxy+keepalived2配置
  IP:192.168.1.20
  #yum   -yinstall pcre-develzlib-devel bzip2-devel kernel-developenssl-devel popt-develzlib-devel
  #tar zxfkeepalived-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
  #chkconfigkeepalivedon
  #scproot@192.168.1.10:/etc/keepalived/keepalived.conf/etc/keepalived/
  #scproot@192.168.1.10:/etc/keepalived/keepalived.conf.bak      /etc/keepalived/远程复制一份主的配置
  #vim /etc/keepalived/keepalived.conf做简单修改即可
https://s5.运维网.com/wyfs02/M01/9F/64/wKioL1mb-c3Qgny7AABcjSHKlRw000.png
  #service keepalived restart
  #ipaddr show   deveth0
https://s3.运维网.com/wyfs02/M00/00/B4/wKiom1mb-eGhKQuuAABiu162kts372.png配置haproxy2
  #tarzxfhaproxy-1.4.24.tar.gz使用源码编译安装
  #cdhaproxy-1.4.24
  #make TARGET=linux26                     64位系统
  #make install
  #mkdir/etc/haproxy                   创建配置文件目录
  #cpexamples/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给一个执行权限
  #servicehaproxystart
  #serviceiptablesstop
  WEB 1配置
  IP:vmnet 1:192.168.1.30
  vmnet 2:192.168.2.20
  #yum-y installpcre-devel zlib-develrpcbind nfs-utils
  #chkconfigrpcbind   on
  # chkconfignfs   on
  #servicerpcbind start
  #service nfsstart
  #useradd-M-s/sbin/nologin nginx
  #tarzxf   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
https://s4.运维网.com/wyfs02/M00/9F/64/wKioL1mb-jPyffF6AAASNpujBVc491.pngWEB 2配置
  IP:vmnet 1:192.168.1.40
  vmnet 2:192.168.2.10
  #yum-y installpcre-devel zlib-develrpcbind nfs-utils
  #chkconfigrpcbind   on
  # chkconfignfs   on
  #servicerpcbind start
  #service nfsstart
  #useradd-M-s/sbin/nologin nginx
  #tarzxf   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
  https://s3.运维网.com/wyfs02/M01/00/B4/wKiom1mb-kjjbPkCAAASNpujBVc795.png客户机windows 7 访问http://192.168.1.254
https://s5.运维网.com/wyfs02/M00/9F/64/wKioL1mb-l-Bbz6FAABOPFZTpbA957.png
  https://s2.运维网.com/wyfs02/M02/00/B4/wKiom1mb-oHDMwleAABgEHbjitE752.png
  把haproxy+keepalived 1宕掉
  客户机测试访问http://192.168.1.254
https://s4.运维网.com/wyfs02/M02/00/B4/wKiom1mb-qjh7yPBAABQC8S4VWM423.png
https://s5.运维网.com/wyfs02/M00/00/B4/wKiom1mb-rODWB1NAABjP8rDgL0619.png
  NFS共享存储配置
  IP:vmnet 2:192.168.2.30
  #yum-yinstallrpcbindnfs-utils
  #chkconfigrpcbind   on
  # chkconfignfs   on
  #mkdir-p/opt/wwwroot
  #vim /etc/exports
  /opt/wwwroot   192.168.2.0/24(rw,sync,no_root_squash)
  #servicerpcbindstart
  #servicenfsstart
  #echo   www.itdby.com> /opt/wwwroot/index.html
  各节点服务器
  mount192.168.2.30:/opt/wwwroot/usr/local/nginx/html/
  客户机测试访问http://192.168.1.254
https://s2.运维网.com/wyfs02/M00/00/B4/wKiom1mb-sHTRcUgAAAeUUnlxUk750.png

页: [1]
查看完整版本: haproxy+keepalived-IT@彦小疯