m4-第四次考试


第四次考试


1
nfs服务器172.16.1.31
共享下面两个目录
/app/w 要求的权限可读写,同步数据,所有用户都压缩为匿名用户
/app/r 要求的权限为只读,同步数据,所有用户都压缩为匿名用户
客户端上面的要求:
backup服务器 把 nfs服务器的/data/r 挂载到 /data/r
web01 服务器 把 nfs服务器的/data/w 挂载到 /data/w
请写出部署流程与测试结果。

nfs服务器
确保软件已经安装
[root@nfs01 ~]# rpm ‐qa nfs‐utils rpcbind
rpcbind‐0.2.016.el6.x86_64
nfs‐utils‐1.2.378.el6.x86_64
启动并开机自启
[root@nfs01 ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@nfs01 ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@nfs01 ~]# chkconfig nfs on
[root@nfs01 ~]# chkconfig rpcbind on
[root@nfs01 ~]# chkconfig |egrep 'nfs|rpcbind'
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfs‐rdma 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off

配置分享
[root@nfs01 ~]# cat /etc/exports
#share to 172.16.1.0/24
/app/w 172.16.1.0/24(rw,sync,all_squash,anonuid=65534,anongid=65534)
/app/r 172.16.1.0/24(ro,sync,all_squash,anonuid=65534,anongid=65534)
创建目录
[root@nfs01 ~]# mkdir /app/{r,w} ‐p
[root@nfs01 ~]# tree /app/
/app/
├── r
└── w
[root@nfs01 app]# chown ‐R nfsnobody.nfsnobody /app/
[root@nfs01 app]# lsld *
drwxr‐xr‐x. 2 nfsnobody nfsnobody 4096 Aug  4 20:46 r
drwxr‐xr‐x. 2 nfsnobody nfsnobody 4096 Aug  4 20:46 w
[root@nfs01 app]# /etc/init.d/nfs reload
测试
[root@nfs01 app]# showmount ‐e 172.16.1.31
Export list for 172.16.1.31:
/app/r    172.16.1.0/24
/app/w    172.16.1.0/24
[root@nfs01 r]# cd /app/r
[root@nfs01 r]# touch test_from_nfs{1..4}.txt
[root@nfs01 r]# ll
total 0
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 20:58 test_from_nfs1.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 20:58 test_from_nfs2.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 20:58 test_from_nfs3.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 20:58 test_from_nfs4.txt
[root@nfs01 r]# cd /app/w/
[root@nfs01 w]# touch test_from_nfs{a..d}.txt
[root@nfs01 w]# ll
total 0
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 21:01 test_from_nfs{1..d}.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 21:02 test_from_nfsa.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 21:02 test_from_nfsb.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 21:02 test_from_nfsc.txt
‐rw‐r‐‐r‐‐. 1 root root 0 Aug  4 21:02 test_from_nfsd.txt
backup服务器 把 nfs服务器的
/app/r 挂载到 /data/r
在客户端安装软件,web01 同下 [root@backup
~]# yum install nfs‐utils rpcbind ‐y [root@backup ~]# /etc/init.d/rpcbind start Starting rpcbind: [ OK ] [root@backup ~]# chkconfig rpcbind on [root@backup ~]# chkconfig nfs off [root@backup ~]# showmount ‐e 172.16.1.31 Export list for 172.16.1.31: /app/r 172.16.1.0/24 /app/w 172.16.1.0/24
创建目录并挂载 [root@backup
~]# mkdir /data/r ‐p [root@backup ~]# mount ‐t nfs ‐o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.31:/app/r /data/r [root@backup ~]# df ‐h Filesystem Size Used Avail Use% Mounted on /dev/sda3 8.6G 1.2G 7.0G 14% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 27M 154M 15% /boot 172.16.1.31:/app/r 8.6G 1.2G 7.0G 15% /data/r
永久挂载
/bin/mount ‐t nfs ‐o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.31:/data/ /upload
添加到 /etc/rc.local
测试 [root@backup
~]# cd /data/r/ [root@backup r]# ll total 0 ‐rw‐r‐‐r‐‐. 1 root root 0 Aug 4 20:58 test_from_nfs1.txt ‐rw‐r‐‐r‐‐. 1 root root 0 Aug 4 20:58 test_from_nfs2.txt ‐rw‐r‐‐r‐‐. 1 root root 0 Aug 4 20:58 test_from_nfs3.txt ‐rw‐r‐‐r‐‐. 1 root root 0 Aug 4 20:58 test_from_nfs4.txt [root@backup r]# touch test.txt touch: cannot touch `test.txt': Read‐only file system
web01 服务器 把 nfs服务器的/app/w 挂载到 /data/w
软件安装同backup
mkdir /data/w/ ‐p

挂载
mount ‐t nfs ‐o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.31:/app/w /data/w [root@web01 w]# df ‐h Filesystem Size Used Avail Use% Mounted on /dev/sda3 8.6G 1.1G 7.1G 14% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 27M 154M 15% /boot 172.16.1.31:/app/w 8.6G 1.2G 7.0G 15% /data/w 测试
[root@web01 ~]# cd /data/w/
[root@web01 w]# touch file_crete_in_web01.{a..d}.sh
[root@web01 w]# ll
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4  2018
file_crete_in_web01.a.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4  2018
file_crete_in_web01.b.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4  2018
file_crete_in_web01.c.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4  2018
file_crete_in_web01.d.sh
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4  2018 test_from_nfsa.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4  2018 test_from_nfsb.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4  2018 test_from_nfsc.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4  2018 test_from_nfsd.txt
[root@nfs01 w]# ll
total 0
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4 21:10
file_crete_in_web01.a.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4 21:10
file_crete_in_web01.b.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4 21:10
file_crete_in_web01.c.sh
‐rw‐r‐‐r‐‐. 1 nfsnobody nfsnobody 0 Aug  4 21:10
file_crete_in_web01.d.sh
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4 21:02 test_from_nfsa.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4 21:02 test_from_nfsb.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4 21:02 test_from_nfsc.txt
‐rw‐r‐‐r‐‐. 1 root      root      0 Aug  4 21:02 test_from_nfsd.txt
View Code

 

2(50分)
搭建nfs服务器(nfs01)共享/data-nfs目录给172.16.1.0/24网段并拥有读写权限,并把/data目录的数据实时复制到backup服务器的/backup-nfs上面。
要求:
1.nfs01服务期共享目录为/data-nfs目录
2.要求172.16.1.0/24网段内用户可以访问
3.所有用户访问nfs服务器都要压缩为www用户并uid gid都为888
4.backup服务器备份目录为/backup-nfs

注:
nfs服务器为nfs01 10.0.0.31 172.16.1.31
backup为 10.0.0.41 172.16.1.41

 

一、nfs 部分
1.nfs服务器端
    1.搭建nfs
    1.1 安装nfs软件,并启动

yum install nfs-utils rpcbind -y
 
[root@nfs01 ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64
[root@nfs01 ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@nfs01 ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
    1.2 添加开机自启动

[root@nfs01 ~]# chkconfig nfs on
[root@nfs01 ~]# chkconfig rpcbind on
 
[root@nfs01 ~]# chkconfig |egrep 'nfs|rpcbind'
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfs-rdma 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
    1.3 配置/etc/exports

    
[root@nfs01 ~]# vim /etc/exports
 
#share /data-nfs to 172.16.1.0/24
/data-nfs 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anongid=888)

    1.4 创建www用户及共享目录

useradd www -u 888
mkdir -p /data-nfs
chown -R www.www /data-nfs/        更改共享目录权限
/etc/init.d/nfs reload







2.backup服务器端

2.1 安装软件,开机自启

[root@backup ~]# yum install nfs-utils rpcbind -y
[root@backup ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
 
[root@backup ~]# chkconfig rpcbind on
[root@backup ~]# chkconfig nfs off
[root@backup ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data-nfs 172.16.1.0/24

2.2 创建目录并挂载nfs共享目录

[root@backup ~]# mkdir -p /from-nfs
 
[root@backup ~]# mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.31:/data-nfs/ /from-nfs
[root@backup ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.5G 6.9G 18% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
172.16.1.31:/data-nfs 8.8G 1.5G 6.9G 18% /from-nfs

2.3 开机自动挂载

[root@backup ~]# tail -l /etc/rc.local
/bin/mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 172.16.1.31:/data-nfs/ /from-nfs





3.测试

[root@backup ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             8.6G  1.2G  7.0G  14% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             190M   27M  154M  15% /boot
172.16.1.31:/data-nfs/
                      8.6G  1.2G  7.0G  15% /from-nfs
[root@backup ~]# cd /from-nfs/
[root@backup backup-nfs]# ls
[root@backup backup-nfs]# touch test.from.backup 
 
[root@nfs01 ~]# ll /data-nfs/ 
total 0
-rw-r--r--. 1 www www 0 Aug  2 15:39 test.from.backup







二、实时复制部分
    backup 服务器端
确保已经配置好rsync服务
 
mkdir /backup-nfs
chown -R rsync.rsync /backup-nfs
 
 
[root@backup ~]# cat /etc/rsyncd.conf
######rsync_config_______________start
#created by lewen 
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
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
 
[backup-nfs]
path = /backup-nfs/





nfs服务器 

确保已安装rsync inotify-tools软件
 
[root@nfs01 ~]# rpm -q rsync inotify-tools
rsync-3.0.6-12.el6.x86_64
inotify-tools-3.14-1.el6.x86_64
 
 
安装sersync
[root@nfs01 ~]# mkdir -p /home/oldboy/tools
[root@nfs01 ~]# cd /home/oldboy/tools
[root@nfs01 tools]# rpm -qa lrzsz
lrzsz-0.12.20-27.1.el6.x86_64
[root@nfs01 tools]# pwd
/home/oldboy/tools
[root@nfs01 tools]# unzip sersync_installdir_64bit.zip
[root@nfs01 tools]# tree
.
├── sersync_installdir_64bit
│ └── sersync
│ ├── bin
│ │ └── sersync
│ ├── conf
│ │ └── confxml.xml
│ └── logs
└── sersync_installdir_64bit.zip
5 directories, 3 files
 
 
配置sersync路径
 
[root@nfs01 tools]# mv sersync_installdir_64bit/sersync/ /usr/local/
 
[root@nfs01 tools]# ls -l /usr/local/sersync/bin/sersync
-rw-r--r-- 1 root root 1810128 Oct 26 2011 /usr/local/sersync/bin/sersync
[root@nfs01 tools]# chmod +x /usr/local/sersync/bin/sersync
[root@nfs01 tools]#ln -s /usr/local/sersync/bin/sersync /usr/local/bin/



配置sersync配置文件

sersync部分
 <sersync>
        <localpath watch="/data">
            <remote ip="172.16.1.41" name="backup-nfs"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuz --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" 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>

[root@nfs01 conf]# diff confxml.xml confxml.xml.bak 
24,25c24,25
<   <localpath watch="/data">
<       <remote ip="172.16.1.41" name="backup-nfs"/>
---
>   <localpath watch="/opt/tongbu">
>       <remote ip="127.0.0.1" name="tongbu1"/>
30,31c30,31
<       <commonParams params="-artuz --delete"/>
<       <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
---
>       <commonParams params="-artuz"/>
>       <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
36c36
<   <failLog path="/var/log/rsync_fail.log" timeToExecute="60"/><!--default every 60mins execute once-->
---
>   <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->



测试

[root@nfs01 data]# pwd
/data
[root@nfs01 data]# ls
file_from_nfs_data.txt  ts.res
[root@nfs01 data]# touch success.sh
 
 
[root@backup ~]# ll /backup-nfs/
total 0
-rw-r--r--. 1 rsync rsync 0 Aug  2 20:06 file_from_nfs_data.txt
-rw-r--r--. 1 rsync rsync 0 Aug  2 20:21 success.sh
-rw-r--r--. 1 rsync rsync 0 Aug  2 20:17 ts.res

 

 

 



posted @ 2019-03-14 14:02  元贞  阅读(156)  评论(0)    收藏  举报