离线安装ntp服务,同步内网ntp。写一个脚本
时间: 2024-05-14 16:18:53 浏览: 72
以下是一个简单的脚本,它可以在Ubuntu系统上离线安装ntp服务并同步内网ntp服务器:
```bash
#!/bin/bash
# 设置ntp服务器地址
ntp_server="10.0.0.1"
# 安装ntp软件包
sudo apt-get update
sudo apt-get -y install ntp
# 配置ntp服务器地址
sudo sed -i "s/pool.ntp.org/$ntp_server/" /etc/ntp.conf
# 重启ntp服务
sudo service ntp restart
# 手动同步ntp服务器
sudo ntpdate $ntp_server
```
请注意,此脚本假设您的内网ntp服务器位于10.0.0.1。如果您的ntp服务器位于不同的IP地址,请相应地更改ntp_server变量。另外,此脚本需要以管理员身份运行(即使用sudo),以便执行安装和配置操作。
相关问题
离线centos时间同步内网ntp服务器 脚本
可以使用以下脚本来离线同步 CentOS 系统时间:
```bash
#!/bin/bash
# 设置内网 NTP 服务器 IP 地址
ntp_server="192.168.1.10"
# 安装 ntpdate
yum install -y ntpdate
# 同步时间
ntpdate $ntp_server
# 写入系统时间
hwclock --systohc
echo "Time has been synchronized with $ntp_server."
```
注意,该脚本需要在 root 用户权限下运行。另外,如果系统已经安装了 ntp 服务,则可以不用安装 ntpdate,直接使用 ntpdate 命令进行时间同步即可。
没网,安装ntp服务时间同步内网ntp服务器 脚本
安装 NTP 服务:
```
sudo apt-get update
sudo apt-get install ntp
```
编辑 NTP 配置文件 `/etc/ntp.conf`:
```
sudo nano /etc/ntp.conf
```
将默认的 NTP 服务器地址注释掉,添加你的内网 NTP 服务器地址,例如:
```
# pool.ntp.org servers
#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org
# Use internal NTP server
server internal-ntp-server.local
```
保存并退出。
重启 NTP 服务:
```
sudo systemctl restart ntp
```
检查 NTP 服务状态:
```
sudo systemctl status ntp
```
如果状态显示为 active (running),说明 NTP 服务已经成功安装并同步了时间。如果状态显示为 inactive (dead),则有可能是配置文件错误或者无法连接到内网 NTP 服务器。
阅读全文
相关推荐
















