/etc/haproxy/haproxy.cfg configuration files for//haproxy
Haproxy default is to use 5000 port
[[email protected] ~]# lsof-i:80//See if Port 80 is occupied
haproxy-Reverse Proxy
[Email protected] ~]# vim/etc/haproxy/haproxy.cfg
Under the backend Wangdada
Add your real server
Attention! :
Frontend main *: Default is 5000, I should be 80 port.
[Email protected] ~]# systemctl start Haproxy
[Email protected] ~]# lsof-i:80
Add this segment in/etc/haproxy/haproxy.cfg to see the Haproxy status
Listen status
Bind 0.0.0.0:8000
Option Httplog
Stats Refresh 30s
Stats Uri/status
Stats Realm Haproxy_manager_page
Stats Auth Admin:admin
Stats Hide-version
Test: 10.18.42.157:8000/status Enter the password you set
[Email protected] ~]# systemctl restart Haproxy
[Email protected] ~]# lsof-i:8000
haproxy-Agent MySQL
[[email protected] ~]# vim/etc/haproxy/haproxy.cfg//Add Listem msql Segment
[Email protected] ~]# lsof-i:3306
[Email protected] ~]# Systemctl stop mysqld
[Email protected] ~]# systemctl restart Haproxy
[Email protected] ~]# systemctl status Haproxy
[Email protected] ~]# lsof-i:3306
Then add your upstream server (real MySQL) inside MySQL:
Mysql> Grant All on * * to [e-mail protected] ' 10.18.42.% ' identified by ' [email protected] ';
mysql> flush Privileges;
Mysql> select * from Mysql.user\g;
Find a machine to access the 10.18.42.157, substantive access is 10.18.42.74
[Email protected] ~]# mysql-uroot-p ' [email protected] '-H 10.18.42.157
Haproxy High-availability
Haproxy+keepalived
Do two haproxy, will do a configuration file CP one copy, remember the backup configuration file. In this way, there are two identical haproxy, which are installed on both Haproxy servers with the following settings keepalived:
[Email protected] ~]# vim/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Global_defs {
router_id Wang //Multiple keepalived The name cannot be the same
}
vrrp_script chk_haproxy { //Set a vrrp_scrpt, the name is arbitrary
Script "lsof-i:80 | grep Haproxy | | Exit 1 " //determine 80 ports with or without Haproxy, no return 1
Interval 2 //Two seconds to judge each time
fail 1 //Permit failed 1 times
}
Vrrp_instance Web {
State BACKUP//self-select master and backup as appropriate
Interface Ens33
VIRTUAL_ROUTER_ID 43
Priority 250
nopreempt set to No preemption Note: This configuration can only be set on the backup host, and this host priority is higher than the other one
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1234444
}
Track_script {
Chk_haproxy //Call the above script
}
virtual_ipaddress {
10.18.42.188
}
}
compared to the previous increase in content is Cyan The Background section adds a script statement, and a statement that invokes this script. If 80 ports are detected without haproxy,keepalived, the VIP,VIP will be floated to another keepalived server. High availability is achieved.
NDB engine
Lb_ haproxy reverse proxy; agent MySQL; high availability