This manual is for keepalived 1.3.6
As some critical functions are unstable in the version 1.2.15, the version 1.3.6 is recommended.
Package description
keepalived package is an open source software used to perform high availability and load balancing functions. The first function is carried out by VRRP protocol implementation, and the second one is based on Linux Vitrual Server (IPVS). keepalived is not developed by Eltex and does not include any updates except configuration. A required version for the operating system used is compiled from source codes available in keepalived official repository on GitHub (https://github.com/acassen/keepalived).
Keepalived is used for SoftWLC controllers backup organization, and only VRRP functionality is applied.
Contact Wi-Fi or Broadband Access Service Center to get keepalived package for Ubuntu 14.04.
Installation
To install the package, download it to a server and run the following command:
root@master:/# dpkg -i keepalived_1.3.6-eltexu14_amd64.deb
Installation should be carried out on behalf of root super user
Starting/stopping procedure
To start the service, run the following command:
service keepalived start
If the service has been started successfully, the response will be:
keepalived start/running, process 2471
To stop the service:
root@master:/# service keepalived stop
System response:
keepalived stop/waiting
To check the service status, run the command:
root@master:/# service keepalived status
Response:
keepalived start/running, process 2809
Configuration
keepalived configuration includes the next files:
File | Description |
/etc/keepalived/keepalived.conf | the main configuration file |
/etc/keepalived/check_ping.sh | a script for EMS status check |
/etc/keepalived/keep_notify.sh | a script ran on state change (when switching to MASTER, BACKUP, FAULT) |
/etc/sysconfig/keepalived | keepalived launch parameters configuration file |
/etc/keepalived/mongo_switch.js | a script for switching replicaSet MongoDB to the state relevant to VRRP |
Main configuration file
The listing of the main configuration file by default
! Configuration File for keepalived global_defs { notification_email { admin@example.org } notification_email_from softwlc@example.org smtp_server mail.example.org smtp_connect_timeout 30 router_id swlc1 enable_traps } vrrp_script check_network { script "/etc/keepalived/check_ping.sh" interval 5 weight 50 fall 3 rise 3 init_fail user root } vrrp_instance VI_SWLC { state BACKUP interface eth0 virtual_router_id 1 track_script { check_network } track_interface { eth0 weight 50 } priority 150 advert_int 1 nopreempt authentication { auth_type PASS auth_pass eltex } virtual_ipaddress { <virtual_ip> dev eth0 label eth0:1 } notify_master "/etc/keepalived/keep_notify.sh master" notify_backup "/etc/keepalived/keep_notify.sh backup" notify_fault "/etc/keepalived/keep_notify.sh fault" unicast_peer { <ip_server1> } }
The configuration file consists of three main sections: global_defs, vrrp_script, vrrp_instance
. The first and the second sections contain definitions of global parameters and the state checking script's configuration respectively, and the third one describes the VRRP instance itself.
Test script
The current implementation offers the following script as a test one:
#!/bin/bash # host to ping # there - default gw HOST=<default_gw_ip> # -q quiet # -c nb of pings to perform ping -q -c5 $HOST > /dev/null # $? var keeping result of execution # previous command if [ $? -eq 0 ] then echo `date +"%T %F"` "OK gw reachable" EXIT_CODE=0 else echo `date +"%T %F"` "ERROR gw unreacheble!" EXIT_CODE=1 fi exit $EXIT_CODE
the script pings a default gateway and returns an output code. Thus, SoftWLC is guaranteed to be accessible for external clients if the script has been executed successfully.
Role change configuration
When the server's state is changed, the keep_notify.sh script is started.
#!/bin/bash MYSQL_USER="<mysql_user>" MYSQL_PASSWORD="<mysql_password>" mongo_set_role() { local role="$1" if [[ "$(which mongo)" ]]; then mongo --quiet --eval "var role=\"$role\"" admin /etc/keepalived/mongo_switch.js # Uncomment if using mongodb auth #mongo -u<username> -p<password> --quiet --eval "var role=\"$role\"" admin /etc/keepalived/mongo_switch.js fi } if ! lockfile-create --use-pid -r 5 /tmp/keep.mode.lock; then echo "Unable to lock" echo "Unable to lock" > /tmp/keep.mode.lock.fail exit 0 fi case "$1" in master) # ems_reload_all echo "MASTER" > /tmp/keep.mode mongo_set_role master service eltex-ems restart service tomcat7 restart service eltex-ngw restart # рестарт слейва MySQL чтобы при восстановлении связи - сразу получить изменения, # а не ждать периодического heartbeat от второго сервера mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "stop slave" mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "start slave" ;; backup) echo "BACKUP" > /tmp/keep.mode mongo_set_role slave service mongodb restart service eltex-ems stop service tomcat7 stop service eltex-ngw stop mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "stop slave" mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e "start slave" ;; fault) echo "FAULT" > /tmp/keep.mode mongo_set_role slave service mongodb restart ;; *) echo "Usage: $0 {master|backup|fault}" exit 1 esac lockfile-remove /tmp/keep.mode.lock; exit 0
ReplicaSet MongoDB master changing script.
// Provided by environment var role; if (role != 'master' && role != 'slave') { throw "Role must be either master or slave"; } var thisIsMaster = (role == 'master'); var status = rs.isMaster(); var thisHost = status.me; print("Primary: " + status.ismaster + "; applying configuration ..."); var cfg = rs.conf(); for (var i = 0; i < cfg.members.length; i++) { var member = cfg.members[i]; var self = (member.host == thisHost); if (self ^ thisIsMaster) { // Configuration for slave member.priority = 1; member.votes = 0; print(member.host + ": secondary"); } else { // Configuration for master member.priority = 2; member.votes = 1; print(member.host + ": primary"); } } var result = rs.reconfig(cfg, { force: !status.ismaster }); if (result.ok == 1) { print("Reconfiguration done"); } else { print(result); }
Keepalived daemon configuration
Parameters for launching etc.
Saving a log to a separate file
By default, keepalived
writes a log to the /var/log/syslog
file. For keepalived debugging, monitoring and managing convenience, separate log filing can be configured. rsyslog
configuration example is introduced below:
nano -w /etc/rsyslog.d/10-keepalived.conf if $programname contains 'Keepalived' then /var/log/keepalived.log if $programname contains 'Keepalived' then ~
Then restart rsyslog using the command:
root@swlc01-server:/# service rsyslog restart
Messages from keepalived daemon will be written only to the /var/log/keepalived.log
file, not to the /var/log/syslog
.