gaoshaofei

导航

 

1.准备三台服务器

NFS服务器          10.0.0.31  
NFS客户端          10.0.0.7
Backup备份服务器   10.0.0.41

2.NFS服务器安装配置NFS服务

1 .安装nfs服务
[root@nfs ~]# yum -y install nfs-utils
2 .配置nfs服务
[root@nfs ~]# vim /etc/exports
/data   172 .16.1.0/24(rw,sync,all_squash,anonuid= 666 ,anongid= 666 )
3 .配置必须的数据
创建用户www
[root@nfs ~]# groupadd -g666 www
[root@nfs ~]# useradd -u666 -g666 -M -s /sbin/nologin www
创建目录/data
[root@nfs ~]# mkdir /data
授权属主属组为www
[root@nfs ~]# chown www.www /data
4 .启动nfs服务
[root@nfs ~]# systemctl start nfs
[root@nfs ~]# systemctl enable nfs
5 .检查nfs配置
[root@nfs ~]# cat /var/lib/nfs/etab
/data	172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)

3.客户端只安装NFS服务不启动

1 .安装nfs-utils,但是不需要配置不需要启动
[root@web01 ~]# yum -y install nfs-utils
2 .查看nfs服务端共享的目录
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172 .16.1.31:
/data 172 .16.1.0/
3 .创建挂载点
[root@web01 ~]# mkdir /img
4 .挂载nfs的/data目录
[root@web01 ~]# mount -t nfs 172.16.1.31:/data  /img
5 .查看结果
[root@web01 ~]# df -h
172.16.1.31:/data   48G  3.8G   45G   8% /img
6 .测试写入
[root@web01 ~]# touch /img/1.txt

4.备份服务器安装rsync同步数据

创建用户1 .安装rsync服务
[root@backup ~]# yum -y install rsync
2 .配置rsync服务
[root@backup ~]# vim /etc/rsyncd.conf
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[backup]
path = /backup

[nfs]
path = /nfs


3 .创建必要数据
创建用户
[root@backup ~]# groupadd -g666 www
[root@backup ~]# useradd -u666 -g666 -M -s /sbin/nologin www
创建密码文件
[root@backup ~]# vim /etc/rsync.passwd
rsync_backup:123456
授权为 600
[root@backup ~]# chmod 600 /etc/rsync.passwd
[root@backup ~]# ll /etc/rsync.passwd
-rw------- 1 root root 20 Dec 4 08 :
/etc/rsync.passwd

创建目录
[root@backup ~]# mkdir /backup /nfs
修改属主属组为www
[root@backup ~]# chown www.www /backup/ /nfs
[root@backup ~]# ll -d /backup/ /nfs/
drwxr-xr-x 2 www www 19 Dec 4 08 :54 /backup/
drwxr-xr-x 2 www www 6 Dec 4 10 :12 /nfs/
4 .启动rsync服务
systemctl start rsyncd
systemctl enable rsyncd
5,客户端测试:
web01:
[root@web01 ~]# rsync -avz /etc/hosts rsync_backup@10.0.0.41::nfs
Password:
nfs: 必须要测试 因为部署的实时同步工具lsync会调用以下
命令
[root@nfs ~]# rsync -avz /etc/passwd rsync_backup@10.0.0.41::nfs
Password:

5.NFS服务器安装rsync服务实现实时共享

1 .安装lsync服务
[root@nfs ~]# yum -y install lsyncd
2 .配置lsync服务
[root@nfs ~]# vim /etc/lsyncd.conf
settings {
logfile = "/var/log/lsyncd/lsyncd.log",      --日志文件所在的位置
statusFile ="/var/log/lsyncd/lsyncd.status", --状态文件日志所在的位置
maxProcesses = 2 ,							 --最大的进程数量,内核的数量保持一致
nodaemon = false,							 --以守护进程方式来运行
}
sync {
default.rsync,								 --默认用rsync命令
source = "/data/", 						     --实时监控/data目录 只要发生变化立刻推送到backup
target = "rsync_backup@10.0.0.41::nfs",	     -- 通过rsync守护进程命令来推送数据
delete = true,								 --使用--delete参数来实时同步
delay = 1 ,   								 --1秒钟同步
rsync = {
binary = "/usr/bin/rsync", 					 --命令所在的位置
password_file = "/etc/rsyncd.pwd",			 -- 密码的配置文件
archive = true, 						     -- -a参数
compress = true, 							 -- -z参数
}
}


创建密码文件
[root@nfs ~]# echo 123456 > /etc/rsyncd.pwd
[root@nfs ~]# chmod 600 /etc/rsyncd.pwd

3 .启动lsync服务
在lsync启动的时候,会自动先执行一遍里面的rsync命令
[root@nfs ~]# systemctl start lsyncd
posted on 2025-05-04 14:42  不懂运维的小高  阅读(21)  评论(0)    收藏  举报