Install the Keepalived Tool

Source: Internet
Author: User
Tags install openssl

Before installing keepalived, check whether the host has been installed. If ps-ef | grep keepalive is not checked, it is easy to overwrite the previously installed content, in this case, the configuration files we used to get are not much trouble.
The following are all root user upload tools. The compressed package is more than 200 kb, not large. Cd & mkdir fwy & chmod 777 fwy & cd fwy scp padba @ cnsz081003:/paic/dba/dbsoft/mysql/keepalived-1.1.19.tar.gz. Password MdCg2014 tar xvf keepalived-1.1.19.tar.gz mv keepalived-1.1.19 ..
Install OpenSSL [root @ cnsh042942 fwy] # yum install openssl-devel Loaded plugins: product-id, security, sub‑manager This system is not registered to Red Hat sub‑management. you can use sub‑manager to register. el6_u5_base | 1.2 kB 00:00 Setting up Install Process Package openssl-devel-1.0.1e-15.el6.x86_64 already installed and latest version Nothing to do
Compile and install mv/root/fwy/keepalived-1.1.19/root cd/root/keepalived-1.1.19./configure make & make install
Configure cp/usr/local/etc/rc. d/init. d/keepalived/etc/rc. d/init. d/cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/mkdir/etc/keepalived cp/usr/local/sbin/keepalived/usr/sbin/mkdir/opt /keepalived touch/etc/keepalived. conf
Configure the script [root @ cnsh042942 keepalived] # ip a 1: lo: <LOOPBACK, UP, LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00 inet 127.0.0.1/8 scope host lo inet6 :: 1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST, MULTICAST, SLAVE, UP, LOWER_UP> mtu 1500 qdisc mq master bond0 state UP qlen 1000 link/ether 00: 50: 56: aa: 0a: 89 brd ff: ff: ff 3: bond0: <BROADCAST, MULTICAST, MASTER, UP, LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 00: 50: 56: aa: 0a: 89 brd ff: ff inet 10.31.10.138/24 brd 10.31.10.255 scope global bond0 inet6 fe80 :: 250: 56ff: feaa: a89/64 scope link valid_lft forever preferred_lft forever
Our 10.31.10.138 is bound to bond0, and bond0 should be considered a virtual Nic. Specifically, the interface bond0 bond0, virtual_router_id 117 117, the address in virtual_ipaddress, is written as the desired vip, and DA first applies for a vip to avoid conflict.
Touch/opt/keepalived/keepalived_check_mysql.sh touch/opt/keepalived/to_master.sh
Keepalived. conf configuration file, which exists but is empty. Ls-l/etc/keepalived. conf
The Master node uses the following script: vrrp_script check_mysql {script "/opt/keepalived/keepalived_check_mysql.sh" weight-10} vrrp_instance KEEPALIVED_MYSQL {## note: both MYSQL servers are set to BACKUP state backup interface bond0 virtual_router_id 117 # Master is set to 101, slave is set to 100 priority 101 nopreempt track_script {check_mysql} virtual_ipaddress {10.31.10.152} yy_master/opt/keepalived/to_master.sh} vrrp_script check_mysql {s Keep "/opt/keepalived/keepalived_check_mysql.sh" weight-10} The virtual_router_id value of the master database and slave database must be the same. For mysql, if the same network segment already has the same virtual_router_id used, then it fails.
The server Load balancer node uses the following script. You can note that the priority is 1 smaller than the preceding one. Vrrp_instance KEEPALIVED_MYSQL {## Note: Both MYSQL servers are set to BACKUP state backup interface bond0 virtual_router_id 117 # Master is set to 101, slave is set to 100 priority 100 # nopreempt track_script {check_mysql} virtual_ipaddress {10.31.10.152} yy_master/opt/keepalived/to_master.sh}

Creating a channel is to define some users in mysql that can log on with ciphertext, and then directly use password to log on to some tools to ensure security. Switch to mysql user: mysql_config_editor set -- login-path = keepalived_monitor -- host = localhost -- user = keepalived -- password -- socket =$ {MYSQL_HOME}/var/mysql. sock is generated in the mysql user's home directory. mylogin. cnf file.
Root User cd/opt/keepalived/keepalived_check_mysql.sh Script: MYSQL =/usr/bin/mysql, to change it to/paic/t0gimp/rdbms/mysql/5.6/bin/mysql LOG_FILE =/opt/keepalived/check_mysql.log, you can change it to/opt/keepalived/check_t0gimp.log export with a better name. MYSQL_TEST_LOGIN_FILE =/paic/emmsq/data/mysqldata/emmsq /. mylogin. cnf, this. mylogin. the cnf file is automatically created when the mysql user creates a channel under the Home Directory of the mysql user. $ MYSQL -- login-path = keepalived_monitor-e's "keepalived_monitor changed to the actual channel name"
#! /Bin/bash MYSQL =/paic/t0gimp/rdbms/mysql/5.6/bin/mysql # Log File LOG_FILE =/opt/keepalived/check_t0gimp.log export MYSQL_TEST_LOGIN_FILE =/paic/t0gimp/rdbms /mt0gimp /. mylogin. cnf # Check times CHECK_TIME = 3 # mysql is working MYSQL_ OK is 1, mysql down MYSQL_ OK is 0 MYSQL_ OK = 1 function check_mysql_helth () {$ MYSQL -- login-path = keepalived_monitor-e "show status;">/dev/null 2> & 1 if [$? = 0]; then MYSQL_ OK = 1 else MYSQL_ OK = 0 fi return $ MYSQL_ OK} while [$ CHECK_TIME-ne 0] do let "CHECK_TIME-= 1" check_mysql_helth if [$ MYSQL_ OK = 1]; then CHECK_TIME = 0 # echo 'date -- date = today + "% Y-% m-% d % H: % M: % S" '-[INFO]-mysql available: success [$ MYSQL_ OK]> $ LOG_FILE exit 0 fi if [$ MYSQL_ OK-eq 0] & [$ CHECK_TIME-eq 0] then echo 'date -- date = today + "% y-% m-% d % H: % M: % S "'-[INFO]-mysql invaild. keepalived stop.> $ LOG_FILE exit 1 fi sleep 1 done

To_master.sh this is the shell script run after switching from the database to the master database.
#! /Bin/bash MYSQL =/paic/t0gimp/rdbms/mysql/5.6/bin/mysql VIP = 10.31.10.152 GATEWAY = 10.31.10.200/sbin/arping-I bond0-c 5-s $ VIP $ GATEWAY &>/dev/null $ MYSQL -- login-path = keepalived_switch-e "set global read_only = OFF">/dev/null 2> & 1
Sh script authorizes cd/opt/keepalived chmod 700 *. sh
Start and Stop keepalived [root @ cnsh281018 ~] #/Etc/init. d/keepalived start [root @ cnsh281018 ~] #/Etc/init. d/keepalived stop
Verify that [root @ cnsh042942 keepalived] #/etc/init. d/keepalived start Starting keepalived: [OK] [root @ cnsh042942 keepalived] # ps-ef | grep keepa root 20353 1 0? 00:00:00 keepalived-D root 20354 20353 0? 00:00:00 keepalived-D root 20372 1 0? 00:00:00/bin/bash/opt/keepalived/keepalived_check_mysql.sh root 20382 20354 3? 00:00:00 keepalived-D root 20383 20382 0? 00:00:00/bin/bash/opt/keepalived/keepalived_check_mysql.sh root 20394 17696 0 00:00:00 pts/2 grep keepa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.