文件服务器fdb,NFS网络文件系统-中

5、 NFS优化

5.1 安全的参数

在客户端进行挂载的时候,可以使用nosuid,noexec,在服务端可以使用sync,同步写入磁盘。

[root@nfsserver~]# cat /var/lib/nfs/etab(服务端参数)

/kel 192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)

[root@nfsserver~]# tail -1 /etc/exports

/kel192.168.1.0/24(rw,sync)

[root@nfsclient~]# mount -t nfs -o nosuid,noexec 192.168.1.70:/kel /opt(客户端参数)

[root@nfsclient~]# cat /proc/mounts

192.168.1.70:/kel//opt nfs4rw,nosuid,noexec,relatime,vers=4,rsize=16384,wsize=16384,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.63,minorversion=0,local_lock=none,addr=192.168.1.700 0

5.2 性能的参数

在服务端主要设置async,异步写入:

[root@nfsserver~]# vi /etc/exports

[root@nfsserver~]# exportfs -rv

exporting192.168.1.0/24:/kel

[root@nfsserver~]# cat /var/lib/nfs/etab

/kel 192.168.1.0/24(rw,async,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)

在客户端主要使用rsize,wsize来扩大读取和写入的数据量。

[root@nfsclient~]# mount -t nfs -o noatime,nodiratime,rsize=131072,wsize=131072,nosuid,noexec192.168.1.70:/kel /opt

[root@nfsclient~]# cat /proc/mounts

192.168.1.70:/kel//opt nfs4rw,nosuid,noexec,noatime,nodiratime,vers=4,rsize=16384,wsize=16384,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.63,minorversion=0,local_lock=none,addr=192.168.1.700 0

5.3 内核优化

主要是接收套接字缓冲区大小和发送套接字缓冲区大小进行设置,如下所示:

[root@nfsserver~]# ls -l /etc/sysctl.conf(配置文件路径)

-rw-r--r--. 1root root 1150 Oct  7  2011 /etc/sysctl.conf

[root@nfsserver~]# echo "net.core.wmem_default=8388608" >> /etc/sysctl.conf

[root@nfsserver~]# echo "net.core.rmem_default=8388608" >> /etc/sysctl.conf

[root@nfsserver~]# echo "net.core.rmem_max=16777216" >> /etc/sysctl.conf

[root@nfsserver~]# echo "net.core.wmem_max=16777216" >> /etc/sysctl.conf

[root@nfsserver~]# tail -4 /etc/sysctl.conf(检查配置文件)

net.core.wmem_default=8388608

net.core.rmem_default=8388608

net.core.rmem_max=16777216

net.core.wmem_max=16777216

[root@nfsserver~]# sysctl -p(使设置生效)

5.4 测试性能的改变

主要用来测试以上优化的结果,测试结果仅限本地虚拟机:

—————未加参数进行测试—————

[root@nfsclient~]# mount 192.168.1.70:/kel /opt

[root@nfsclientopt]# time dd if=/dev/zero of=orginalfile bs=9k count=1000

1000+0 recordsin

1000+0 recordsout

9216000 bytes(9.2 MB) copied, 0.291541 s, 31.6 MB/s

real  0m0.385s

user 0m0.001s

sys   0m0.020s

—————加noatime,nodiratime参数进行测试—————

[root@nfsclient~]# mount -o rw,noatime,nodiratime192.168.1.70:/kel /opt

[root@nfsclientopt]# time dd if=/dev/zero of=notimefile bs=9k count=1000

1000+0 recordsin

1000+0 recordsout

9216000 bytes(9.2 MB) copied, 0.28665 s, 32.2 MB/s

real  0m0.313s

user 0m0.001s

sys   0m0.016s

—————缩小默认情况下rsize=16384,wsize=16384—————

[root@nfsclient~]# mount -o rw,noatime,nodiratime,rsize=8192,wsize=8192192.168.1.70:/kel /opt

[root@nfsclient~]# cd /opt

[root@nfsclientopt]# time dd if=/dev/zero of=rwsizefile bs=9k count=1000

1000+0 recordsin

1000+0 recordsout

9216000 bytes(9.2 MB) copied, 0.43722 s, 21.1 MB/s

real  0m0.486s

user 0m0.001s

sys   0m0.016s

—————内核优化—优化时间更多!!!————

[root@nfsclient~]# cat /proc/sys/net/core/rmem_max

124928

[root@nfsclient~]# cat /proc/sys/net/core/wmem_max

124928

[root@nfsclient~]# cat /proc/sys/net/core/rmem_default

124928

[root@nfsclient~]# cat /proc/sys/net/core/wmem_default

124928

[root@nfsclient~]# cat /proc/sys/net/core/rmem_max

124928

[root@nfsclient~]# cat /proc/sys/net/core/wmem_max

124928

[root@nfsclient~]# cat /proc/sys/net/core/rmem_default

124928

[root@nfsclient~]# cat /proc/sys/net/core/wmem_default

124928

[root@nfsclient~]# echo "net.core.wmem_default=8388608" >> /etc/sysctl.conf

[root@nfsclient~]# echo "net.core.rmem_default=8388608" >> /etc/sysctl.conf

[root@nfsclient~]# echo "net.core.rmem_max=16777216" >> /etc/sysctl.conf

[root@nfsclient~]# echo "net.core.wmem_max=16777216" >> /etc/sysctl.conf

[root@nfsclient~]# tail -4 /etc/sysctl.conf

net.core.wmem_default=8388608

net.core.rmem_default=8388608

net.core.rmem_max=16777216

net.core.wmem_max=16777216

[root@nfsclient~]# sysctl -p

[root@nfsclientopt]# time dd if=/dev/zero of=kernelfile bs=9k count=1000

1000+0 recordsin

1000+0 recordsout

9216000 bytes(9.2 MB) copied, 0.448142 s, 20.6 MB/s

real  0m0.494s

user 0m0.001s

sys   0m0.023s

结论:

① 添加参数noatime,nodiratime能提高速度

② 参数rsize,wsize增大会提高速度

③ 内核参数会降低速度(这是个悲剧)

最好的优化,更换更快的磁盘,使用raid10,网络硬件优化。

6、 使用自己创建的匿名用户

使用匿名用户的判断流程如下:

f486fa26dc7adc7252b4024f189c127e.png

在默认情况下使用匿名用户的nfsnobody,uid和gid均为65534,在创建自己的匿名用户时候,在客户端和服务器端必须都要创建,如下:

—————服务端创建nfs匿名用户—————

[root@nfsserver~]# useradd nfs -s /sbin/nologin

[root@nfsserver~]# echo nfs|passwd --stdin nfs

Changingpassword for user nfs.

passwd: allauthentication tokens updated successfully.

[root@nfsserver~]# tail -1 /etc/passwd

nfs:x:501:501::/home/nfs:/sbin/nologin

[root@nfsserver~]# groupmod -g 65533 nfs

[root@nfsserver~]# usermod -u 65533  -g 65533 nfs

—————服务端修改共享目录权限—————

[root@nfsserver~]# chown nfs.nfs /kel

[root@nfsserver~]# ls -ld /kel

drwxr-xr-x 2 nfsnfs 4096 Aug 23 02:14 /kel

—————服务端修改配置并检查—————

[root@nfsserver~]# cat /etc/exports

#this is forshare download file by kel

/kel192.168.1.63(rw,async,all_squash,anonuid=65533,anongid=65533)

[root@nfsserver~]# /etc/init.d/nfs reload

[root@nfsserver~]# showmount -e

Export list fornfsserver:

/kel192.168.1.63

—————服务端创建nfs匿名用户—————

[root@nfsclient~]# useradd nfs -s /sbin/nologin

[root@nfsclient~]#  echo nfs|passwd --stdin nfs

Changingpassword for user nfs.

passwd: allauthentication tokens updated successfully.

[root@nfsclient~]# groupmod -g 65533 nfs

[root@nfsclient~]# usermod -u 65533  -g 65533 nfs

[root@nfsclient~]# tail -1 /etc/passwd

nfs:x:65533:65533::/home/nfs:/sbin/nologin

挂载测试读写:

[root@nfsclient~]# mount 192.168.1.70:/kel /opt(NFS客户端挂载共享目录)

[root@nfsclient~]# df -Ph(查看挂载结果)

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root  6.5G 4.1G  2.1G  67% /

tmpfs                  67M     0  67M   0% /dev/shm

/dev/sda1             485M   31M 429M   7% /boot

192.168.1.70:/kel     9.9G 4.9G  4.5G  53% /opt

[root@nfsclientopt]# touch test(验证读写)

[root@nfsclientopt]# ls -l test(查看匿名用户是否正确)

-rw-r--r--. 1nfs nfs 0 Aug 23 07:20 test

7、 设定开机启动

设定开机启动有两种方式,一种是放在配置文件/etc/rc.local中;一种是放在配置文件/etc/fstab中。

7.1 配置文件rc.local

如下所示:

[root@nfsclient~]# echo "#auto mount the nfs filesystem" >>/etc/rc.local(注释)

[root@nfsclient~]# echo "mount -t nfs 192.168.1.70:/kel /opt">> /etc/rc.local(挂载)

[root@nfsclient~]# tail -2 /etc/rc.local

#auto mount thenfs filesystem

mount -t nfs192.168.1.70:/kel /opt

进行重启测试,启动之后查看挂载信息:

[root@nfsclient~]# df -Ph(查看挂载信息)

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root  6.5G 4.1G  2.1G  67% /

tmpfs                  67M     0  67M   0% /dev/shm

/dev/sda1             485M   31M 429M   7% /boot

192.168.1.70:/kel     9.9G 4.9G  4.5G  53% /opt

7.2 配置文件fstab

如下所示:(有的时候可能有问题)

[root@nfsclient~]# tail -1 /etc/fstab(开机挂载配置文件)

192.168.1.70:/kel   /opt         nfs   defaults   0 0

[root@nfsclient~]# df -Ph(查看挂载信息)

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root  6.5G 4.1G  2.1G  67% /

tmpfs                  67M     0  67M   0% /dev/shm

/dev/sda1             485M   31M 429M   7% /boot

192.168.1.70:/kel     9.9G 4.9G  4.5G  53% /opt

重启测试,在使用/etc/fstab的时候,可能会导致挂载不成功,而且,有可能造成服务器无法启动的风险,建议放在rc.local中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值