In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
System: centos7
192.168.1.55 mysql Port 3306 Percona-XtraDB-Cluster Master Node
192.168.1.56 mysql Port 3307 Percona-XtraDB-Cluster+haproxy+keepalived
192.168.1.57 MySQL Port 3307 Percona-XtraDB-Cluster+haproxy+keepalived
192.168.4.58/21 vip ip
Software version: Percona-XtraDB-Cluster-5.7.16-27.19percona-xtrabackup-2.4.5
Haproxy-1.7.0 keepalived-1.3.2
I. configuration of linux system restrictions
1. Turn off the system firewall
Systemctl stop firewalld.service disable Firewall systemctl disable firewalld.service disable Firewall 2, close SElinuxsed-I's Universe SELINUX.Covering Universe SELINUXCPAGO / etc/selinux/configsetenforce 0 selinux takes effect immediately
II. System installation convention
Source package compilation installation location: / usr/local/ software name
Data directory / apps/data
Third, install the package in the source code
Download Percona-XtraDB-Cluster-5.7.16-27.19
Wget-P / usr/local/src https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/Percona-XtraDB-Cluster-5.7.16-27.19/rel-5.7.16/source/tarball/Percona-XtraDB-Cluster-5.7.16-27.19.tar.gz
Download percona-xtrabackup-2.4.5
Wget-P / usr/local/src https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.5/source/tarball/percona-xtrabackup-2.4.5.tar.gz
Download boost_1_59_0
Mkdir-p / usr/local/boostwget-P / usr/local/boost https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
Download haproxy-1.7.0
Wget-P / usr/local/src http://www.haproxy.org/download/1.7/src/haproxy-1.7.0.tar.gz
Download keepalived-1.3.2
Wget-P / usr/local/src http://www.keepalived.org/software/keepalived-1.3.2.tar.gz
Download automake-1.15
Wget-P / usr/local/src ftp://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
Fourth, install the compilation environment and compile dependency
1. Yum-y install epel-release2, uninstall the old mysql or mariadbyum-y remove mariadb* mysql*3, install the compilation environment yum-y install libtool ncurses-devel libgcrypt-devel libev-devel\ git scons gcc gcc-c++ openssl check cmake bison boost-devel\ asio-devel libaio-devel ncurses-devel readline-devel pam-devel socat\ libaio automake autoconf vim redhat-lsb check-devel curl curl-devel xinetd4, Install keepalived dependency (192.168.1.56 192.168.1.57) yum-y install libnl-devel openssl-devel libnfnetlink-devel ipvsadm\ popt-devel libnfnetlink kernel-devel popt-static iptraf
Fifth, compile and install Percona-XtraDB-Cluster-5.7.16-27.19percona-xtrabackup-2.4.5
1. Decompress percona-xtrabackup-2.4.5.tar.gz
Tar-xvf / usr/local/src/percona-xtrabackup-2.4.5.tar.gz-C / usr/local/src/
2. Decompress Percona-XtraDB-Cluster-5.7.16-27.19.tar.gz
Tar-xvf / usr/local/src/Percona-XtraDB-Cluster-5.7.16-27.19.tar.gz-C / usr/local/src/
3. Compile percona-xtrabackup-2.4.5
Cd / usr/local/src/percona-xtrabackup-2.4.5/cmake. /-DBUILD_CONFIG=xtrabackup_release\-DWITH_MAN_PAGES=OFF\-DDOWNLOAD_BOOST=1\-DWITH_BOOST= "/ usr/local/boost" make-J4 & & make installln-sf / usr/local/xtrabackup/bin/* / usr/sbin/
4. Compile and install Percona-XtraDB-Cluster-5.7.16-27.19
4.1.Create mysql username and folder
Mkdir / apps/ {run,log} / mysqld-puseradd mysql-s / sbin/nologin-Mchown-R mysql:mysql / apps
4.2.Compiling garbd,libgalera_smm.so
Cd / usr/local/src/Percona-XtraDB-Cluster-5.7.16-27.19cd "percona-xtradb-cluster-galera" revno value cat GALERA-REVISIONscons-j4 psi=1-- config=force revno= "b98f92f" boost_pool=0 libgalera_smm.soscons-J4-- config=force revno= "b98f92f" garb/garbd create pxc installation directory mkdir-p / usr/local/Percona-XtraDB-Cluster/ {bin Lib} copy the compilation result file to the pxc installation directory cp garb/garbd / usr/local/Percona-XtraDB-Cluster/bincp libgalera_smm.so / usr/local/Percona-XtraDB-Cluster/lib
4.3.Compiler Percona-XtraDB-Cluster-5.7.16-27.19
-DMYSQL_SERVER_SUFFIX is worth getting cd / usr/local/src/Percona-XtraDB-Cluster-5.7.16-27.19WSREProomVERSION = "$(grep WSREP_INTERFACE_VERSION wsrep/wsrep_api.h | cut-d'"'- f2). $(grep 'SET (WSREP_PATCH_VERSION' "cmake/wsrep.cmake" | cut-d' "'- f2)" echo $WSREP_VERSION-DCOMPILATION_COMMENT value gets cd / usr/local/src/Percona-XtraDB-Cluster- 5.7.16-27.19source VERSIONMYSQL_VERSION= "$MYSQL_VERSION_MAJOR.$MYSQL_VERSION_MINOR.$MYSQL_VERSION_PATCH" echo $MYSQL_VERSION REVISION= "$(cd" $SOURCEDIR " Grep'^ short: 'Docs/INFO_SRC | sed-e' s/short: / /') "- DCOMPILATION_COMMENT value Percona XtraDB Cluster binary (GPL) $MYSQL_VERSION-$WSREP_VERSION Revision $REVISION compile Percona-XtraDB-Cluster-5.7.16-27.19 cd / usr/local/src/Percona-XtraDB-Cluster-5.7.16-27.19cmake. /-DBUILD_CONFIG=mysql_release\-DCMAKE_BUILD_TYPE=RelWithDebInfo\-DWITH_EMBEDDED _ SERVER=OFF\-DFEATURE_SET=community\-DENABLE_DTRACE=OFF\-DWITH_SSL=system-DWITH_ZLIB=system\-DCMAKE_INSTALL_PREFIX= "/ usr/local/Percona-XtraDB-Cluster"\-DMYSQL_DATADIR= "/ apps/data"\-DMYSQL_SERVER_SUFFIX= "27.19"\-DWITH_INNODB_DISALLOW_WRITES=ON\ -DWITH_WSREP=ON\-DWITH_UNIT_TESTS=0\-DWITH_READLINE=system\-DWITHOUT_TOKUDB=ON\-DCOMPILATION_COMMENT= "Percona XtraDB Cluster binary (GPL) 5.7.16-27.19 Revision bec0879 "\-DWITH_PAM=ON\-DWITH_INNODB_MEMCACHED=ON\-DDOWNLOAD_BOOST=1\-DWITH_BOOST=" / usr/local/boost "\-DWITH_SCALABILITY_METRICS=ON make-J4 & & make install copy the file to the installation directory cp-R / usr/local/src/Percona-XtraDB-Cluster-5.7.16-27.19/percona-xtradb -cluster-tests / usr/local/Percona-XtraDB-Cluster/ create soft connection mysql system environment ln-sf / usr/local/Percona-XtraDB-Cluster/bin/* / usr/sbin/ copy startup file to system boot directory cp-R / usr/local/Percona-XtraDB-Cluster/support-files/mysql.server / etc/init.d/mysqld copy monitoring file to xinetd management directory cp-R / usr/local/Percona-XtraDB- Cluster/xinetd.d/mysqlchk / etc/xinetd.d/ add dynamic library echo "/ usr/local/Percona-XtraDB-Cluster/lib" > > / etc/ld.so.conf ldconfig
4.4 configure MySQL health check
Vim / etc/xinetd.d/mysqlchkserver = / usr/bin/clustercheck modified to add mysqlchk 9200/tcp # mysqlchk from cp / usr/local/Percona-XtraDB-Cluster/bin/clustercheck to / usr/bin/server = / usr/sbin/clustercheckvim / etc/services if not fixed
4.5my.cnf configuration
192.168.1.55vim / etc/my.cnf# Template my.cnf for PXC# Edit to your environment. [client] socket=/apps/data/mysql.sockport= 3306 [mysqld] user=mysqlserver-id=10055datadir=/apps/datasocket=/apps/data/mysql.socklog-error=/apps/log/mysqld/mysqld.logpid-file=/apps/run/mysqld/mysqld.pidlog-binlog_slave_updatesexpire_logs_days=7port=3306character_set_server = utf8# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Path to Galera librarywsrep_provider=/usr/ Local/Percona-XtraDB-Cluster/lib/libgalera_smm.so# Cluster connection URL contains IPs of nodes#If no IP is found This implies that a new cluster needs to be created # in order to do that you need to bootstrap this nodewsrep_cluster_address='gcomm://192.168.1.55192.168.1.56192.168.1.57'#wsrep_cluster_address=gcomm://# In order for Galera to work correctly binlog format should be ROWbinlog_format=ROW# MyISAM storage engine has only experimental supportdefault_storage_engine=InnoDBwsrep_sst_receive_address=192.168.1.55:6010wsrep_node_incoming_address=192.168.1.55wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.55 Ist.recv_addr=192.168.1.55:6020 "# Slave thread to usewsrep_slave_threads= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galerainnodb_autoinc_lock_mode=2# Node IP addresswsrep_node_address=192.168.1.55# Cluster namewsrep_cluster_name=pxc-cluster#If wsrep_node_name is not specified, then system hostname will be usedwsrep_node_name=pxc-cluster-node-1#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING MASTERpxc_strict_mode=ENFORCING# SST methodwsrep_sst_method=xtrabackup-v2#wsrep_sst_method=rsync#Authentication for SST method # modify your created account and password wsrep_sst_auth= "sstuser:456789"
192.168.1.56vim / etc/my.cnf# Template my.cnf for PXC# Edit to your environment. [client] socket=/apps/data/mysql.sockport= 3307 [mysqld] user=mysqlserver-id=10056datadir=/apps/datasocket=/apps/data/mysql.socklog-error=/apps/log/mysqld/mysqld.logpid-file=/apps/run/mysqld/mysqld.pidlog-binlog_slave_updatesexpire_logs_days=7port=3307character_set_server = utf8# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Path to Galera librarywsrep_provider=/usr/ Local/Percona-XtraDB-Cluster/lib/libgalera_smm.so# Cluster connection URL contains IPs of nodes#If no IP is found This implies that a new cluster needs to be created # in order to do that you need to bootstrap this nodewsrep_cluster_address='gcomm://192.168.1.55192.168.1.56192.168.1.57'#wsrep_cluster_address=gcomm://# In order for Galera to work correctly binlog format should be ROWbinlog_format=ROW# MyISAM storage engine has only experimental supportdefault_storage_engine=InnoDBwsrep_sst_receive_address=192.168.1.56:6010wsrep_node_incoming_address=192.168.1.56wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.56 Ist.recv_addr=192.168.1.56:6020 "# Slave thread to usewsrep_slave_threads= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galerainnodb_autoinc_lock_mode=2# Node IP addresswsrep_node_address=192.168.1.56# Cluster namewsrep_cluster_name=pxc-cluster#If wsrep_node_name is not specified, then system hostname will be usedwsrep_node_name=pxc-cluster-node-2#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING MASTERpxc_strict_mode=ENFORCING# SST methodwsrep_sst_method=xtrabackup-v2#wsrep_sst_method=rsync#Authentication for SST method # modify your created account, Password wsrep_sst_auth= "sstuser:456789" 192.168.1.57vim / etc/my.cnf# Template my.cnf for PXC# Edit to your environment. [client] socket=/apps/data/mysql.sockport= 3307 [mysqld] user=mysqlserver-id=10057datadir=/apps/datasocket=/apps/data/mysql.socklog-error=/apps/log/mysqld/mysqld.logpid-file=/apps/run/mysqld/mysqld.pidlog-binlog_slave_updatesexpire_logs_days=7port=3307character_set_server = utf8# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic -links=0# Path to Galera librarywsrep_provider=/usr/local/Percona-XtraDB-Cluster/lib/libgalera_smm.so# Cluster connection URL contains IPs of nodes#If no IP is found This implies that a new cluster needs to be created # in order to do that you need to bootstrap this nodewsrep_cluster_address='gcomm://192.168.1.55192.168.1.56192.168.1.57'#wsrep_cluster_address=gcomm://# In order for Galera to work correctly binlog format should be ROWbinlog_format=ROW# MyISAM storage engine has only experimental supportdefault_storage_engine=InnoDBwsrep_sst_receive_address=192.168.1.57:6010wsrep_node_incoming_address=192.168.1.57wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.57 Ist.recv_addr=192.168.1.57:6020 "# Slave thread to usewsrep_slave_threads= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galerainnodb_autoinc_lock_mode=2# Node IP addresswsrep_node_address=192.168.1.57# Cluster namewsrep_cluster_name=pxc-cluster#If wsrep_node_name is not specified, then system hostname will be usedwsrep_node_name=pxc-cluster-node-3#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING MASTERpxc_strict_mode=ENFORCING# SST methodwsrep_sst_method=xtrabackup-v2#wsrep_sst_method=rsync#Authentication for SST methodwsrep_sst_auth= "sstuser:456789" # modify your created account and password
4.6 initialize the database
192.168.1.55 initialization data mysqld-- initialize-- user=mysql-- datadir= "/ apps/data" start the database / etc/init.d/mysqld start-- wsrep-cluster-address= "gcomm://" all require a password to enter after closing the database MySQL5.7 / etc/init.d/mysqld stop security mode expects MySQL to change the password mysqld_safe-- wsrep-cluster-address=gcomm://-- user=mysql-- skip-grant-tables-- skip-networking & use mysql Update user set authentication_string=Password ('123456') where user='root';flush privileges;shutdownexit exits MySQLps-ef | grep mysql until MySQL completely shuts down and starts MySQL/etc/init.d/mysqld start again-- wsrep-cluster-address= "gcomm://" to enter MySQL to create a synchronization account and change the root password mysql-u root-p123456 to create a MySQL synchronization account and password GRANT ALL PRIVILEGES ON *. * TO sstuser@'%' IDENTIFIED BY' 456789; FLUSH PRIVILEGES GRANT ALL PRIVILEGES ON *. * TO sstuser@'localhost' IDENTIFIED BY '456789; FLUSH PRIVILEGES; modifies root to connect remotely to GRANT ALL PRIVILEGES ON *. * TO root@'%' IDENTIFIED BY' 123456; FLUSH PRIVILEGES; creates health check database account password GRANT PROCESS ON *. * TO 'clustercheckuser'@'localhost' IDENTIFIED BY' clustercheckpasswordpassword' If you use your own account password, please change the account password corresponding to vim / usr/sbin/clustercheck 192.168.1.56 192.168.1.57 other nodes directly start service mysqld start restart the first node 192.168.1.55 service mysqld restart error / etc/init.d/mysqld bootstrap-pxc boot completed login MySQL mysql-u root-p123456 check the number of MySQL nodes mysql > show global status like 'wsrep_cluster_size' +-+-+ | Variable_name | Value | +-+-+ | wsrep_cluster_size | 3 | +-+-+ 1 row in set (0.00 sec) mysql > show global status like 'wsrep_incoming_addresses' +-- +-- + | Variable_name | Value | +- -+-- + | wsrep_incoming_addresses | 192.168.1.57 _ 3307192.168.1.56 _ 3307192.168.1.55 _ 3306 | +- -+-+ 1 row in set (0.00 sec) create test data to see if mysql > create database test is synchronized Query OK, 1 row affected (0.01sec)
4.7 Database health check starts
Systemctl start xinetd.service check whether port 9200 is open netstat-anlp | grep 9200tcp6 00:: 9200: * LISTEN 73323/xinetd tests whether the port is normal telnet 192.168.1.55 9200Escape character is'^] .HTTP/1.1 200 OKContent-Type: text/plainConnection: closeContent-Length: 40Percona XtraDB Cluster Node is synced.Connection closed by foreign host. If you don't check the account password of the linked database, please modify vim / etc/xinetd.d/mysqlchkuser root restart systemctl restart xinetd.service and test again. If you return 200, ok or error, please check the system log to fix it.
6. Compile and install haproxy (192.168.1.56192.168.1.57)
Install haproxy logging support yum-y install rsyslog extract haproxy-1.7.0.tar.gz tar-xvf / usr/local/src/haproxy-1.7.0.tar.gz-C / usr/local/src/cd / usr/local/src/haproxy-1.7.0make TARGET=linux31 PREFIX=/usr/local/haproxymake install PREFIX=/usr/local/haproxy create folder haproxymkdir-pv / usr/local/haproxy/ {conf,run Log} create the haproxy startup script vim / ETC _ init. D _ description! / bin/bash# chkconfig:-85 minutes description: haproxy is a World Wide Web server. It is used to servePROGDIR=/usr/local/haproxyPROGNAME=haproxyDAEMON=$PROGDIR/sbin/$PROGNAMECONFIG=$PROGDIR/conf/$PROGNAME.confPIDFILE=$PROGDIR/run/$PROGNAME.pidDESC= "HAProxy daemon" SCRIPTNAME=/usr/local/haproxy/init.d/$PROGNAME# Gracefully exit if the package has been removed.test-x $DAEMON | | exit 0start () {echo-n "Starting $DESC: $PROGNAME" $DAEMON-f $CONFIG echo "."} stop () {echo-n "Stopping $DESC: $PROGNAME" cat $PIDFILE | xargs kill echo "."} reload () {echo-n "reloading $DESC: $PROGNAME" $DAEMON-f $CONFIG-p $PIDFILE-sf $(cat $PIDFILE)} case "$1" in start) start ; stop) stop;; restart) stop start;; reload) reload;; *) echo "Usage: $SCRIPTNAME {start | stop | restart | reload}" > & 2 exit 1;; esacexit 0chmod + x / etc/init.d/haproxy # executable permission
Create haproxy.conf
Vim / usr/local/haproxy/conf/haproxy.conf global log 127.0.0.1 local0 log 127.0.0.1 local1 notice # log loghost local0 info maxconn 50000 chroot / usr/local/haproxy uid 99 gid 99 daemon nbproc 2 Pidfile / usr/local/haproxy/run/haproxy.pid # debug # quiet defaults log global mode tcp option tcplog option dontlognull option forwardfor option redispatch retries 3 timeout connect 3000 Timeout client 50000 timeout server 50000frontend admin_stat bind *: 8888 mode http default_backend stats-backfrontend pxc-front bind *: 3306 mode tcp default_backend pxc-backfrontend pxc-onenode-front bind *: 3308 mode tcp default_backend pxc-onenodebackend pxc-back mode tcp balance Roundrobin option httpchk server node1 192.168.1.55:3306 check port 9200 inter 12000 rise 3 fall 3 server node2 192.168.1.56:3307 check port 9200 inter 12000 rise 3 fall 3 server node3 192.168.1.57:3307 check port 9200 inter 12000 rise 3 fall 3backend pxc-onenode mode tcp balance roundrobin option httpchk server node1 192.168.1.55:3306 check port 9200 inter 12000 rise 3 fall 3 server Node2 192.168.1.56 inter 3307 check port 9200 inter 12000 rise 3 fall 3 backup server node3 192.168.1.57 inter 3307 check port 9200 inter 12000 rise 3 fall 3 backupbackend stats-back mode http balance roundrobin stats uri / admin?stats stats auth admin:admin stats realm Haproxy\ StatisticsHaproxy rsyslog log configuration vim / etc/rsyslog.conf # $ModLoad imudp modify $ModLoad imudp # $UDPServerRun 514 modify $UDPServerRun 51log add Haproxy log Recording path local0.* / usr/local/haproxy/log/haproxy.log restart rsyslogsystemctl restart rsyslog.service start Haproxy service haproxy start join boot boot chkconfig haproxy on check whether haproxy starts ps-ef | grep haproxy haproxy access port 8888 account password admin:admin http://192.168.1.56:8888/admin?statshttp://192.168.1.57:8888/admin?stats
7. Compile and install keepalived
Install automake-1.15tar-xvf / usr/local/src/automake-1.15.tar.gz-C / usr/local/srccd / usr/local/src/automake-1.15./configure & & make & & make install
Compile keepalived
Tar-xvf / usr/local/src/keepalived-1.3.2.tar.gz-C / usr/local/srccd / usr/local/src/keepalived-1.3.2./configure-- prefix=/usr/local/keepalivedvmware virtual machine installation modification. / lib/config.hHAVE_DECL_RTA_ENCAP 1 modified to HAVE_DECL_RTA_ENCAP 0 if you do not modify the compilation will report an error make & & make install copy the keepalived executable file to / usr/sbin/cp / usr / local/keepalived/sbin/keepalived / usr/sbin/
Create a keepalived startup script
Vim / et _ c _ description _ r _ r / etc/rc.d/init.d/functions# Source configuration file (we set KEEPALIVED_OPTIONS there). / etc/sysconfig/keepalivedRETVAL=0prog= "keepalived" start () {echo-n $"Starting $prog:" daemon keepalived ${KEEPALIVED_OPTIONS} RETVAL=$? Echo [$RETVAL-eq 0] & & touch / var/lock/subsys/$prog} stop () {echo-n $"Stopping $prog:" killproc keepalived RETVAL=$? Echo [$RETVAL-eq 0] & & rm-f / var/lock/subsys/$prog} reload () {echo-n $"Reloading $prog:" killproc keepalived-1 RETVAL=$? Echo} # See how we were called.case "$1" in start) start;; stop) stop;; reload);; restart) stop start;; condrestart) if [- f / var/lock/subsys/$prog]; then stop start fi Status) status keepalived RETVAL=$?; *) echo "Usage: $0 {start | stop | reload | restart | condrestart | status}" RETVAL=1esacexit $RETVALchmod + x / etc/rc.d/init.d/keepalived # keepalived executable
Configure keepalived
Cp / usr/local/keepalived/etc/sysconfig/keepalived / etc/sysconfig/ create / etc/keepalived folder mkdir-p / etc/keepalived
Create / etc/keepalived/keepalived.conf (192.168.1.56)
Vim / etc/keepalived/keepalived.conf! When Configuration File for keepalivedglobal_defs {notification_email {admin@test.com # fails Email address} notification_email_from admin@test.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_script chk_haproxy {# Custom Monitoring script script "/ etc/keepalived/chk_haproxy.sh" interval 2 weight 2} vrrp_instance VI_1 {state BACKUP # Let VIP not take back nopreempt interface eth0 # listening interface virtual_router_id 51 priority 100 # priority The priority on the backup machine should be lower than this value advert_int 1 # check interval authentication {auth_type PASS auth_pass 1111} track_script {# custom monitoring script chk_haproxy} virtual_ipaddress { # VIP address You can set more than one 192.168.4.58 notify_fault 21} notify_backup "/ etc/init.d/haproxy restart" notify_fault "/ etc/init.d/haproxy stop"}
Create / etc/keepalived/keepalived.conf (192.168.1.57)
! When Configuration File for keepalivedglobal_defs {notification_email {admin@test.com # fails Email address} notification_email_from admin@test.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL} vrrp_script chk_haproxy {# Custom Monitoring script script "/ etc/keepalived/chk_haproxy.sh" interval 2 weight 2} vrrp_instance VI_1 {state BACKUP # keep VIP from taking back nopreempt interface eth0 # listening interface virtual_router_id 51 priority 99 # priority The priority on the backup machine should be lower than this value advert_int 1 # check interval authentication {auth_type PASS auth_pass 1111} track_script {# custom monitoring script chk_haproxy} virtual_ipaddress { # VIP address You can set more than one 192.168.4.58 notify_fault 21} notify_backup "/ etc/init.d/haproxy restart" notify_fault "/ etc/init.d/haproxy stop"}
Create / etc/keepalived/chk_haproxy.sh
Vim / etcswap keepalivedhaproxy eq eq. Then / etc/init.d/haproxy startfisleep 2if [$(ps-C haproxy-- no-header | wc-l)-eq 0]; then / etc/init.d/keepalived stopfichmod + x / etc/keepalived/chk_haproxy.sh# executable permissions
Start keepalived
192.168.1.56service keepalived start ip a1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6:: 1/128 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:1b: 50:a3 brd ff:ff:ff:ff:ff:ff inet 192.168.1.56/21 brd 192.168.7.255 scope global dynamic eth0 valid_lft 44444sec preferred_lft 44444sec inet 192.168.4.58/21 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe1b:50a3/64 scope link valid_lft forever preferred_lft forever192.168.1.57service keepalived start 1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6:: 1/128 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:63:ae:85 brd ff:ff:ff:ff:ff:ff inet 192.168 . 1.57/21 brd 192.168.7.255 scope global dynamic eth0 valid_lft 58142sec preferred_lft 58142sec inet6 fe80::20c:29ff:fe63:ae85/64 scope link valid_lft forever preferred_lft forever
Shut down the 192.168.1.56 keepalived process
Service keepalived stop [root@56~] # ip a1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6:: 1/128 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:1b: 50:a3 brd ff:ff:ff:ff:ff:ff inet 192.168.1.56/21 brd 192.168.7.255 scope global dynamic eth0 valid_lft 44258sec preferred_lft 44258sec inet6 fe80::20c:29ff:fe1b:50a3/64 scope link valid_lft forever preferred_lft forever
View 192.168.1.57
[root@57~] # ip a 1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6:: 1/128 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:63:ae: 85 brd ff:ff:ff:ff:ff:ff inet 192.168.1.57/21 brd 192.168.7.255 scope global dynamic eth0 valid_lft 57869sec preferred_lft 57869sec inet 192.168.4.58/21 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe63:ae85/64 scope link valid_lft forever preferred_lft forever
The other two keepalived are configured to BACKUP when the first failure recovers without preempting the IP service that is providing the service will not flash off. Haproxy configuration dual-port link 3306 is to load three servers at the same time 3308 is only one to use when the first one is dead.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.