NFS搭建

服务器:华为RH2288
硬件配置:12块3T SATA硬盘,2块600G SAS硬盘
raid组划分工具:MegaCli

一、配置本地硬盘和目录

安装MegaCli
rpm -ivh Lib_Utils-1.00-09.noarch.rpm
rpm -ivh MegaCli-8.07.14-1.noarch.rpm

查看raid卡信息
/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL
可支持以下raid组类型和硬盘类型:
RAID Level Supported : RAID0, RAID1, RAID5, RAID6, RAID00, RAID10, RAID50, RAID60, PRL 11, PRL 11 with spanning, SRL 3 supported, PRL11-RLQ0 DDF layout with no span, PRL11-RLQ0 DDF layout with span
Supported Drives : SAS, SATA

查看raid组配置
/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL

Slot Number: 0-11是2.7TB,12和13是600GB
Enclosure Device ID 都是 2

删除raid组
/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0

重新划分raid组,4快盘一个raid5,共3个raid5
/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [2:0,2:1,2:2,2:3] WT Direct -a0
/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [2:4,2:5,2:6,2:7] WT Direct -a0
/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [2:8,2:9,2:10,2:11] WT Direct -a0

生成如下三块硬盘
[root@zyc-nfs-server ~]# fdisk -l|grep /dev/sd
Disk /dev/sdb: 9000.0 GB, 8999997014016 bytes
Disk /dev/sdc: 9000.0 GB, 8999997014016 bytes
Disk /dev/sdd: 9000.0 GB, 8999997014016 bytes

使用parted分区
parted -s /dev/sdb “mklabel gpt”
parted -s /dev/sdb “mkpart primary 0 -1”

parted -s /dev/sdc “mklabel gpt”
parted -s /dev/sdc “mkpart primary 0 -1”

parted -s /dev/sdd “mklabel gpt”
parted -s /dev/sdd “mkpart primary 0 -1”

格式化并挂载分区

mkdir /nfs1
mkdir /nfs2
mkdir /nfs3

mkfs.xfs -f /dev/sdb1
mkfs.xfs -f /dev/sdc1
mkfs.xfs -f /dev/sdd1

mount /dev/sdb1 /nfs1
mount /dev/sdc1 /nfs2
mount /dev/sdd1 /nfs3

编辑fstab增加以下内容
/dev/sdb1 /nfs1 xfs defaults 1 2
/dev/sdc1 /nfs2 xfs defaults 1 2
/dev/sdd1 /nfs3 xfs defaults 1 2

 

二、安装NFS

yum install nfs-utils rpcbind
启动nfs
[root@zyc-nfs-server ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]

配置自启动
chkconfig nfs on

修改/etc/hosts 增加主机名,否则showmount会出现Unknown host

修改/etc/exports,增加以下内容:
/nfs1 10.155.1.206(rw,sync,no_root_squash)

nfs更新挂载状态
exportfs -rv

客户端挂载
mount.nfs 10.10.10.170:/nfs1/ /opt/nfs_dir

添加iptables规则,配置白名单只允许部分IP访问NFS
chkconfig iptables on
iptables -A INPUT -s 10.155.1.206/32 -p tcp -m tcp –dport 2049 -j ACCEPT
iptables -A INPUT -p tcp -m tcp –dport 2049 -j DROP