架设NTP服务器,是个相对比较简单的事情, 架设NTP服务器目的就是使各个工作站的时间统一,下面这篇文章主要给大家介绍了CentOS 7中搭建ntp时钟服务器的步骤,需要的朋友可以参考借鉴,下面来一起学习学习吧。

前言

NTP 网络时间协议用来同步网络上不同主机的系统时间。你管理的所有主机都可以和一个指定的被称为 NTP 服务器的时间服务器同步它们的时间。而另一方面,一个 NTP 服务器会将它的时间和任意公共 NTP 服务器,或者你选定的服务器同步。由 NTP 管理的所有系统时钟都会同步精确到毫秒级。

在公司环境中,如果他们不想为 NTP 传输打开防火墙,就有必要设置一个内部 NTP 服务器,然后让员工使用内部服务器而不是公共 NTP 服务器。在这篇文章中,我们会介绍在CentOS 7 搭建ntp时钟服务器的步骤,一起来看看吧。

服务器 : 192.168.137.3
客户机: 192.168.137.6

1、 服务器端

centos7下首先确认服务器的防火墙、selinux关闭状态

#cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core)

第一步 为服务器和客户机安装ntp ntpdate --默认已安装

#yum install ntp ntpdate -y

第二步 查找时间同步服务器

http://www.pool.ntp.org/zone/asia

第三步 编辑 /etc/ntp.conf

server time.windows.com
server s2m.time.edu.cn
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
server 127.127.1.0 iburst  local clock 当外部时间不可用时,使用本地时间。
restrict 192.168.137.1 mask 255.255.255.0 nomodify  允许更新的IP地址段

第四步 启动ntp服务

systemctl start ntpd
systemctl enable ntpd.service 设置开机启动服务

第五步 验证服务

 #ntpq -p
 
  remote   refid  st t when poll reach delay offset jitter
==============================================================================
 211.138.200.209 .INIT.   16 u - 64 0 0.000 0.000 0.000
 ns.pku.edu.cn .INIT.   16 u - 64 0 0.000 0.000 0.000
 211.138.200.208 .INIT.   16 u - 64 0 0.000 0.000 0.000
 nipper.paina.jp .INIT.   16 u - 64 0 0.000 0.000 0.000
 send.mx.cdnetwo .INIT.   16 u - 64 0 0.000 0.000 0.000
*LOCAL(0)  .LOCL.   5 l 52 64 1 0.000 0.000 0.000
 
#date -R
Fri, 15 Jul 2016 15:28:34 +0800

2、客户端

第六步 远程客户端时间同步测试

#date 
Fri Jul 15 15:31:22 CST 2016
#ntpdate 192.168.137.3
15 Jul 15:33:04 ntpdate[63912]: step time server 192.168.137.3 offset -4.492463 sec

第七步 客户端设置计划任务,每天晚上1点同步时间

crontab -e
00 01 * * * root /usr/sbin/ntpdate 192.168.137.3; /sbin/hwclock -w  

格式 00 01 * 五个字符表示 分 时 日 月 年

这也是在使用Listbox的时候遇到的问题,ItemHeight的默认值是13,当在属性窗口里更改它时,改了又变回去了。后来上网查了下资料,原来Listbox默认是不能更改ItemHeight的。想要更改的话,需要这样做:
首先设置DrawMode属性为OwnerDrawVariable,自己画Listbox。
然后处理DrawItem和MeasureItem两个事件,DrawItem是在显示项时触发,MeasureItem是在要计算项的宽高时触发。在DrawItem里重新绘制项目,如下:

程序代码

e.DrawBackground ();
e.DrawFocusRectangle ();
e.Graphics.DrawString (listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush (e.ForeColor), e.Bounds);

可以在MeasureItem里设置ItemHeight

程序代码

e.ItemHeight = 20;

如果只是这样简单的设个值的话可以不用MeasureItem事件了,因为这里已经可以在属性窗口里更改ItemHeight的值了。

用记事本新建一个后缀名为bat的文件,复制以下内容,保存后。运行即可开始清理

@echo off        
echo 正在清除系统垃圾文件,请稍等......        
del /f /s /q %systemdrive%\*.tmp        
del /f /s /q %systemdrive%\*._mp        
del /f /s /q %systemdrive%\*.log        
del /f /s /q %systemdrive%\*.gid        
del /f /s /q %systemdrive%\*.chk        
del /f /s /q %systemdrive%\*.old        
del /f /s /q %systemdrive%\recycled\*.*        
del /f /s /q %windir%\*.bak        
del /f /s /q %windir%\prefetch\*.*        
rd /s /q %windir%\temp & md %windir%\temp        
del /f /q %userprofile%\cookies\*.*        
del /f /q %userprofile%\recent\*.*        
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"        
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"        
del /f /s /q "%userprofile%\recent\*.*"        
echo 清除系统LJ完成!        
echo. & pause  

实际验证效果不错。