1.背景:我们使用的是社区版Neo4j不支持集群功能,因此通过对Neo4j进行双写,再通过keepalived实现主备切换
2.环境:Neo4j服务器A(10.23.4.123),Neo4j服务器B(10.23.4.124),VIP(10.23.4.126),服务器均为CentOs
3.安装keepalived1
yum install keepalived
4.修改主机10.23.4.123 keepalived的配置文件/etc/keepalived/keepalived.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30global_defs {
router_id neo4j_master
}
vrrp_script chk_neo4j {
script "netstat -lntp | grep 7687"
interval 1
}
vrrp_instance neo4j {
state BACKUP
interface ens160
lvs_sync_daemon_interface ens160
virtual_router_id 210
priority 150
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.23.4.126
}
track_script {
chk_neo4j
}
}
5.修改主机10.23.4.124 keepalived的配置文件/etc/keepalived/keepalived.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30global_defs {
router_id neo4j_slave
}
vrrp_script chk_neo4j {
script "netstat -lntp | grep 7687"
interval 1
}
vrrp_instance neo4j {
state BACKUP
interface ens160
lvs_sync_daemon_interface ens160
virtual_router_id 210
priority 150
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.23.4.126
}
track_script {
chk_neo4j
}
}
6.启动keepalived1
2systemctl enable keepalived.service
systemctl start keepalived.service
7.验证
- 停止Neo4j-A,在Neo4j-B通过命令ip a查看VIP是否飘到Neo4j-B上
- 停止Neo4j-B,在Neo4j-A通过命令ip a查看VIP是否飘到Neo4j-A上