centos7 ntp server & samba
最近公司内部一个需求:必须 Linux建个 ntp server ,并且 Windows可以net time \\ip 访问。
想要解决问题,还得解决前置问题。
服务器不能上网,无法直接访问外部 yum源 , 只能使用光盘了。
########### 更改yum源为 cdrom
# 光盘正确连接的情况下:
mkdir -p /media/cdrom
mount /dev/cdrom /media/cdrom
yum clean all # 清缓存
cd /etc/yum.repos.d/
mkdir bak
mv *.repo ./bak # 备份 mv ./bak/CentOS-Media.repo ./ # 只留一个光盘源 yum-config-manager --enable c7-media # 启用光盘源
# 如果上面这条执行不成功,也可以修改CentOS-Media.repo 将倒数第二行 enabled=1 保存退出
yum list # 看看能否显示c7-media源 yum install zip # 测试安装,Repository 应显示 c7-media
或者:使用外网机离线下载,然后再上传到内网机上。
#--------------------------- 离线下载方式 ------------------------------
# 联网机
yum install yum-plugin-downloadonly # 安装下载工具
mkdir -p /data/rpm # 下载目录
yum install --downloadonly --downloaddir=/data/rpm samba # 下载某软件包及依赖
ll /data/rpm # 查看文件
## 手动复制文件到内网机,或scp 或rsync
# 内网机
mkdir -p /data/samba
cd /data/samba
rsync -a 192.168.52.6:/data/rpm ./ # 从远端复制文件过来
yum localinstall *.rpm -y # 安装当前目录下所有包
为什么要使用NTP server ? crontab 里加上 ntpdate 命令不行吗?
因为很多应用服务或程序,需要线性的时间同步,不能出现时间跳跃。ntpdate命令,会使本机时间直接跳跃到与ntp服务器同步的时间。
时间的跳跃可能会对某些应用程序数据产生不良影响。
比如:Mongodb 就需要使用ntp 服务来同步时间,官方文档说:时间不同步可能会造成分片集群或复制集节点挂机.
########### ntp server
ip a # 本机IP 192.168.52.5
yum install -y ntp # 安装服务
ntpdate cn.pool.ntp.org # 先同步一次公网时间
# 参考:https://www.cnblogs.com/harrymore/p/9566229.html
vim /etc/ntp.conf # 配置文件 (部分修改的有注释)
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.52.0 mask 255.255.255.0 nomodify notrap # 此网段更少限制
server cn.pool.ntp.org prefer # 优先
server asia.pool.ntp.org
server asia.pool.ntp.org
server 127.127.1.0 # 收到客户端请求,若未更新则使用本地时间 不是127.0.0.1 确实是127.127.1.0
Fudge 127.127.1.0 stratum 10 # 服务器层次(首字母是大写)
systemctl start ntpd # 启动服务 , 可能要5到15分钟才会生效
ntpq -p # 显示 npt server 列表,* 表示当前的
ntpstat # 显示同步状态 synchronised to NTP server (…)
watch ntpq -p # 监视状态,注意reach变化,以poll
客户端测试:
###### Linux 客户端执行测试:
ntpdate 192.168.52.5
# 成功则显示如下某一行 :
# 3 Aug 07:37:30 ntpdate[6243]: adjust time server 192.168.52.5 offset 0.149892 sec
# 3 Aug 07:41:16 ntpdate[6246]: step time server 192.168.52.5 offset 2463.842440 sec
###### Windows 10 测试 ():
# 设置日期和时间,Internet时间,更改设置,打勾,填上 192.168.52.5
# 点击立即更新,提示同步成功!
###### 特殊情况 smb
# 约几十台 瘦客户机 程序需要使用以下Windows命令:
net stop w32time & net start w32time & net time \\192.168.52.5
# 也就是依次执行:停止时间服务,启动时间服务,获取远端电脑时间
为了支持对windows机的响应,安装samba
# 双反斜杠\\开头 访问Linux, 通常是samba协议,跟ntp无关
yum install -y samba
vim /etc/samba/smb.conf # 配置文件,需要设置免密访问
[global]
workgroup = SAMBA # 与win不同也没关系
server string = Samba Server Version %v # 描述
security = user # 密码登录
map to guest = Bad User # 无须用户名和密码(关键)
[temp] # Windows中显示的文件夹
comment = temp directory
path = /temp # 共享目录
browseable = yes
writeable = yes
guest ok = yes # 允许guest即任意用户访问
create mode = 0777 # 权限
directory mode = 2777 # 权限
mkdir /temp # 创建共享目录
systemctl start smb # 启动服务
使用windows测试:
# Win测试
\\192.168.52.5 # 显示共享文件夹
# cmd
net time \\192.168.52.5 # 命令成功完成
net time \\192.168.52.5 /set /y # 同步本机时间
Windows ntp server:
######### 若 Windows 开启ntp server, 只需简单几步:
# 执行下面的命令:
reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer" /f /v "Enabled" /t REG_DWORD /d 1
reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config" /f /v "AnnounceFlags" /t REG_DWORD /d 5
net stop w32time & net start w32time
# 在关闭防火墙的前提下,其它电脑再按上面方法访问测试。
转载于//www.cnblogs.com/frx9527/p/ntp\_smb.html
还没有评论,来说两句吧...