linux
服務器名稱 |
IP地址 |
操做系統 |
軟件包 |
用途 |
VIP地址 |
nosql1.linuxplus.com |
172.16.216.185 |
Centos 7.5 |
libevent-devel,memcached,magent |
主節點 |
172.16.216.200 |
nosql2.linuxplus.com | 172.16.216.186 | Centos 7.5 | libevent-devel,memcached,magent | 備份節點 |
|
nosql3.linuxplus.com | 172.16.216.187 | Centos 7.5 | telnet |
測試節點 |
sql
[root@nosql1 software]# mkdir /opt/software/magent [root@nosql1 software]# tar xf magent-0.5.tar.gz -C /opt/software/magent [root@nosql1 software]# cd magent/ [root@nosql1 magent]# ls ketama.c ketama.h magent.c Makefile [root@nosql1 magent]# vim ketama.h #ifndef _KETAMA_H #define _KETAMA_H 添加: #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif [root@nosql1 magent]# vim Makefile LIBS = -levent -lm #首行LIBS = -levent後加上-lm [root@nosql1 magent]# make gcc -Wall -O2 -g -c -o magent.o magent.c gcc -Wall -O2 -g -c -o ketama.o ketama.c gcc -Wall -O2 -g -o magent magent.o ketama.o -levent -lm [root@nosql1 magent]# ls ketama.c ketama.h ketama.o magent magent.c magent.o Makefile [root@nosql1 magent]# cp magent /usr/bin [root@nosql1 magent]# scp magent root@172.16.216.186:/usr/bin
vim
緩存
[root@nosql1 ~]# yum install keepalived [root@nosql1 ~]# cd /etc/keepalived/ [root@nosql1 keepalived]# vim keepalived.conf ! Configuration File for keepalived global_defs { notification_email { devops@qq.com } notification_email_from devops@qq.com smtp_server mail.qq.com smtp_connect_timeout 30 router_id devops_MA enable_script_security } vrrp_script magent { script "/opt/magent.sh" interval 2 user root } vrrp_instance devops_ha { state MASTER interface ens33 virtual_router_id 51 priority 180 advert_int 1 nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.216.200 } track_script { magent } } [root@nosql1 ~]# vim /opt/magent.sh #!/bin/bash mem=$(ps -ef | grep keepalived | grep -v grep | wc -l) if [ $mem -gt 0 ] then magent -u devops -n 51200 -l 172.16.216.200 -p 12000 -s 172.16.216.185:11211 -b 172.16.216.186:11211 /usr/local/memcached/bin/memcached -u devops -m 128 -d else pkill -9 magent fi [root@nosql1 ~]# systemctl start keepalived.service [root@nosql1 ~]# netstat -ntap | grep 12000 tcp 0 0 172.16.216.200:12000 0.0.0.0:* LISTEN 16649/magent [root@nosql2 keepalived]# netstat -tulnp |grep 11211 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 13959/./memcached tcp6 0 0 :::11211 :::* LISTEN 13959/./memcached
bash
服務器
nosql
tcp
ide
memcached
[root@nosql2 ~]# yum install keepalived [root@nosql2 ~]# cd /etc/keepalived/ [root@nosql2 keepalived]# vim keepalived.conf ! Configuration File for keepalived global_defs { notification_email { devops@qq.com } notification_email_from devops@qq.com smtp_server mail.qq.com smtp_connect_timeout 30 router_id devops_MB enable_script_security } vrrp_script magent { script "/opt/magent.sh" interval 2 user root } vrrp_instance devops_ha { state BACKUP interface ens33 virtual_router_id 52 priority 90 advert_int 1 nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.216.200 } track_script { magent } } [root@nosql2 ~]# vim /opt/magent.sh #!/bin/bash mem=$(ip addr | grep 172.16.216.200 | grep -v grep | wc -l) if [ $mem -gt 0 ] then magent -u devops -n 51200 -l 172.16.216.200 -p 12000 -s 172.16.216.185:11211 -b 172.16.216.186:11211 /usr/local/memcached/bin/memcached -u devops -m 128 -d else pkill -9 magent fi [root@nosql2 ~]# systemctl start keepalived.service [root@nosql2 keepalived]# netstat -tulnp |grep 12000 tcp 0 0 172.16.216.200:12000 0.0.0.0:* LISTEN 27343/magent [root@nosql2 keepalived]# netstat -tulnp |grep 11211 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 13959/./memcached tcp6 0 0 :::11211 :::* LISTEN 13959/./memcached
[root@nosql3 ~]# telnet 172.16.216.200 12000 Trying 172.16.216.200... Connected to 172.16.216.200. Escape character is '^]'. set username 0 0 11 devopsadmin STORED get username VALUE username 0 11 devopsadmin END [root@nosql1 bin]# telnet 172.16.216.185 11211 Trying 172.16.216.185... Connected to 172.16.216.185. Escape character is '^]'. get username VALUE username 0 11 devopsadmin END quit Connection closed by foreign host. [root@nosql2 bin]# telnet 172.16.216.186 11211 Trying 172.16.216.186... Connected to 172.16.216.186. Escape character is '^]'. get username VALUE username 0 11 devopsadmin END quit Connection closed by foreign host.