yum install -y nfs-utils rpcbind
Environmental instructions
nfs server system: CentOS 6.5 x86_64
nfs server IP: 192.168.1.10
nfs client system: CentOS 6.5 x86_64
nfs client IP: 192.168.1.12
Install the NFS server (192.168.1.10)
Step-1: install nfs-utils and rpcbind, run the following command:
yum install -y nfs-utils rpcbind
Step-2: specify a fixed port for NFS, run the following command:
vi /etc/sysconfig/nfs
RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004
Step-3: Open the firewall above the port, run the following command:
iptables -I INPUT -p tcp –dport 111 -j ACCEPT
iptables -I INPUT -p udp –dport 111 -j ACCEPT
iptables -I INPUT -p tcp –dport 2049 -j ACCEPT
iptables -I INPUT -p udp –dport 2049 -j ACCEPT
iptables -I INPUT -p tcp –dport 30001:30004 -j ACCEPT
iptables -I INPUT -p udp –dport 30001:30004 -j ACCEPT
service iptables save
service iptables restart
Step-4: Set SELinux for the licensing status, run the following command:
vi /etc/selinux/config
SELINUX=enforcing
SELINUX=permissive
setenforce 0
Step-5: Create a shared directory, run the following command:
mkdir -p /data/nfs_share
above command will create a shared directory /data/nfs_share
Step-6:Configuring exports file, run the following command:
vi /etc/exports
a new row at the end of the above documents, as follows:
/data/nfs_share 192.168.1.12(rw,sync,no_root_squash)
/data/nfs_share *(ro)
This line means that only 192.168.1.12 client can to read and write permission to mount the shared directory, other clients read-only privileges to mount.
Step-7: Start NFS-related services, run the following command:
chkconfig nfs on
chkconfig rpcbind on
root@server ~]# chkconfig rpcbind on
[root@server ~]# service nfs start
service rpcbind start
Starting NFS services: [ OK ]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connectio n refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]
[root@server ~]# service rpcbind start
Starting rpcbind: [ OK ]
[root@server ~]# service rpcbind start
[root@server ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@server ~]# service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS services: [ OK ]
Shutting down RPC idmapd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
service nfs start
service rpcbind start
Step-8: the relevant port inspection of NFS is already enabled, run the following command:
service iptables status
rpcinfo -p localhost
2. Install NFS client (192.168.1.12)
NFS client does not need to start the NFS service, but you need to install nfs-utils, run the following command:
yum install -y nfs-utils autofs
3. Manually mount the NFS share
Step-1: determine the mount point, run the following command:
showmount -e 192.168.1.10 -e option to display the export list NFS server-side.
Step-2: Create the mount directory, run the following command:
mkdir -p /root/remote_dir
/root/remote_dir for the mount point directory shared directory.
Step-3: Mount the shared directory, run the following command:
mount -t nfs 192.168.1.10:/data/nfs_share /root/remote_dir
remote_dir which, -t option specifies that the type of the file system for nfs.
Step-4: After sharing the end catalog, unload the shared directory, run the following command:
umount /root/remote_dir
4. boot automatically mount
Adding to the fstab file to mount the entries of the shared directory, you can achieve startup automatically mount, but then the connection with the NFS server will always be active. Run the following command:
mkdir -p /root/remote_dir
vi /etc/fstab
at the end of the above documents to join mount entries shared directory, as follows:
192.168.1.10:/data/nfs_share /root/remote_dir nfs defaults 0 0
where the first five fields Set to 0 to the shared directory file system does not use the dump command to dump the first six field is set to 0 indicates that the shared directory file system does not need to use the fsck command to check.
In addition, you can use the automounter (autofs) achieve on-demand to automatically mount a network shared directory. When the share is no longer used, and inactivity certain time automounter will share unmounting.
5. Demand automatically mount (special map)
When the autofs service is running, the system exists in a file called / special directory net, but the directory will appear empty. Step NFS client through a special map-demand automatically mount the shared directory is as follows:
Step-1: Modify the timeout period of inactivity, run the following command:
vi /etc/sysconfig/autofs
TIMEOUT=300
TIMEOUT=600
the above file TIMEOUT = 300 replaced TIMEOUT = 600 is the timeout inactivity by five minutes modified to 10 minutes.
After configuration is complete,
restart the autofs service: service autofs restart
Step-2: access network shared directory, run the following command:
cd /net/192.168.1.10/data/nfs_share When you run the above command,
autofs will automatically mount an NFS server in a network shared directory.
Step-3: Uninstall the mounted network share, the details are as follows:
All files and directories under /net/192.168.1.10/data/nfs_share stop use and the timeout expires after (10 minutes),
autofs will unload the shared directory.
6. Demand automatically mount (an indirect map)
Step-1: Modify the timeout period of inactivity, run the following command:
vi /etc/sysconfig/autofs
the above file
TIMEOUT=300
replaced
TIMEOUT=600
is the timeout inactivity by five minutes modified to 10 minutes.
Step-2: the establishment of a shared directory mount point of the parent directory, run the following command:
mkdir -p /root/demo
Step-3: Configure shared parent directory directory mount point, run the following command:
vi /etc/auto.master
the content of the file are as follows:
/root/demo /etc/auto.demo
is the parent directory mount point, this directory is always visible in the system, by autofs service monitoring, to determine whether the “need” to mount / create subdirectories mount point.
/etc/auto.demo for a single configuration file that contains the autofs service under this parent directory management subdirectory mount point list.
Step-4: Configure shared directory mount point directory, run the following command:
vi /etc/auto.demo
the content of the file are as follows: remote_dir -rw 192.168.1.10:/data/nfs_share which, remote_dir subdirectory mount point,
this directory is not normally visible only when the autofs service creates this directory and
When after Mount sharing them directly naming / access, it will become visible. -rw to mount a network share when you want to use the mount option.
192.168.1.10:/data/nfs_share need to mount an NFS server and shared directories.
remote_dir -rw 192.168.1.10:/data/nfs_share
Step-5: Restart the autofs service, run the following command:
service autofs restart
Step-6: access to network shared directory, run the following command:
cd /root/demo/remote_dir
After running the above command, autofs will automatically create a mount point directory and mount the shared directory.
Step-7: offload network shared directory, the details are as follows:
All files and directories under /root/demo /remote_dir Stop use
and the timeout expires after (10 minutes), autofs will unload the shared directory.
Recent Comments