Linux centos 推拉、共享、监控的设置的分享
新建四台虚拟机
打开第一台连接shell更改主机名、网卡
backup
1、主机名网卡配置
[root@jytcentos7.6 ~]# hostnamectl set-hostname backup #更改主机名[root@jytcentos7.6 ~]# sed -i 's#200#41#'g /etc/sysconfig/network-scripts/ifcfg-eth0 #更改网卡ip
[root@jytcentos7.6 ~]# sed -i 's#200#41#'g /etc/sysconfig/network-scripts/ifcfg-eth1 #更改网卡ip
[root@jytcentos7.6 ~]# systemctl restart network #重启网卡
连接xshell
[root@backup ~]#ip add #查看
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ae:8e:87 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.41/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feae:8e87/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ae:8e:91 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.41/24 brd 172.16.1.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feae:8e91/64 scope link
valid_lft forever preferred_lft forever
- 更改第二台、第三台、第四台
1nfs
[root@jytcentos7.6 ~]# hostnamectl set-hostname nfs[root@jytcentos7.6 ~]# sed -i 's#200#31#'g /etc/sysconfig/network-scripts/ifcfg-eth0
[root@jytcentos7.6 ~]# sed -i 's#200#31#'g /etc/sysconfig/network-scripts/ifcfg-eth1
[root@jytcentos7.6 ~]# systemctl restart network
[root@nfs ~]#
2web01
[root@jytcentos7.6 ~]# hostnamectl set-hostname web01
[root@jytcentos7.6 ~]# sed -i 's#200#7#'g /etc/sysconfig/network-scripts/ifcfg-eth0
[root@jytcentos7.6 ~]# sed -i 's#200#7#'g /etc/sysconfig/network-scripts/ifcfg-eth1
[root@jytcentos7.6 ~]# systemctl restart network
[root@web01 ~]#
3web02
[root@jytcentos7.6 ~]# hostnamectl set-hostname web02[root@jytcentos7.6 ~]# sed -i 's#200#8#'g /etc/sysconfig/network-scripts/ifcfg-eth0
[root@jytcentos7.6 ~]# sed -i 's#200#8#'g /etc/sysconfig/network-scripts/ifcfg-eth1
[root@jytcentos7.6 ~]# systemctl restart network
[root@web02 ~]#
2backup 配置rsyncd.conf
useradd rsyncmkdir /backup
chown -R rsync.rsync /backup
cp /etc/rsyncd.conf{,.ori} #做备份防止出错
cat >/etc/rsyncd.conf<<EOF
#rsync_config_______________start
#created by oldboy
#site: http://www.oldboyedu.com
uid = rsync #管理备份目录的用户
gid = rsync # 管理备份目录的用户组
use chroot = no # 安全功能,数据是否锁定到备份目录
max connections = 200 #并发链接 同时多少用户端访问
timeout = 600 #超时时间
pid file = /var/run/rsyncd.pid #进程号所在文件
lock file = /var/run/rsync.lock #锁文件
log file = /var/log/rsyncd.log #日志文件 查看报错等
ignore errors # 忽略错误
read only = false #可写
list = false #不容许列表
hosts allow = 172.16.1.0/24 #那些主机可以访问
hosts deny = 0.0.0.0/32 #那些主机不容许访问
auth users = rsync_backup #远程虚拟连接用户
secrets file = /etc/rsync.password #存放密码的文件:格式:用户名:密码 权限 必须660
[backup] #【模块名】远程访问使用模块名访问
comment = welcome to oldboyedu backup! #说明注释
path = /backup/ #服务器端用户备份的目录 用户合组,rsync.rsync
EOF
systemctl start rsyncd #开启rsync服务
systemctl enable rsyncd #设置开机自启
systemctl status rsyncd #查看服务状态
echo "rsync_backup:oldboy" > /etc/rsync.password #添加密码
chmod 600 /etc/rsync.password #设置密码权限
cat /etc/rsync.password
ls -l /etc/rsync.password
- 欧了!
nfs推拉配置
[root@nfs ~]# echo ' export RSYNC_PASSWORD=oldboy' >>/etc/bashrc[root@nfs ~]# tail -1 /etc/bashrc
export RSYNC_PASSWORD=oldboy
[root@nfs ~]# . /etc/bashrc
[root@nfs ~]# echo $RSYNC_PASSWORD
oldboy
[root@nfs ~]#
推送测试
[root@nfs ~]# rsync /etc/hosts rsync_backup@172.16.1.41::backup
推送成功
[root@backup ~]# cd /backup/
[root@backup /backup]# ll
总用量 4
-rw-r--r-- 1 rsync rsync 332 4月 20 21:05 hosts
[root@backup /backup]#
共享web01和web02以nfs为媒介
1、nfs配置
yum install nfs-utils rpcbind -y #下载插件rpm -qa nfs-utils rpcbind #查看插件
systemctl start nfs #开启服务
systemctl enable nfs #设置开机自启
mkdir /data
echo "#oldboy-jyt" >/etc/exports
echo "/data 172.16.1.0/24(rw,sync)" >>/etc/exports #设置共享目录
grep nfsno /etc/passwd
chown -R nfsnobody.nfsnobody /data #设置目录属主属组
systemctl reload nfs #开启nfs服务
showmount -e 172.16.1.31 #查看共享目录
Export list for 172.16.1.31:
/data 172.16.1.0/24
配置成功
2、web01
yum install nfs-utils rpcbind -y #下载插件rpm -qa nfs-utils rpcbind
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data /mnt #挂载共享目录
chmod +x /etc/rc.local
echo "/usr/bin/mount -t nfs 172.16.1.31:/data /mnt" >>/etc/rc.local #设置开机自动挂载
3、web02
yum install nfs-utils rpcbind -y#下载插件rpm -qa nfs-utils rpcbind
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data /mnt#挂载共享目录
chmod +x /etc/rc.local
echo "/usr/bin/mount -t nfs 172.16.1.31:/data /mnt" >>/etc/rc.local #设置开机自动挂载
- 共享测试
[root@web01 /mnt]# ll
总用量 0
[root@web01 /mnt]# touch binbin.txt
[root@web01 /mnt]# ll
总用量 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 4月 20 21:38 binbin.txt
[root@web01 /mnt]#
[root@web02 ~]# cd /mnt
[root@web02 /mnt]# ll
总用量 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 4月 20 21:38 binbin.txt
[root@web02 /mnt]#
- 共享测试成功
监控nfs的data目录做到实时推送备份
安装插件
yum install inotify-tools -yrpm -ql inotify-tools|head -2
测试nfs-》nfs
[root@nfs /data]# ll总用量 0
[root@nfs /data]# touch x{1..5}.txt
[root@nfs /data]#
[root@nfs ~]# inotifywait -mrq --format '%w%f' -e close_write,delete /data
/data/binbin.txt
/data/x1.txt
/data/x2.txt
/data/x3.txt
/data/x4.txt
/data/x5.txt
菜鸟9528号,请求开炮。