Deployment diagram:
Haproxy Installation
181 and 1792 servers install Haproxy the same steps
--Create Haproxy user
Useradd haproxy--
after unpacking, go to haproxy directory
CD haproxy-1.4.25/
--Compile installation make
target=linux26 Prefix=/usr/local/haproxy arch=x86_64 make
install Prefix=/usr/local/haproxy
haproxy Configuration
Cd/usr/local/haproxy Touch
haproxy.cfg
vim haproxy.cfg
global log 127.0.0.1 local0 # #记日志的功能 maxconn 4096 chroot/usr/local/haproxy user haproxy Group ha Proxy daemon defaults log global option Dontlognull retries 3 option Redispatch maxconn contimeout 5000
Srvtimeout 50000 Listen admin_stats 192.168.57.180:48800 stats # #统计页面 T 50000 Stats Auth admin:admin mode http option httplog Listen allmycat_service 192.168.57.180:8098 mode TC P option tcplog option httpchk OPTIONS * http/1.1\r\nhost:\ www balance roundrobin server mycat_181 192.16 8.57.181:8066 Check Port 48700 Inter 5s Rise 2 Fall 3 server mycat_179 192.168.57.179:8066 Check Port 48700 Inter 5s RIS E 2 Fall 3 srvtimeout 20000
Configuring the Haproxy logging feature
Yum–y Install Rsyslog
mkdir/etc/rsyslog.d
cd/etc/rsyslog.d/touch
haproxy.conf
vim haproxy.conf
$ModLoad imudp
$UDPServerRun 514
local0.*/var/log/haproxy.log
vim/etc/rsyslog.conf
Add the following on the line above the RULES #
# Include all config files in/etc/rsyslog.d/
$IncludeConfig/etc/rsyslog.d/*.conf
Add the following below local7.*/var/log/boot.log
local0.*/var/log/haproxy.log
Restart the Rsyslog service
Service Rsyslog Restart
Add Rsyslog to the auto start service
Chkconfig--add rsyslog
chkconfig--level 2345 Rsyslog on
Configure monitor Mycat whether it survives
Installing the XINETD Plugin
Yum Install Xinetd-y
CD/ETC/XINETD.D Touch
mycat_status
vim mycat_status
Service Mycat_status
{
flags = reuse
Socket_type = stream
port = 48700 wait
= no
user = Nobody
server =/usr/local/bin/mycat_status
log_on_failure + = USERID
disable = no
}
Create xinetd Boot Service script
Vim/usr/local/bin/mycat_status
#!/bin/bash
#/usr/local/bin/mycat_status.sh
# This script checks if a MYCAT server are healthy running on localhost . It'll
# return:
#
' http/1.x ok\r ' (if Mycat is running smoothly)
#
"http/1.x 503 Internal Se RVer error\r "(else)
mycat= '/usr/local/mycat/bin/mycat status |grep ' not running ' | wc-l '
IF [" $mycat "=" 0 "];
then
/bin/echo-e "http/1.1 ok\r\n"
else
/bin/echo-e "http/1.1 503 Service unavailable\r\n"
fi
Modify script file permissions
I was here for a long time, according to the authoritative guide mycat_status the contents of this script also have a lot of problems, there are no spaces in several places.
chmod 777/usr/local/bin/mycat_status
chmod 777/etc/xinetd.d/mycat_status
Add a startup script to the service
Vim/etc/services
Add at end
Mycat_status 48700/tcp # Mycat_status
Restart the XINETD service
Service xinetd Restart
Add xinetd to the self-boot service
Chkconfig--add xinetd
chkconfig--level 2345 xinetd on
Create a haproxy start-stop script
Startup script
Touch/usr/local/haproxy/sbin/start
chmod +x/usr/local/haproxy/sbin/start
vim /usr/local/haproxy/ Sbin/start
#!/bin/sh
/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg &
Close Script
Touch/usr/local/haproxy/sbin/stop
chmod +x/usr/local/haproxy/sbin/stop
vim/usr/local/haproxy/sbin/stop
#!/bin/sh
ps-ef | grep sbin/haproxy | grep-v grep |awk ' {print $} ' |xargs Kill-s 9
Authorized
Chown-r haproxy.haproxy/usr/local/haproxy/*
keepalived Installation Steps
The keepalived installation step process is consistent on both servers except for a slightly different keepalived.conf configuration file. OpenSSL installation
Yum Install Openssl-y
./config--prefix=/usr/local/openssl
./config-t make depend make to
test make
install
Ln -s/usr/local/openssl/usr/local/ssl
vim/etc/ld.so.conf
Add the following at the end of the file
/usr/local/openssl/lib
Modifying environment Variables
Vim/etc/profile
Add the following at the end of the file
Export Openssl=/usr/local/openssl/bin
export path= $PATH: $OPENSSL
Make environment variables effective immediately
Source/etc/profile
Install Openssl-devel
Yum Install Openssl-devel-y
Test
Ldd/usr/local/openssl/bin/openssl
Linux-vdso.so.1 => (0x00007fff996b9000)
libdl.so.2 =>/lib64/libdl.so.2 (0x00000030efc00000)
Libc.so.6 =>/lib64/libc.so.6 (0x00000030f0000000)
/lib64/ld-linux-x86-64.so.2 (0x00000030ef800000)
which OpenSSL
/usr/bin/openssl
OpenSSL version
OpenSSL 1.0.0-fips 2010
keepalived Installation
./configure--prefix=/usr/local/keepalived make make
install
cp/usr/local/keepalived/sbin/keepalived /usr/sbin/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
cp/usr/local/keepalived/etc /rc.d/init.d/keepalived/etc/init.d/
mkdir/etc/keepalived
cd/etc/keepalived/
cp/usr/local/ keepalived/etc/keepalived/keepalived.conf/etc/keepalived
mkdir-p /usr/local/keepalived/var/log
Create configuration files and scripts
Mkdir/etc/keepalived/scripts
cd/etc/keepalived/scripts
vim/etc/keepalived/keepalived.conf Master
!
Configuration fileforkeepalived vrrp_script chk_http_port {script "/etc/keepalived/scripts/check_haproxy.sh" Interval 2 weight 2} vrrp_instance vi_1 {State MASTER #192.168.57.179 to Backup interface eth0 #对外提供服务的网络接口 Virtual_route r_id #VRRP组名, two node settings must be the same, to indicate that each node belongs to the same VRRP group priority #数值愈大, the higher the priority, backup on the Advert_int 1 #同步通知间隔 authentication { #包含验证类型和验证密码. Types mainly have pass, ah two kinds, commonly used type of pass, AH is said to use the problem Auth_type pass Auth_pass 1111} track_script {Chk_http_port #调用脚本check_ haproxy.sh Check if Haproxy is alive} virtual_ipaddress {#vip地址, this IP must be consistent with our VIP set in the LVS client 192.168.57.180 dev eth0 scope Global} not
Ify_master/etc/keepalived/scripts/haproxy_master.sh notify_backup/etc/keepalived/scripts/haproxy_backup.sh Notify_fault/etc/keepalived/scripts/haproxy_fault.sh notify_stop/etc/keepalived/scripts/haproxy_stop.sh}
Backup
!
Configuration fileforkeepalived vrrp_script chk_http_port {script "/etc/keepalived/scripts/check_haproxy.sh" Interval 2 weight 2} vrrp_instance vi_1 {state backup #192.168.57.179 to Backup interface eth0 #对外提供服务的网络接口 Virtual_route r_id #VRRP组名, the settings for two nodes must be the same, to indicate that each node belongs to the same VRRP group priority #数值愈大, the higher the priority, backup on the Advert_int 1 #同步通知间隔 authentication { #包含验证类型和验证密码. Types mainly have pass, ah two kinds, commonly used type of pass, AH is said to use the problem Auth_type pass Auth_pass 1111} track_script {Chk_http_port #调用脚本check_ haproxy.sh Check if Haproxy is alive} virtual_ipaddress {#vip地址, this IP must be consistent with our VIP set in the LVS client 192.168.57.180 dev eth0 scope Global} not
Ify_master/etc/keepalived/scripts/haproxy_master.sh notify_backup/etc/keepalived/scripts/haproxy_backup.sh Notify_fault/etc/keepalived/scripts/haproxy_fault.sh notify_stop/etc/keepalived/scripts/haproxy_stop.sh}
vim/etc/keepalived/scripts/check_haproxy.sh
#!/bin/bash
starthaproxy= "/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg"
stopkeepalived= "/etc/init.d/keepalived Stop"
logfile= "/usr/local/keepalived/var/log/ Keepalived-haproxy-state.log "
echo" [Check_haproxy status] ">> $LOGFILE
a= ' ps-c haproxy--no-header |WC -L '
echo [check_haproxy status] >> $LOGFILE
date >> $LOGFILE
if [$A-eq 0];then
Echo $STAR Thaproxy >> $LOGFILE
$STARTHAPROXY >> $LOGFILE 2>&1 sleep
5
fi
If [' Ps-c haproxy --no-header |wc-l '-eq 0];then
exit 0
Else
exit 1
fi
vim/etc/keepalived/scripts/haproxy_master.sh
#!/bin/bash
starthaproxy= '/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg '
STOPHAPROXY = ' Ps-ef | grep Sbin/haproxy | Grep-v grep | awk ' {print $} ' | Xargs kill-s 9 '
logfile= '/usr/local/keepalived/var/log/keepalived-haproxy-state.log '
echo ' [Master] ' > > $LOGFILE
Date >> $LOGFILE
echo "Being master ..." >> $LOGFILE 2>&1
echo "Stop Haproxy ... ">> $LOGFILE 2>&1
$STOPHAPROXY >> $LOGFILE 2>&1
echo" Start Haproxy ... " >> $LOGFILE 2>&1
$STARTHAPROXY >> $LOGFILE 2>&1
echo "Haproxy stared ..." >> $ LOGFILE
vim/etc/keepalived/scripts/haproxy_backup.sh
#!/bin/bash
starthaproxy= '/usr/local/haproxy/sbin/haproxy-f/usr/local/haproxy/haproxy.cfg '
STOPHAPROXY = ' Ps-ef | grep Sbin/haproxy | Grep-v grep | awk ' {print $} ' | Xargs kill-s 9 '
logfile= "/usr/local/keepalived/var/log/keepalived-haproxy-state.log"
echo "[Backup]" > > $LOGFILE
Date >> $LOGFILE
echo "Being backup ..." >> $LOGFILE 2>&1
echo "Stop Haproxy ... ">> $LOGFILE 2>&1
$STOPHAPROXY >> $LOGFILE 2>&1
echo" Start Haproxy ... " >> $LOGFILE 2>&1
$STARTHAPROXY >> $LOGFILE 2>&1
echo "Haproxy stared ..." >> $ LOGFILE
vim/etc/keepalived/scripts/haproxy_fault.sh
#!/bin/bash
Logfile=/usr/local/keepalived/var/log/keepalived-haproxy-state.log
echo "[Fault]" >> $ LOGFILE
Date >> $LOGFILE
vim/etc/keepalived/scripts/haproxy_stop.sh
#!/bin/bash
Logfile=/usr/local/keepalived/var/log/keepalived-haproxy-state.log
echo "[Stop]" >> $ LOGFILE
Date >> $LOGFILE
give script executable permissions
chmod 777/etc/keepalived/scripts/*
Add keepalived to the self-boot service
Chkconfig--add keepalived
chkconfig--level 2345 keepalived on
--Start Services service
keepalived start
Authoritative guide The code section is a lot of problems, almost every piece of code have problems, sometimes a space takes a long time to find this problem, so in the code to be careful; in particular, copy other people's code do not originally copied the best is to check, In addition to the code itself problem permissions are sometimes easy to ignore errors, especially the executable file to note whether there are executable permissions.