@q8517220
2018-11-12T13:07:21.000000Z
字数 15880
阅读 545
配置rsync服务端,rsync客户端推送
[root@web02 ~]# rsync -avz /backup/ rsync_backup@172.16.10.10::backup --password-file=/etc/rsync.passwordsending incremental file list./testsent 130669 bytes received 30 bytes 11365.13 bytes/sectotal size is 134217728 speedup is 1026.92推送成功的 !!!!!!!!!!!!
[root@web02 ~]# tar zcvfh /backup/backup_$(date +%F).tar.gz /var/spool/cron/root /etc/rc.local /etc/sysconfig/iptables /var/www/html /app/logstar: 从成员名中删除开头的“/”/var/spool/cron/root/etc/rc.local/etc/sysconfig/iptables/var/www/html//app/logs/
[root@web02 ~]# vim /server/scripts/bak.sh#!/bin/bashIP=`ifconfig eth1|awk -F "[ :]+" 'NR==2{print $4}'`Path=/backupif [ $(date +%w) -eq 0 ]thenTime="web_$(date +%F-%w -d "-1day")"elseTime=$(date +%F -d "-1day")fimkdir -p $Path/$IPcd / &&\tar zcvfh $Path/$IP/backup_$Time.tar.gz var/spool/cron/root etc/rc.local etc/sysconfig/iptables var/www/html app/logs &&\md5sum $Path/$IP/backup_$Time.tar.gz >$Path/$IP/backup_$Time.tar.log &&\rsync -avz $Path/ rsync_backup@172.16.10.10::backup --password-file=/etc/rsync.password
[root@web02 ~]# vim /server/scripts/check_and_del.sh#!/bin/bashIP=`ifconfig eth1|awk -F "[ :]+" 'NR==2{print $4}'`Path=/backupthenTime="web_$(date +%F-%w -d "-1day")"elseTime=$(date +%F -d "-1day")fiLANG-enfind /backup/ -type f -name "*${Time}*.log"|xargs md5sum -c >>$Path/${Time}_result.log &&\mail -s "$Time bak result" 592654815@qq.com <$Path/${Time}_result.logfind /backup/ -type f ! -name "web*-6*" -mtime +180 |xargs rm -f
2.4配置mail使用外部smtp发邮件
通过修改 配置文件可以使用外部smtp服务器,可以达到sendmail/postfix等内部邮件服务而用外部的smtp服务器发送邮件的目的:
修改/etc/mail.rc最后一行加入set from=592654815@qq.com smtp=smtp.163.com smtp-auth-user=592654815 smtp-auth-password=lihao520 smtp-auth=login
.nfs看挂载情况:
①服务端:[root@localhost ~]# cat /var/lib/nfs/etab/data 172.16.10.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)②客户端:[root@web02 ~]# df -h ---->这种方法,出问题就会卡死,不建议Filesystem Size Used Avail Use% Mounted on/dev/sda2 18G 935M 16G 6% /tmpfs 495M 0 495M 0% /dev/shm/dev/sda1 194M 28M 157M 15% /boot172.16.10.10:/data 18G 1.2G 16G 8% /mnt[root@web02 ~]# cat /proc/mountsrootfs / rootfs rw 0 0proc /proc proc rw,relatime 0 0sysfs /sys sysfs rw,relatime 0 0devtmpfs /dev devtmpfs rw,relatime,size=496916k,nr_inodes=124229,mode=755 0 0devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0tmpfs /dev/shm tmpfs rw,relatime 0 0/dev/sda2 / ext4 rw,relatime,barrier=1,data=ordered 0 0/proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0/dev/sda1 /boot ext4 rw,relatime,barrier=1,data=ordered 0 0none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0172.16.10.10:/data/ /mnt nfs4 rw,relatime,vers=4,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=172.16.10.30,minorversion=0,local_lock=none,addr=172.16.10.10 0 0
nfs client mount 挂载参数:
fg:前端挂载
bg:后台挂载
soft:限时挂载,超时退出
hard:持续挂载,直到kill或unmount
intr:当使用hard挂载,可以timeout后把它中断掉
rsize:读的区块大小
wsize:写的区块大小
man mount 后的-o参数
下面mount命令-o选项后面可以连接参数,注意,有些选项只有出现/etc/fstab里才有效,下面这些选项绝大多数文件系统上,但是sync仅适合ext2 ext3 fat vfat ufs等文件系统。
①async:涉及文件系统I/O的操作都是异步处理,即不会同步写到磁盘,此参数会提高性能,但会降低数据安全,一般情况,生产环境不推荐使用,除非对性能要求很高,对数据可靠性不要求。
②sync:该参数和async相反,有I/0操作时,都会同步出路I/O,即把数据同步写入磁盘,此参数会牺牲一点I/O性能,但是,换来的是掉电后数据的安全性。
atime:在每一次数据访问时,会同步更新访问文件的inode时间戳,默认选项,在高并发情况下建议通过明确加上noatime,来取消这个默认项,以提升I/O性能,优化I/O的 目的。
ro:以只读
rw:可写
2.1.1案例:
①fstab修改错误导致系统无法启动故障修复案例
进入单用户或救援模式: mount -o rw,remount /
然后修改/etc/fstab
②文件系统内部自动一致性(只读)
③rsync bug
进入单用户或救援模式: mount -o rw,remount /
2.1.1mount 挂载优化
客户端挂载
mount -t nfs -o noatime,nodiratime,nosuid,rsize=131072,wsize=131072 172.16.10.10:/data/ /mnt
其实默认设置就不错了。
mount -t nfs 172.16.10.10:/data/ /mnt
2.1.2nfs内核优化建议
/proc/sys/net/core/rmem_default:该文件指定接收套接字缓冲区大小的默认值(以字节为单位),默认:124928
(/proc/sys/net/core/rmen_max:该文件指定接收套接字缓冲区大小的最大值(以字节为单位),默认:124928
cat /proc/sys/net/core/wmem_default该文件指定发送套接字缓冲区大小的默认值(以字节为单位),默认:124928
cat /proc/sys/net/core/wmem_max该文件指定发送套接字缓冲区大小的最大值(以字节为单位),默认:124928
NFS内核优化
[root@localhost ~]# cat >>/etc/sysctl.conf<<EOFnet.core.rmen_default = 8388600net.core.wmen_default = 8388600net.core.rmen_max = 16777216net.core.wmen_max = 16777216EOF
2.2.1企业生产场景NFS共享存储优化小结:
①硬件:Sas/ssd磁盘,买多块,raid5 raid10 网卡吞吐量要大,至少千兆(多块bond)
②NFS服务器端配置:/data 172.16.10.10/24(rw,sync,all_squash,)
③客户端配置命令:
mount -t nfs -o noatime,nodiratime,nosuid,rsize=131072,wsize=131072 172.16.10.10:/data/ /mnt
④对NFS 服务的所有服务器内核进行优化时,执行如下命令:
[root@localhost ~]# cat >>/etc/sysctl.conf<<EOFnet.core.rmen_default = 8388600net.core.wmen_default = 8388600net.core.rmen_max = 16777216net.core.wmen_max = 16777216EOF
执行sysctl -p生效
如果卸载时提示"umount: /mnt: device is busy",需要退出挂载目录再进行卸载,如果NFSsever宕机了,则需要强卸载,可执行umount -lf /mnt
大型网站NFS网络文件系统的替代软件为分布式文件系统MFS GlusterFS FastDFS
2.3nfs系统应用的优缺点:
优点:
①NFS文件系统内数据在文件系统上,可以看见的。
②部署快速,维护简单方便,且可控,满足需求就是最好的。
③可靠,从软件层面上看,数据可靠性高,经久耐用,数据是在文件系统之上。
④服务非常稳定。
缺点:
①存在单点故障,如果NFS server宕机了,文件目录就不能共享,所有客户端不能访问。
②在大数据高并发的场合,NFS效率、性能有限(2千万/日以下PV的网站不是瓶颈,除非网站架构设计很差)。
③客户端认证是基于IP和主机名,权限要根据ID识别,安全性一般(用于内网,则问题不大)
④NFS数据是明文的,NFS本身不对数据完整性验证。
⑤多台客户机器挂载一个NFS服务时,连接管理维护麻烦(耦合度高),尤其NFS服务端出问题后,所有NFS客户端都处于挂掉状态(测试环境可使用autofs自动挂载解决,正式环境可修复NFS服务或强制卸载)
⑥涉及同步(实时等待)和异步(解耦)的概念,NFS服务端和客户端相对来说就是耦合度有些高,网站程序也是一样,尽量不要耦合度太高,系统及程序架构师的重要职责就是程序及架构解耦,让网站的扩展性变得更好。
应用建议:大中小型网站(参考点2000万/日PV以下)线上应用,都有用武之地,门户站也会有应用,生产场景应该多把数据的访问往前推,即尽量把静态存储里的资源通过CDN或缓存服务器提供服务,如果没有缓存服务或架构不好,存储服务器数量再多也扛不住压力,而且用户体验度差。
①实现从nfs客户端到rsync服务端部署
rsync服务配置步骤:1.查看rsync安装包rpm -qa rsync2.添加rsync服务的用户,管理本地目录的useradd rsync -s /sbin/nologin -Mid rsync3.生成rsyncd.conf配置文件vim /etc/rsyncd.conf放入事先准备的配置4.根据rsyncd.conf的auth users配置账户,远程连接的,并根据secrets file参数生成密码文件echo "rsync_backup:lihao" >> /etc/rsync.password5.为密码文件配置权限chmod 600 /etc/rsync.password6.创建共享的目录并授权rsync服务管理mkdir /backup -pchown -R rsync.rsync /backup7.启动rsync服务并检查rsync --daemonps -ef |grep rsync|grep -v grep``````备份端:[root@localhost ~]# cat -n /etc/rsyncd.conf1 #rsync_config___________start2 #created by lihao 21:36 2018/8/203 ##rsync.conf start##4 uid = rsync #用户5 gid = rsync #用户组6 use chroot = no #安全相关7 max connections = 200 #最大连接数8 timeout = 300 #超时时间秒9 pid file = /var/run/rsyncd.pid #进程对应的进程号文件10 lock file = /var/run/rsync.lock #锁文件11 log file = /var/log/rsyncd.log #日志文件12 [backup] #模块名称13 path = /backup #服务器提供访问的目录14 ignore errors #忽略错误15 read only = false #可写16 list = false #不能列表17 hosts allow = 172.16.10.0/24 #允许服务器连接18 hosts deny = 0.0.0.0/32 #拒绝连接19 auth users = rsync_backup20 secrets file = /etc/rsync.password21 #rsync_config___________end多模块应用[root@localhost /]# vim /etc/rsyncd.conf1 #rsync_config___________start2 #created by lihao 21:36 2018/8/203 ##rsync.conf start##4 uid = rsync5 gid = rsync6 use chroot = no7 max connections = 2008 timeout = 3009 pid file = /var/run/rsyncd.pid10 lock file = /var/run/rsync.lock11 log file = /var/log/rsyncd.log12 ignore errors13 read only = false14 list = false15 hosts allow = 172.16.10.0/2416 #hosts deny = 0.0.0.0/3217 auth users = rsync_backup18 secrets file = /etc/rsync.password19 [backup]20 path = /backup21 [lihao]22 path = /lihao23 #rsync_config___________end创建rsync用户[root@localhost ~]# id rsyncid: rsync:无此用户[root@localhost ~]# useradd rsync -s /sbin/nologin -M[root@localhost ~]# tail -1 /etc/passwdrsync:x:500:500::/home/rsync:/sbin/nologin[root@localhost ~]# rsync --daemon[root@localhost ~]# ps -ef |grep rsync|grep -v greproot 1503 1 0 21:53 ? 00:00:00 rsync --daemon[root@localhost ~]# mkdir /backup[root@localhost ~]# ls -ld /backup/drwxr-xr-x 2 root root 4096 8月 20 21:54 /backup/[root@localhost ~]# chown rsync.rsync /backup/[root@localhost ~]# vim /etc/rsyncd.password1 rsync_backup:lihao[root@localhost ~]# ls /etc/rsync.password -l-rw-r--r-- 1 root root 19 8月 20 22:04 /etc/rsync.password[root@localhost ~]# chmod 600 /etc/rsync.password[root@localhost ~]# ls /etc/rsync.password -l-rw------- 1 root root 19 8月 20 22:04 /etc/rsync.password[root@localhost ~]# lsof -i :873COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMErsync 1503 root 4u IPv4 11123 0t0 TCP *:rsync (LISTEN)rsync 1503 root 5u IPv6 11124 0t0 TCP *:rsync (LISTEN)客户端配置1.生成连接服务器需要的密码文件echo "lihao" >>/etc/rsync.password2.为密码文件配置权限chmod 600 /etc/rsync.password3.同步文件(两种方法)rsync -avz /backup rsync://rsync_backup@172.16.10.10/backup --password-file=/etc/rsync.passwordrsync -avz /backup/ rsync_backup@172.16.10.10::backup/ --password-file=/etc/rsync.password[root@localhost ~]# echo "lihao" >>/etc/rsync.password[root@localhost ~]# cat /etc/rsync.passwordlihao[root@localhost ~]# chmod 600 /etc/rsync.password[root@localhost ~]# ll /etc/rsync.password-rw------- 1 root root 6 8月 20 22:28 /etc/rsync.password[root@localhost backup]# rsync -avz /backup/ rsync_backup@172.16.10.10::backup/ --password-file=/etc/rsync.passwordsending incremental file list./stu001stu002stu003stu004stu005stu006stu007stu008stu009stu010stu011stu012stu013stu014stu015stu016stu017stu018stu019stu020stu021stu022stu023stu024stu025stu026stu027stu028stu029stu030stu031stu032stu033stu034stu035stu036stu037stu038stu039stu040stu041stu042stu043stu044stu045stu046stu047stu048stu049stu050stu051stu052stu053stu054stu055stu056stu057stu058stu059stu060stu061stu062stu063stu064stu065stu066stu067stu068stu069stu070stu071stu072stu073stu074stu075stu076stu077stu078stu079stu080stu081stu082stu083stu084stu085stu086stu087stu088stu089stu090stu091stu092stu093stu094stu095stu096stu097stu098stu099stu100sent 4428 bytes received 1911 bytes 12678.00 bytes/sectotal size is 0 speedup is 0.00
NFS------网络文件系统。主要功能是通过网络(一般局域网)让不同的主机系统之间可以共享文件或目录。
NFS端口不固定
NFS工作流程:
①先启动RPC服务
②启动NFS服务,自动向RPC注册
③客户端请求NFS服务
④RPC返回IP端口
⑤客户端拿着IP端口请求数据
修改yum.conf 记录rpm文件
[root@ntf-backup ~]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
安装nfs安装包
[root@ntf-backup ~]# yum -y install nfs-utils rpcbind[root@nfs-server ~]# rpm -aq nfs-utils rpcbindnfs-utils-1.2.3-78.el6.x86_64rpcbind-0.2.0-16.el6.x86_64[root@nfs-server ~]# /etc/init.d/rpcbind start (要先启动rpc,再启动nfs)正在启动 rpcbind: [确定][root@nfs-server ~]# netstat -ntpau|grep rpcbindtcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1425/rpcbindtcp 0 0 :::111 :::* LISTEN 1425/rpcbindudp 0 0 0.0.0.0:111 0.0.0.0:* 1425/rpcbindudp 0 0 0.0.0.0:752 0.0.0.0:* 1425/rpcbindudp 0 0 :::111 :::* 1425/rpcbindudp 0 0 :::752 :::* 1425/rpcbind[root@nfs-server ~]# rpcinfo -p localhostprogram vers proto port service100000 4 tcp 111 portmapper100000 3 tcp 111 portmapper100000 2 tcp 111 portmapper100000 4 udp 111 portmapper100000 3 udp 111 portmapper100000 2 udp 111 portmapper[root@nfs-server ~]# /etc/init.d/nfsnfs nfslock[root@nfs-server ~]# /etc/init.d/nfs start启动 NFS 服务: [确定]启动 NFS mountd: [确定]启动 NFS 守护进程: [确定]正在启动 RPC idmapd: [确定][root@nfs-server ~]# rpcinfo -p localhostprogram vers proto port service100000 4 tcp 111 portmapper100000 3 tcp 111 portmapper100000 2 tcp 111 portmapper100000 4 udp 111 portmapper100000 3 udp 111 portmapper100000 2 udp 111 portmapper100005 1 udp 36426 mountd100005 1 tcp 43685 mountd100005 2 udp 58343 mountd100005 2 tcp 39429 mountd100005 3 udp 45346 mountd100005 3 tcp 38027 mountd100003 2 tcp 2049 nfs100003 3 tcp 2049 nfs100003 4 tcp 2049 nfs100227 2 tcp 2049 nfs_acl100227 3 tcp 2049 nfs_acl100003 2 udp 2049 nfs100003 3 udp 2049 nfs100003 4 udp 2049 nfs100227 2 udp 2049 nfs_acl100227 3 udp 2049 nfs_acl100021 1 udp 35376 nlockmgr100021 3 udp 35376 nlockmgr100021 4 udp 35376 nlockmgr100021 1 tcp 37467 nlockmgr100021 3 tcp 37467 nlockmgr100021 4 tcp 37467 nlockmgr
开机自启动:
[root@nfs-server ~]# chkconfig nfs on[root@nfs-server ~]# chkconfig rpcbind on
NFS共享的目录:为NFS服务端要共享的实际目录,要用绝对路径,如(/data)。注意共享目录的本地权限,如果
需要读写共享,一定要让本地目录可以被NFS客户端用户nfsnobody读写。
NFS客户端地址:为NFS服务端授权的可访问共享目录的NFS客户端地址,可以为单独的IP地址或主机名、域名等也可以为整个网段地址
,还可以用“*”来匹配所有客户端服务器,这里所谓的客户端一般来说是前端的业务服务器。
[root@nfs-server ~]# mkdir /data -poot@nfs-server ~]# id nfsnobodyuid=65534(nfsnobody) gid=65534(nfsnobody) 组=65534(nfsnobody)[root@nfs-server ~]# chown -R nfsnobody.nfsnobody /data[root@nfs-server ~]# ll /data总用量 12drwxr-xr-x 5 nfsnobody nfsnobody 4096 8月 2 22:17 oldboydrwxr-xr-x 7 nfsnobody nfsnobody 4096 8月 2 22:51 testdrwxr-xr-x 7 nfsnobody nfsnobody 4096 8月 6 21:33 www[root@nfs-server ~]# vim /etc/exports1 #share /data for lihao at 2018/8/282 /data 172.16.10.0/24(rw,sync)"/etc/exports" 2L, 66C 已写入[root@nfs-server ~]# cat /etc/exports#share /data for lihao at 2018/8/28/data 172.16.10.0/24(rw,sync)[root@nfs-server ~]# /etc/init.d/rpcbind statusrpcbind (pid 1425) 正在运行...[root@nfs-server ~]# /etc/init.d/nfs statusrpc.svcgssd 已停rpc.mountd (pid 1465) 正在运行...nfsd (pid 1480 1479 1478 1477 1476 1475 1474 1473) 正在运行...[root@nfs-server ~]# rpcinfo -p localhostprogram vers proto port service100000 4 tcp 111 portmapper100000 3 tcp 111 portmapper100000 2 tcp 111 portmapper100000 4 udp 111 portmapper100000 3 udp 111 portmapper100000 2 udp 111 portmapper100005 1 udp 36426 mountd100005 1 tcp 43685 mountd100005 2 udp 58343 mountd100005 2 tcp 39429 mountd100005 3 udp 45346 mountd100005 3 tcp 38027 mountd100003 2 tcp 2049 nfs100003 3 tcp 2049 nfs100003 4 tcp 2049 nfs100227 2 tcp 2049 nfs_acl100227 3 tcp 2049 nfs_acl100003 2 udp 2049 nfs100003 3 udp 2049 nfs100003 4 udp 2049 nfs100227 2 udp 2049 nfs_acl100227 3 udp 2049 nfs_acl100021 1 udp 35376 nlockmgr100021 3 udp 35376 nlockmgr100021 4 udp 35376 nlockmgr100021 1 tcp 37467 nlockmgr100021 3 tcp 37467 nlockmgr100021 4 tcp 37467 nlockmgr[root@nfs-server ~]# /etc/init.d/nfs reload[root@nfs-server ~]# showmount -e 172.16.10.10Export list for 172.16.10.10:/data 172.16.10.0/24####服务端已经配置完成###########客户端配置#####[root@web ~]# showmount -e 172.16.10.10Export list for 172.16.10.10:/data 172.16.10.0/24[root@web ~]# mount -t nfs 172.16.10.10:/data /mnt[root@web mnt]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 18G 1.1G 16G 7% /tmpfs 495M 0 495M 0% /dev/shm/dev/sda1 194M 28M 157M 15% /boot172.16.10.10:/data 18G 1.2G 16G 8% /mnt (提示挂载成功)##测试##[root@web ~]# cd /mnt[root@web mnt]# lsoldboy test www[root@web mnt]# touch test.txt[root@web mnt]# echo "1123" >test.txt[root@nfs-server ~]# cd /data[root@nfs-server data]# lsoldboy test test.txt www[root@nfs-server data]# cat test.txt1123###完成##NFS客户端:①检查系统版本hostname nfs-cat /etc/redhat-releaseuname -r②安装rpc服务检查rpm -aq nfs-utils rpcbindyum -y install nfs-utils rpcbind③启动rpc服务并检查/etc/init.d/rpcbind start/etc/init.d/rpcbind status④设置开机自启动并检查chkconfig rpcbind onchkconfig --list rpcbind⑤检查服务端的NFS是否OKshowmount -e 172.16.10.10排查故障:1.物理故障 ping 172.16.10.102.端口是否开通Telnet 172.16.10.10 111(注意:防火墙是否开启阻挡)⑥挂载并测试mount -t nfs 172.16.10.10:/data /mnt服务端配置①检查系统版本hostname nfs-cat /etc/redhat-releaseuname -r②安装rpc服务检查rpm -aq nfs-utils rpcbindyum -y install nfs-utils rpcbind③启动rpc和NFS服务并检查/etc/init.d/rpcbind start/etc/init.d/rpcbind statusrpcinfo -p localhost/etc/init.d/nfs startrpcinfo -p localhost④设置开机自启动并检查chkconfig rpcbind onchkconfig --list rpcbindchkconfig nfs onchkconfig --list nfs⑤配置共享/data目录cat >>/etc/exports<<EOF#shared data for bbs by lihao at 2018/8/31/data 172.16.10.10/24(rw,sync)EOFcat /etc/exports⑥创建共享目录mkdir /datachown -R nfsnobody.nfsnobody /data⑦平滑加载NFS服务并检查/etc/init.d/nfs reloadshowmount -e 172.16.10.10
①实现从nfs客户端对nfs目录文件系统事件的实时监控
3.2.1安装inotify-tools包
yum安装方法:
[root@nfs_server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo[root@nfs_server ~]# yum -y install inotify-tools[root@nfs_server ~]# rpm -qa inotify-toolsinotify-tools-3.14-1.el6.x86_64
工具集介绍:
中间可以用逗号隔开create,delete,close_write
实时监控/data目录创建和删除文件[root@nfs_server ~]# inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create,delete /data
①当监控到nfs目录文件系统事件变化后,触发rsync推送变化的文件
[root@nfs_server scripts]# vim inotify.sh#!/bin/bashPath=/dataIp=192.168.16.103/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write $Path \|while read filedocd $Path && \rsync -az ./ --delete rsync_backup@$Ip::nfsbackup/ --password-file=/etc/rsync.password &done
inotify调优:
事件相关参数默认大小
[root@nfs_server scripts]# cd /proc/sys/fs/inotify[root@nfs_server inotify]# lsmax_queued_events max_user_instances max_user_watches[root@nfs_server inotify]# cat max_queued_events16384[root@nfs_server inotify]# cat max_user_instances128[root@nfs_server inotify]# cat max_user_watches8192
关键参数说明:
max_queued_events--设置inotify实例事件(event)队列可容纳的事件数量
max_user_instances--设置每个用户可以运行的inotifywait或inotifywatch命令的进程数
max_user_watches--设置inotifywait或inotifywatch命令可以监控的文件数量(单进程
实战调优:
[root@nfs_server inotify]# echo 655350 >/proc/sys/fs/inotify/max_user_watches[root@nfs_server inotify]# echo 655350 >/proc/sys/fs/inotify/max_queued_events[root@nfs_server inotify]# cat /proc/sys/fs/inotify/max_queued_events655350
重启会失效:写入/etc/rc.local.
inotify优点:
1.监控文件系统事件变化,通过同步工具实现实时数据同步。
inotify缺点:
1.并发如果大于200个文件(10-100k),同步就会有延迟。
2.有变化才推送,没变化不理会
3.监控到事件后,调用rsync同步单进程的(加&并发),sersync多进程同步。
sersync功能:
1.支持配置文件管理
2.真正的守护进程socket
3.可以对失败文件定时重传(定时任务功能)
4.第三方的HTTP接口(例如更新cdn缓存)
5.默认多线程rsync同步
** 高并发数据实时同步方案小结**
1.inotify(sersync)+rsync文件级别
2.drbd文件系统级别,基于block.缺点:备节点数据不可用
3.第三方软件的同步功能:MySQL同步,oracle,mongodb
4.程序双写,直接写两台服务器
5.业务逻辑解决(读写分离,备读不到,读主)
6.nfs集群(1.4.5)(双写主存储,备存储用inotify(sersync)+rsync,备没有找主解决延迟问题)