NFS high availability

Roles service IP
Master nfs service, sersync Service 192.168.31.155
Slave rsync service 192.168.31.150
Client 192.168.31.140

Shared directory / data / www / web

Mount the directory / mnt

Installation configuration NFS shared directory

1. Install nfs

The server and the client need to install

yum install -y nfs-utils rpcbind

NFS-Master、NFS-Slave:

echo '/data/www/web 192.168.31.0/24(rw,sync,all_squash)' >> /etc/exports
systemctl start rpcbind && systemctl start nfs
systemctl enable rpcbind && systemctl enable nfs
并且需要配置防火墙,否则客户端有可能挂载失败,连接不上

Configure the firewall release nfs service

firewall-cmd --permanent --add-service=nfs

(Note that first start rpcbind, restart nfs)


Installation Configuration rsync + Sersync

Rsync installed on NFS-Slave end , because we write data on NFS-Master to be backed up to the NFS-Slave server, so we start rsync on NFS-Slave

we /etc/rsyncd.conf

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area

uid = nfsnobody
gid = nfsnobody
port = 873
pid file = /var/rsyncd.pid
log file = /var/log/rsyncd.log
use chroot = no
max connections = 200
read only = false
list = false
fake super = yes
ignore errors
[test_nfs]
path = /test_nfs
auth users = test_nfs
secrets file = /etc/rsync.pass
hosts allow = 192.168.31.0/24
systemctl start rsyncd && systemctl enable rsyncd
echo 'test_nfs:zsf123' > /etc/rsync.pass
chmod 600 /etc/rsync.pass
chown nfsnobody:nfsnobody /test_nfs/

Log Files /var/log/rsyncd.log


Install and configure keepalived

1. yum install keepalived -y

2. vi /etc/keepalived/keepalived.conf

MASTER

//全局定义模块
global_defs {
   router_id NFS-Master
   //运行keepalive机器的标识
}

vrrp_instance VI_1 {
    //靠priority 来区别主从,这个不生效
    state MASTER
    //实例绑定的网卡
    interface enp0s31f6
    //组ID,值一样为一个组
    virtual_router_id 51
    //优先级,优先级高的为master
    priority 150
    //检查时间间隔
    advert_int 1
    //认证模式为密码认证
    authentication {
        auth_type PASS
        auth_pass zhangshoufu
    }
    //设置的VIP
    virtual_ipaddress {
        192.168.1.101
    }
}

BACKUP

global_defs {
   router_id NFS-Slave
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp0s31f6 
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass zhangshoufu
    }
    virtual_ipaddress {
        192.168.1.101
    }
}

systemctl start keepalived.service start

systemctl stop keepalived.service 停止

systemctl enable keepalived.service boot

Because keepalive keepalive drift mechanism is based on the survival of this service is to determine whether the IP address of the drift, if we are machine down machine, this method can be used directly, but if network problems led to a service unavailable,

Firewall

firewall-cmd --state

firewall-cmd --reload

systemctl start firewalld.service

systemctl stop firewalld.service

Multicast allows firewall vrrp

keepalived multicast address is 224.0.0.18

firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface enp0s3 --destination 224.0.0.18 --protocol vrrp -j ACCEPT

If the iptables installed, it must make the appropriate firewall configuration, otherwise there will be brain (split-brain) crack phenomenon


yum install -y wget
332 wget https://rsync.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
333 ll
334 mkdir /rsync/
335 ll
336 mv rsync-3.0.7.tar.gz /rsync/
337 ll
338 ll /rsync/
339 cd /rsync/
340 ll
341 tar xzf rsync-3.0.7.tar.gz
342 ls
343 cd rsync-3.0.7
344 ls
345 yum install -y gcc
346 yum -y install perl
347 ./configure --prefix=/usr/local/rsync/
348 make&&make install
349 ll /usr/local/rsync/

open rsync rsync -daemon #

/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/rsyncd.conf

netstat -antp | grep 873

netstat -nulpt| grep rsync

lsof -i:873

Configuring rsync boot

we /etc/rc.local

At the end of plus / usr / local / rsync / bin / rsync --daemon --config = / usr / local / rsync / rsyncd.conf

Download sersync

mkdir -p /application/tools/

cd /application/tools/

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz

tar xzf sersync2.5.4_64bit_binary_stable_final.tar.gz

mv GNU-Linux-x86 /usr/local/sersync

Configuration sersync

cp confxml.xml confxml.xml.$(date +%F)

you seq

Open sersync daemon to synchronize data

Start command

/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

Sersync parameters Explanation
./sersync -d -d parameter: background service, the use of -r parameter usually local to the remote synchronous whole again, run this parameter to start the daemon in the background and real-time synchronization; synchronization, -d and -r parameter in first overall often used in combination
./sersync -o xx.xml Specify the -o parameter: You can specify a number of different profiles, in order to achieve multi-process multi-instance sersync data synchronization
./sersync -r Do not mention Note: If the filter is set, i.e., in the xml file, filter is true, the parameter is temporarily unavailable -r overall synchronization;

sersync is a software, a script execution time corresponding his promoter, not a command ,, so there is no effect added to /etc/rc.local

Add a script to monitor whether the normal operation of sersync

#!/bin/sh
sersync="/usr/local/sersync/sersync2"
confxml="/usr/local/sersync/confxml.xml"
status=$(ps aux | grep 'sersync2' | grep -v 'grep' | wc -l)
if [ $status -eq 0 ];
then
$sersync -d -r -o $confxml &
else
exit 0;
fi

chmod + x /usr/local/sersync/check_sersync.sh # Add the script execution permissions

vi / etc / crontab # edit, add the following line in the final

/. 5 * * * the root /usr/local/sersync/check_sersync.sh> / dev / null 2>. 1 & # script executed once every 5 minutes

service crond reload # reload service

Node Name Review:

hostname Master

unman -n

Hostname resolution:

cat /etc/hosts

Guess you like

Origin www.cnblogs.com/chengxu715/p/11987023.html