nfs+keepalived实现一个高可用的nfs共享

			**nfs	+ 	  keepalived**
1.实现两台nfs文件共享实现同步功能
 	互相同步文件inotifywait+rsync

nfs_server1: 安装软件包 nfs-utils rpcbind
修改配置文件/etcexports
/root/nginx 192.168.1.0/24(rw,no_root_squash)
nfs共享的路径 允许1网段所有主机访问取消root自动将级
tar -xf inotify-tools-3.13.tar.gz -C /usr/src/
cd /usr/src/inotify-tools-3.13/
./configure
make && make install
ssh-keygen 创建无密码连接
ssh-copy-id [email protected] 把密钥发送给对方
重启服务nfs-utils rpcbind
showmount -e localhost 看看是否能监测到如果没有执行以下命令
iptables -F 清除一下防火墙就好了
创建一个脚本
#!/bin/bash
FROM_DIR="/root/nginx/"
RSYNC_CMD=“rsync -az --delete $FROM_DIR [email protected]:/root/nginx” 同步给62主机
while inotifywait -rqq -e modify,move,create,delete,attrib $FROM_DIR 循环监测
do
$RSYNC_CMD
done & 放后台运行
chmod +x /root/rsync.sh 给脚本执行权限
./rsync 执行一个脚本
pgrep -l inotify 查看是否在后台运行

nfs_server:2
执行跟nfs_server1的方法一致。

测试在nfs_server1创建文件看看能不能同步

nfs1_server配置keepalived
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
[email protected] 事物邮件
}
notification_email_from [email protected]
smtp_server 192.168.200.1 邮件ip
smtp_connect_timeout 30
router_id nfs1 需要修改id值
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER 设置为主
interface eth0
virtual_router_id 51 vip路由id
priority 100 优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 这个密码要跟另外一台keepalived密码一致
}
virtual_ipaddress {
192.168.1.70 定义一个vip地址(浮动ip)
}
}

virtual_server 192.168.1.70 111 {
delay_loop 6
lb_algo wrr 工作模式
lb_kind DR 工作原理
#persistence_timeout 50 超时时间
protocol TCP 协议

real_server 192.168.1.61 111 {		nfs1_server的ip及端口
    weight 1
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
    }

real_server 192.168.1.62 111 { nfs2_server的ip及端口
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

nfs_server2
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
[email protected] 事物邮件
}
notification_email_from [email protected]
smtp_server 192.168.200.1 邮件ip
smtp_connect_timeout 30
router_id nfs2 需要修改id值
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state BACKUP 设置为从
interface eth0
virtual_router_id 51 vip路由id
priority 50 优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111 这个密码要跟另外一台keepalived密码一致
}
virtual_ipaddress {
192.168.1.70 定义一个vip地址(浮动ip)
}
}

virtual_server 192.168.1.70 111 {
delay_loop 6
lb_algo wrr 工作模式
lb_kind DR 工作原理
#persistence_timeout 50 超时时间
protocol TCP 协议

real_server 192.168.1.61 111 {		nfs1_server的ip及端口
    weight 1
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
    }

real_server 192.168.1.62 111 { nfs2_server的ip及端口
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

你可能感兴趣的:(高可用)