目前,CentOS6虽然内核老旧,但是,在国内还是有很多企业,内部在使用这款系统,而在另外一方面,出于很多新技术的要求,部分企业又要部署一些内核较新的操作系统,由此,centos7目前也逐步应用起来,和老的centos6的既有系统配合,称为很好的搭档。另外,部分情况下,ubuntu server的市场占有率,也逐步提升,虽然很多应用场景不是企业核心的应用,但是在一些需要较新内核和软件版本支撑的场合,Ubuntu server还是逐渐出现在企业内部环境中。
这次,我们要实验的是使用CentOS6作为server,安装NIS和NFS服务,使用另外一台CentOS6和一台Ubuntu server 16.04作为client,接入NIS,安装autofs服务,自动挂载nfs共享目录。系统情况如下:
server:ip 192.168.42.101 hostname:server
client:ip 192.168.42.102 hostname:client
ubuntu:ip 192.168.42.15 hostname ubuntu
首先是我们的CentOS6服务端的系列安装:
安装NFS服务:
[root@server ~]# yum -y install nfs-utils
我们此次的目的是把之后的nis用户的home目录挂载出去,方便NIS域中的用户在其他机器登录都能使用统一的home目录。
[root@server ~]# vim /etc/exports
添加如下内容:
/home 192.168.42.0/24(rw,no_root_squash)
实际上,我们不使用no_root_squash选项也一样,通常,普通用户挂载用不用no_root_squash都一样。
把一些关键服务加入开机自启,并启动之:
[root@server ~]# chkconfig rpcbind on [root@server ~]# chkconfig nfs on [root@server ~]# service rpcbind start Starting rpcbind: [ OK ] [root@server ~]# service nfs start Starting NFS services: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ] Starting RPC idmapd: [ OK ]
NFS需要rpcbind服务,rpcbind服务会动态分配rpc相关服务的端口,这给防火墙的配置带来麻烦,我们手动分配下:
[root@server ~]# vim /etc/sysconfig/nfs
20和22行分别取消注释:
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
57行取消注释:
MOUNTD_PORT=892
63行取消注释:
STATD_PORT=662
上述端口,STATD_PORT=662,这个端口和nfslock服务相关,只有在service nfslock start的情况下,才会监听此端口。
重启rpcbind服务后,可以使用rpcinfo -p查看rpc端口状态:
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100227 3 tcp 2049 nfs_acl
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 2 udp 2049 nfs_acl
100227 3 udp 2049 nfs_acl
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
100024 1 udp 662 status
100024 1 tcp 662 status
可以看到,相应的端口已经改成我们指定的端口了。统计下上面要放行的端口列表:tcp:111,892,2049,32803,662;udp端口有111,892,2049,32769,662
[root@server ~]# iptables -I INPUT -p tcp -m multiport --dport 111,892,2049,32803,662 -j ACCEPT [root@server ~]# iptables -I INPUT -p udp -m multiport --dport 111,892,2049,32769,662 -j ACCEPT [root@server ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] [root@server ~]# service iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ]
安装NIS服务:
[root@server ~]# yum -y install ypserv
临时设定nis域名:
[root@server ~]# ypdomainname yyshell.com
写入文件永久生效:
[root@server ~]# echo "NISDOMAIN=yyshell.com" >> /etc/sysconfig/network
让ypserv默认监听所有网段,我们让它只监听特定网段(安全考虑):
[root@server ~]# vim /var/yp/securenets
添加如下内容:
255.0.0.0 127.0.0.0 255.255.255.0 192.168.42.0
需要注意的是,nfs和nis依赖的rpcbind是支持tcp_wrapper的,我们可以用hosts.allow和hosts.deny两个文件,控制rpcbind服务连接:
vim /etc/hosts.deny
rpcbind: ALL
vim /etc/hosts.allow
rpcbind: 127. 192.168.42.
还有一些配置需要更改下:
[root@server ~]# vim /var/yp/Makefile
42,46行分别改成:
MERGE_PASSWD=false
MERGE_GROUP=false
117行添加一个shadow
all: passwd shadow group hosts rpc services netid protocols mail \
启动相关服务,并加入开机自启动:
[root@server ~]# chkconfig ypserv on [root@server ~]# service ypserv start Starting YP server services: [ OK ] [root@server ~]# service ypxfrd start Starting YP map server: [ OK ] [root@server ~]# chkconfig ypxfrd on [root@server ~]# chkconfig yppasswdd on [root@server ~]# service yppasswdd start Starting YP passwd service: [ OK ]
需要注意的是,NIS服务同样依赖rpcbind服务,需要优先启动rpcbind服务才能启动后续服务,本次没有启动时因为上面的nfs已经把这个服务启动了。
用rpcinfo -p查看,发现比之前单独开nfs多了以下rpc端口:
100004 2 udp 676 ypserv
100004 1 udp 676 ypserv
100004 2 tcp 679 ypserv
100004 1 tcp 679 ypserv
600100069 1 udp 694 fypxfrd
600100069 1 tcp 696 fypxfrd
100009 1 udp 716 yppasswdd
这个yp系列服务同样是有rpcbind动态指定各个端口的,为了加入防火墙规则内,我们人为指定下:
[root@server ~]# vim /etc/sysconfig/network
添加如下内容:
YPSERV_ARGS="-p 663" YPXFRD_ARGS="-p 664"
[root@server ~]# vim /etc/sysconfig/yppasswdd
改成:
YPPASSWDD_ARGS="--port 665"
重启下服务:
service ypserv restart
service ypxfrd restart
service yppasswdd restart
再用rpcinfo -p查看rpc端口,会发现都已经安装配置改过来了。
再配置下防火墙:
[root@server ~]# iptables -I INPUT -p udp --dport 663:665 -j ACCEPT [root@server ~]# iptables -I INPUT -p tcp --dport 663:664 -j ACCEPT [root@server ~]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] [root@server ~]# service iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ]
接下来更新nis数据库,按照提示,中间按Ctrl+D:
[root@server ~]# /usr/lib64/yp/ypinit -m At this point, we have to construct a list of the hosts which will run NIS servers. server is in the list of NIS server hosts. Please continue to add the names for the other hosts, one per line. When you are done with the list, type a <control D>. next host to add: server next host to add: The current list of NIS servers looks like this: server Is this correct? [y/n: y] y We need a few minutes to build the databases... .... server has been set up as a NIS master server.
当有新用户添加时,需要按如下步骤更新下nis数据库:
[root@server ~]# cd /var/yp [root@server yp]# make
好了,服务端的nfs,nis搭建介绍就到这里,下一篇将介绍CentOS和Ubuntu客户端的搭建和配置过程。