NFS單點故障及深度最佳化方案,nfs單點故障深度
####主機:
backup nfs01
####系統內容:
[root@backup ~]# cat /etc/redhat-release CentOS release 6.8 (Final)[root@backup ~]# uname -r2.6.32-642.el6.x86_64[root@backup ~]# /etc/init.d/iptables statusiptables: Firewall is not running.[root@backup ~]# getenforceDisabled####安裝包yum install keepalived -y
-------------------------------------------------
-------------------------------------------------
####keepalived設定檔
###backup
global_defs { router_id LVS_02}vrrp_script check_nfs { script "/server/scripts/check_nfs.sh" interval 2 weight 2}vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 100 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.1.3/16 dev eth1 label eth1:1 } track_script { check_nfs }}---------------------------------------------------
---------------------------------------------------
###nfs01
global_defs { router_id LVS_01}vrrp_script check_nfs { script "/server/scripts/check_nfs.sh" interval 2 weight 2}vrrp_instance VI_1 { state MASTER interface eth1 virtual_router_id 100 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 172.16.1.3/16 dev eth1 label eth1:1 } track_script { check_nfs }}
----------------------------------------------
----------------------------------------------
####修改backup rsyncd.conf設定檔
######rsync_config_______________start##rsyncd.conf start##uid = wwwgid = wwwuse chroot = nomax connections = 200timeout = 300pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.logignore errorsread only = falselist = falsehosts allow = 172.16.1.0/24#hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password[backup]path = /backup/[nfsbackup]path = /nfsbackup/[web01backup]path = /web01backup/[data]path = /data#rsync_config_______________end
####修改rsync匿名使用者為www uid為888,添加一個模組/data
--------------------------------------------------
--------------------------------------------------
####添加使用者
useradd -s /sbin/nologin -M -u888 wwwid wwwmkdir /datachown -R www.www /web01backup /nfsbackup /backup /data
####修改nfs01的sersync設定檔,將rsync的模組改為data
<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5"> <host hostip="localhost" port="8008"></host> <debug start="false"/> <fileSystem xfs="false"/> <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude> </filter> <inotify> <delete start="true"/> <createFolder start="true"/> <createFile start="false"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="false"/> <modify start="false"/> </inotify> <sersync> <localpath watch="/data"> <remote ip="172.16.1.41" name="data"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> <commonParams params="-az --delete"/> <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> <userDefinedPort start="false" port="874"/><!-- port=874 --> <timeout start="false" time="100"/><!-- timeout=100 --> <ssh start="false"/> </rsync> <failLog path="/var/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> <crontab start="false" schedule="600"><!--600mins--> <crontabfilter start="false"> <exclude expression="*.php"></exclude> <exclude expression="info/*"></exclude> </crontabfilter> </crontab> <plugin start="false" name="command"/> </sersync> <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> <filter start="false"> <include expression="(.*)\.php"/> <include expression="(.*)\.sh"/> </filter> </plugin> <plugin name="socket"> <localpath watch="/opt/tongbu"> <deshost ip="192.168.138.20" port="8009"/> </localpath> </plugin> <plugin name="refreshCDN"> <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> <sendurl base="http://pic.xoyo.com/cms"/> <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath> </plugin></head>
-------------------------------------------------------------------------
####在backup啟動rpcbind nfs服務,共用/data目錄
[root@backup data]# cat /etc/exports #share /data by oldboy for bingbing at 20160425/data/www 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anongid=888)/data/bbs 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anongid=888)/data/blog 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anongid=888)
####啟動服務
chkconfig rpcbind onchkconfig nfs on
####將web服務的掛載ip改為172.16.1.3
umount -lf /application/nginx-1.10.2/html/www/uploadsumount -lf /application/nginx-1.10.2/html/bbsumount -lf /application/nginx-1.10.2/html/blog/wp-content
####NFS用戶端核心最佳化
cat >>/etc/sysctl.conf<<EOFnet.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216EOFsysctl -p
####用戶端掛載最佳化
mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.3:/data/www /application/nginx-1.10.2/html/www/uploadsmount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.3:/data/bbs /application/nginx-1.10.2/html/bbsmount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.3:/data/blog /application/nginx-1.10.2/html/blog/wp-content
####解決nfs服務停止keepalived不跳到backup的問題,編寫指令碼
[root@m01 storage]# cat check_nfs.sh #!/bin/bashif [ `showmount -e localhost|wc -l` -lt 4 ];then /etc/init.d/keepalived stopfi
####啟動服務,加入開機自啟動
/etc/init.d/keepalived startchkconfig keepalived on