| 您的位置:首页 > 文档 > nis技术 > |
文章分类热门文章 |
快速搭建Time Server与NIS Server.创建:2005-10-27 22:53:06 作者:Unlinux 来自: http://www.Unlinux.com 作者:梁尚锋 网名:好好先生/longfei 原出处:www.chinaunix.net 参考文档:http://www.chinalinuxpub.com/read.htm?id=1337 http://www.fengnet.com/showart.asp?art_id=395&cat_id=10 http://chinaunix.net/jh/6/16555.html 感谢前人的付出 转载请保留上述信息 ========================================================================= 春去春来,一转眼在CU已经混了一年了。这一年来,我在CU学了很多很多,感谢CU,感谢大家的支持和关爱。 我是做技术的,思来想去还是写一篇技术方面的文档,来纪念一下这个特别的日子吧。闲言少叙,言归正传。 一.Time Server的搭建(在此我们使用ntp:Network Time Protocol) Time Server即时间服务器。我们经常会发现服务器上的时间不正确,这样会影响到我们的应用,有时甚至会带来一些不良后果。比如影响我们的备份,影响我们的数据库的更新等。比较常见的解决方法是与公网上的时间服务器同步(只用使用crontab执行00 02 * * * /usr/sbin/ntpdate 195.13.1.153就行了,后面的195.13.1.153就是公网上可以用的时间服务器之一),但这样做计算机必须能连接公网,这样也许会有一些安全问题。并且如果你的计算机在内网不能直接连接公网的时间服务器的话,那就……今天我们就来讲一讲搭建我们自己的时间服务器的做法。 方法一:时间服务器与公网上的时间服务器同步,其它机器与自己的时间服务器同步。缺点:时间服务器还要暴露在公网上。 步骤: 1.检查是否有相应的包 代码: # rpm -qa |grep ntp ntp-4.1.1a-9 chkfontpath-1.9.6-3 如果没有ntp这个包,则从光盘上装上。执行下面命令安装NTP的RPM包: # rpm -ivh ntp-4.1.1a-9.i386.rpm(我使用的是redhat8.0,请根据你的实际情况安装对应的包) 2.修改配置文件 /etc/ntp.conf是ntp的主要配置文件,里面设置了你用来同步时间的时间服务器的域名或者IP地址,下面是到互联网同步时间的最基本的配置: 首先我们来定义自己喜欢的时间服务器:(可用的时间服务器,参看http://chinaunix.net/jh/5/100591.html,或者参看:http://www.eecis.udel.edu/~mills/ntp/servers.html) 代码: server 195.13.1.153 server 194.137.39.67 接下来,我们设置上面两台服务器的访问权限,在这个例子中我们不允许它们修改或者查询我们配置在Linux上的NTP服务器。 代码: restrict 195.13.1.153 mask 255.255.255.255 nomodify notrap noquery restrict 194.137.39.67 mask 255.255.255.255 nomodify notrap noquery 说明:掩码255.255.255.255是用来限制远程NTP服务器的掩码地址。 然后设置允许访问的内网机器。请注意,配置中noquery已经去掉了: 代码: restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap 在此例中,掩码地址扩展为255,因此从192.168.1.1-192.168.1.254的计算机都可以使用我们的NTP服务器来同步时间。如果你想限制的更严格一点,你可以修改你的掩码。 最后,也是最重要的是默认的限制配置要从你配置文件中删除,否则它将覆盖你所有的配置选项,你会发现如果不删除该配置,你的时间服务器将只能和自己通讯。如果ntp.conf中有以下一行,请将它注释: 代码: # restrict default ignore 3.检查可用性 a.保存你的配置文件,然后对每个你在ntp.conf里配置的时间服务器执一下查询命令,确保这些上游时间服务器可用。 代码: # ntpdate 195.13.1.153 27 Jun 10:12:01 ntpdate[25475]: adjust time server 133.100.11.8 offset -0.127154 sec # ntpdate 194.137.39.67 27 Jun 10:12:06 ntpdate[25478]: adjust time server 133.100.9.2 offset 0.010008 sec b.执行下列命令 # ntpq -p …… ……输出略 一个可以证明同步问题的证据是所有远程服务器的jitter值是4000并且delay和reach的值是0。 代码: remote refid st t when poll reach delay offset jitter ============================================================================== LOCAL(0) LOCAL(0) 10 l - 64 7 0.000 0.000 0.008 * 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00 4.设置自启动 为了使NTP服务可以在系统引导的时候自动启动,执行: 代码: # chkconfig ntpd on 启动/关闭/重启NTP的命令是: 代码: # /etc/init.d/ntpd start # /etc/init.d/ntpd stop # /etc/init.d/ntpd restart 5.客户端的设置 a.linux客户端 以root身份登录,执行crontab -e输入00 02 * * * /usr/sbin/ntpdate 192.168.1.1(换成你的Time Server的ip) 这样就会在每天的凌晨两点自动与Time Server同步时间。 b.windows Xp客户端 双击右下角的时间,出现“日期和时间属性”的窗口,选择Internet 时间,在服务器一栏中输入你的Time Server的ip,点击"立即更新",过几秒钟将能看到更新成功的提示。然后勾选“自动与Internet时间服务器同步”。点击确定。 方法二:时间服务器与自己的硬件时钟同步,其它机器与时间服务器同步。缺点:如果Time Server的硬件时钟不准确,则所有的时间将不准确。优点:更安全,没有暴露在公网上的机器。 unix类系统的时钟都有两种,一种是硬件时钟,一种是系统时钟。在此不在详述。步骤如下: 1.校准Time server的硬件时钟(可以直接在bios中设置),或者用hwclock命令来校对,例如: hwclock --set --date="6/16/04 11:14:05" 2.设置系统时间和硬件时钟同步: 输入:hwclock --hctosys. 3.修改配置文件 vi /etc/ntp.conf,我的ntp.conf如下 代码: # Prohibit general access to this service. # restrict default ignore # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 # -- CLIENT NETWORK ------- # Permit systems on this network to synchronize with this # time service. Do not permit those systems to modify the # configuration of this service. Also, do not use those # systems as peers for synchronization. # restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap # --- OUR TIMESERVERS ----- # or remove the default restrict line # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. # restrict mytrustedtimeserverip mask 255.255.255.255 nomodify notrap noquery # --- NTP MULTICASTCLIENT --- #multicastclient # listen on default 224.0.1.1 # restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap # restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap # --- GENERAL CONFIGURATION --- # # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. The # default stratum is usually 3, but in this case we elect to use stratum # 0. Since the server line does not have the prefer keyword, this driver # is never used for synchronization, unless no other other # synchronization source is available. In case the local host is # controlled by some external source, such as an external oscillator or # another protocol, the prefer keyword would cause the local host to # disregard all other synchronization sources, unless the kernel # modifications are in use and declare an unsynchronized condition # #server 127.127.1.0 # local clock server 127.127.1.0 prefer fudge 127.127.1.0 stratum 10 # # Drift file. Put this in a directory which the daemon can write to. # No symbolic links allowed, either, since the daemon updates the file # by creating a temporary in the same directory and then rename()'ing # it to the file. # driftfile /etc/ntp/drift broadcastdelay 0.008 # # Authentication delay. If you use, or plan to use someday, the # authentication facility you should make the programs in the auth_stuff # directory and figure out what this number should be on your machine. # authenticate yes # # Keys file. If you want to diddle your server at run time, make a # keys file (mode 600 for sure) and define the key number to be # used for making requests. # # PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote # systems might be able to reset your clock at will. Note also that # ntpd is started with a -A flag, disabling authentication, that # will have to be removed as well. # keys /etc/ntp/keys 其它设置和方法一相同,启动ntp服务,配置客户端即可。 二.NIS 服务器的配置 NIS即:Network Information Services 网络信息服务,我们使用它可以对系统信息进行集中管理。 1.服务器端配置(假设ip为192.168.0.1) a.检查是否安装了下列包 代码: portmap ypserv ypbind yp-tools make 缺哪个装哪个吧。 b.vi /etc/sysconfig/network 增加下面一行: NISDOMAIN=redhat(这里你可以用你喜欢的域名,不必使用FQDN) c.为立刻使上述设置生效,运行: # domainname redhat d.vi /var/yp/Makefile,找到all: passwd group ......这一行,修改如下: all: passwd group e.启动ypserv服务 代码: # service portmap start # service ypserv start f.初始化NIS数据库,运行: # 代码: /usr/lib/yp/ypinit -m 注意:1) 若以上配置有问题,会显示出错。 2) 提示增加hosts,按[CTRL-D] g.若上部没有错误,重新起动ypserv 代码: # service ypserv restart h.启动密码进程: 代码: # service yppasswdd start i.检查进程是否真的运行,运行: 代码: # ps auxf | grep yp j.检查日志,确定NIS服务是否真的正常,运行: 代码: # tail /var/log/messages 2.linux客户端配置 a.检查是否安装下列包 代码: portmap ypbine yp-tools authconfig 缺哪个装哪个吧。 b.确认服务器端打开portmap服务: 代码: # rpcinfo -p 192.168.0.1 program vers proto port 100000 2 tcp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 32768 status 100024 1 tcp 32768 status 100011 1 udp 851 rquotad 100011 2 udp 851 rquotad 100011 1 tcp 854 rquotad 100011 2 tcp 854 rquotad 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100021 1 udp 32787 nlockmgr 100021 3 udp 32787 nlockmgr 100021 4 udp 32787 nlockmgr 100021 1 tcp 32769 nlockmgr 100021 3 tcp 32769 nlockmgr 100021 4 tcp 32769 nlockmgr 100005 1 udp 867 mountd 100005 1 tcp 870 mountd 100005 3 udp 867 mountd 100005 3 tcp 870 mountd 100004 2 udp 663 ypserv 100004 1 udp 663 ypserv 100004 2 tcp 666 ypserv 100004 1 tcp 666 ypserv 100009 1 udp 680 yppasswdd 391991 100 tcp 7325 c.用authconfig工具,配置客户端访问服务器。如下图 图一 图二 d.authconfig结束时,ypbind会自动启动。tail -f /var/log/messages 看有无报错 e.运行# ypcat passwd 看服务器提供了哪些用户。 3.solaris客户端配置 a.cp /etc/nsswitch.nis /etc/nsswitch.conf b.vi /etc/hosts 添加NIS Server的hostname 和 IP c.domainname redhat d.vi /etc/defaultdomain添加一行 redhat e.ypinit –c 然后输入你的NIS Server的hostname,按ctrl+d,按y退出。 f./usr/lib/netsvc/yp/ypstart #ypwhich –m :查看NIS server的数据库信息,如果看到说明NIS client 成功 4.测试 a.在NIS Server上新增一用户 代码: useradd test passwd test b.cd /var/yp 执行make命令 c.在客户机上用test用户登录 5.注意事项 a.NIS Server的自启动 在服务器端输入ntsysv,选择 代码: portmap ypserv yppasswdd 这个地方你一定要注意让它自启动,否则下次开机nis server不能启动的话,客户端查询不到nis server,将不能登录。 b.每增加一个用户,或者用户修改了密码等,要在服务器端的/var/yp下执行一下make命令。 c.新增用户和修改密码一定要在NIS Server上进行,这样所有的客户端就会自动更新。 后记:就写这么多吧,这是我近期的学习总结,也算是送给自己和CU的周岁献礼吧。欢迎与我交流。 tu2.gif authconfig图二 tu1.gif authconfig图一 转载自:http://www.unlinux.com/doc/nis/20051027/5333.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接
|