负载均衡集群HAProxy安装篇
一.HAProxy的yum安装
[[email protected] ~]# yum -y install haproxy//安装
[[email protected] ~]# systemctl start haproxy.service//启动服务
[[email protected] ~]# systemctl status haproxy.service//查看服务
[[email protected] ~]# systemctl enable haproxy.service //设置开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/haproxy.service to
/usr/lib/systemd/system/haproxy.service.
[[email protected] ~]# systemctl stop haproxy.service//停止服务
[[email protected] ~]# systemctl status haproxy.service//停止服务后的状态
二.二.HAProxy的源码安装
[[email protected] ~]# yum -y install gcc//安装依赖包
[[email protected] ~]# wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.14.tar.gz//下载
[[email protected] ~]# tar zxvf haproxy-1.5.14.tar.gz//解压
[[email protected] ~]# cd haproxy-1.5.14/
[[email protected] haproxy-1.5.14]# ll
[[email protected] haproxy-1.5.14]# more README//查看文档
[[email protected] ~]# uname –a//查看本机内核
Linux wjb10000 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] haproxy-1.5.14]# make TARGET=linux26 ARCH=x86_64 PREFIX=/usr/local/haproxy//编译
其中TARGET表示内核版本,ARCH表示位数,PREFIX表示haprxoy的安装路径。
[[email protected] haproxy-1.5.14]# make install PREFIX=/usr/local/haproxy//安装
[[email protected] haproxy-1.5.14]# cp examples/haproxy.cfg /usr/local/haproxy/ //复制配置文件
[[email protected] haproxy-1.5.14]# ll /usr/local/haproxy/
[[email protected] haproxy-1.5.14]# /usr/local/haproxy/sbin/haproxy –v //查看安装后版本信息
[[email protected] /]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg //启动出现错误
[[email protected] /]# vim /usr/local/haproxy/haproxy.cfg //编辑配置文件
[[email protected] haproxy-1.5.14]# cp -r examples/errorfiles/ /usr/local/haproxy/ //复制错误网页
[[email protected] haproxy-1.5.14]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg//重新启动
[[email protected] haproxy-1.5.14]# ps -ef |grep haproxy//查看启动结果成功。
[[email protected]/]#/usr/local/haproxy/sbin/haproxy -f\
/usr/local/haproxy/haproxy.cfg -st `cat /usr/local/haproxy/logs/haproxy.pid`//重启服务
[[email protected] /]# vim /etc/rc.d/init.d/haproxy//创建启动和关闭服务脚本
#!/bin/bash #chkconfig: 2345 10 90 #description:haproxy BASE_DIR="/usr/local/haproxy" ARGV="[email protected]" start() { echo "START HAPoxy SERVERS" $BASE_DIR/sbin/haproxy -f $BASE_DIR/haproxy.cfg } stop() { echo "STOP HAPoxy Listen" kill -TTOU $(cat $BASE_DIR/haproxy.pid) echo "STOP HAPoxy process" kill -USR1 $(cat $BASE_DIR/haproxy.pid) } case $ARGV in start) start ERROR=$? ;; stop) stop ERROR=$? ;; restart) stop start ERROR=$? ;; *) echo "hactl.sh [start|restart|stop]" esac exit $ERROR |
[[email protected] /]# chkconfig --add haproxy//开机自启动服务
[[email protected] /]# chmod +x /etc/rc.d/init.d/haproxy//增加权限