shell脚本安装ntp server 服务
##############################Deploy ntp server ######################## echo "start deploy ntp server" yum install -y ntp if [ ! -f /var/log/ntpd.log ];then touch /var/log/ntpd.log fi chown ntp:ntp /var/log/ntpd.log cat $basepath/package/ntp.conf > /etc/ntp.conf systemctl restart ntpd systemctl enable ntpd ntppid=`ps aux|grep ntp|grep -v "grep"|awk '{print $2}'` if [ "$ntppid" ];then echo "success ! ntp-server is running now" fi
通过Ansible playbook 方式安装 ntp
- hosts: 192.168.1.62 remote_user: root tasks: - name: Install ntp yum: name: ntp state: present tags: ntp - name: Configure ntp file template: src: . /ntp .conf.j2 dest: /etc/ntp .conf - name: restart ntp service: name=ntpd state=restarted - name: Start the ntp service service: name: ntpd state: started enabled: yes tags: ntp |
cat ntp.conf.j2 driftfile /var/lib/ntp/drift restrict 127.0.0.1 restrict -6 ::1 server 192.168.1.41 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys |
执行结果:
ansible-playbook ntp_setup.yml /usr/lib/python2 .7 /site-packages/requests/__init__ .py:91: RequestsDependencyWarning: urllib3 (1.25.3) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning) PLAY [192.168.1.62] ******************************************************************************************************************************************* TASK [Gathering Facts] **************************************************************************************************************************************** ok: [192.168.1.62] TASK [Install ntp] ******************************************************************************************************************************************** ok: [192.168.1.62] TASK [Configure ntp file ] ************************************************************************************************************************************* changed: [192.168.1.62] TASK [restart ntp] ******************************************************************************************************************************************** changed: [192.168.1.62] TASK [Start the ntp service] ********************************************************************************************************************************** ok: [192.168.1.62] PLAY RECAP **************************************************************************************************************************************************** 192.168.1.62 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 登录 remote host 查看 ps aux| grep ntp ntp 27579 0.0 0.0 25720 1920 ? Ss 16:30 0:00 /usr/sbin/ntpd -u ntp:ntp -g root 27643 0.0 0.0 112708 984 pts /0 S+ 16:30 0:00 grep --color=auto ntp |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端