Building small and medium-sized clusters (nfs+rsync+inotify) - study notes

one. NFS sharing service

1. Install nfs server:

   yum  install  nfs-utils -y

2. Configure nfs server:

   cat /etc/exports

   /home/work 192.168.0.* (rw,sync,all_squash) Generally, this configuration is fine

  1. rw: read-write, readable and writable; note that only the read-write client here can not write normally, and the permissions of the shared directory must be set correctly, refer to question 7  
  2. ro: read-only, read-only;  
  3. sync: The file is written to the hard disk and memory at the same time;  
  4. async: The file is temporarily stored in memory, rather than directly written to memory;  
  5. no_root_squash: If the NFS client uses root when connecting to the server, it also has root permissions for the directory shared by the server. Obviously it is not safe to turn this on.  
  6. root_squash: If the NFS client uses root when connecting to the server, it has anonymous user permissions for the directory shared by the server. Usually, he will use the identity of nobody or nfsnobody;  
  7. all_squash: No matter what user the NFS client uses to connect to the server, it has anonymous user permissions for the directory shared by the server;  
  8. anonuid: The UID value of the anonymous user, usually nobody or nfsnobody, which can be set here;  
  9. anongid: The GID value of the anonymous user.

3. View the nfs server and client configuration parameters:

   cat /var/lib/nfs/etab (server)

   cat /proc/mounts (the client checks the mount situation, and the stuck situation must be checked with this command, do not use df -h)

two. RSYNC Shared Services

1. Client rsync local working mode:

rsync -avz --delete /etc/ /tmp/ (synchronize the contents of etc under tmp and delete redundant files.)

2. The remote synchronization mode of rsyn:

   rsync -avzP -e "ssh -p 22" /tmp/ [email protected]:/tmp/ #Sync the files under the local tmp directory to 240

3. rsync server mode configuration file /etc/rsyncd.conf:

  See help man rsyncd.conf

#rsync.conf start###
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
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 = 192.168.88.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup #virtual users
secrets file = /etc/rsync.password
########################################
[backup]
comment = linux1 backup #Welcome
path = /backup 

    useradd rsync -s /sbin/nologin -M #Create a user for the synchronization service

    echo "rsync_backup:wmj" > /etc/rsync.password #Create a password file

    chmod 600 /etc/rsync.password #Modify the permissions of the password file

4. Start the rsync server:

   rsync --daemon

5. Configuration of rsync client:

  echo "wmj" >/etc/rsync.password  #创建客户端密码文件(只要写密码不要用户)

  chmod 600 /etc/rsync.password  

  rsync -avz --delete /tmp/ [email protected]::backup --password-file=/etc/rsync.password (将客户端的tmp目录里面的内容推送到服务端)

 

二。inotify服务

1.在客户端上安装inotify:

  wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

  ./configure

  make&&make install

2.监听/tmp/目录的增,删,改操作并按格式打印:

  inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create,delete,close_write /tmp/  (打印的日志格式为:“29/05/16 07:55 /tmp/123”)

 

3.使用inotify监听目录实时rsync同步脚本:

#!/bin/bash
inotify=/usr/local/bin/inotifywait

$inotify -mrq --format '%w%f' -e create,delete,close_write /tmp/ \
|while read file
  do
rsync -az --delete /tmp/ [email protected]::backup --password-file=/etc/rsync.password
done

4.优化inotify参数:

# 在/proc/sys/fs/inotify目录下有三个文件,对inotify机制有一定的限制

 

[root@web ~]# ll /proc/sys/fs/inotify/
总用量0
-rw-r--r--1 root root 09月923:36 max_queued_events
-rw-r--r--1 root root 09月923:36 max_user_instances
-rw-r--r--1 root root 09月923:36 max_user_watches

 

   max_user_watches #设置inotifywait或inotifywatch命令可以监视的文件数量(单进程)
   max_user_instances #设置每个用户可以运行的inotifywait或inotifywatch命令的进程数
   max_queued_events #设置inotify实例事件(event)队列可容纳的事件数量
----------------------------

 

echo 50000000>/proc/sys/fs/inotify/max_user_watches -- 把他加入/etc/rc.local就可以实现每次重启都生效
echo 50000000>/proc/sys/fs/inotify/max_queued_events

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326614301&siteId=291194637