自定制centos7系统(三)—脚本安装nodejs及配置ntp时间同步服务器

脚本目录:

在上面的文章中,我们最后说了shell初始执行的是all.sh,下面我们列出all.sh文件内容:

#!/bin/bash
echo "--------开始执行脚本---------"
cd /home/admin/linux
echo "--------开始安装node与yarn---------"
sh node.sh
echo "--------node与yarn安装成功---------"
echo "--------开始配置ntp服务器---------"
sh ntp.sh
echo "--------ntp服务器配置成功---------"
echo "kaiqiquanxian"
chmod u+x /etc/rc.d/rc.local
echo -e 'sh /home/admin/linux/linux.sh' >> /etc/rc.d/rc.local

上述脚本最后赋予开机脚本权限,将上述执行脚本的代码写入rc.local中,待正式开机时会执行linux.sh,本篇文章暂不讲解,下篇文章我们分析linux.sh里面是什么。 

node.sh:

#!/bin/bash
cd /home/admin/linux/packages
rpm -ivh nodejs-15.8.0-1nodesource.x86_64.rpm
rpm -ivh yarn-1.22.5-1.noarch.rpm

 /home/admin/linux/packages目录下有我们提前下载好的nodejs和yarn的rpm包,此处执行rpm安装node和yarn。

ntp.sh:

#!/bin/bash
#修改配置文件ntp.conf
cd /etc/sysconfig/network-scripts/
for file in $(ls *)
do
  if [ ${file:0:8} = "ifcfg-en" ]
  then echo -e 'OTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.1.9"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"' >> /etc/sysconfig/network-scripts/$file
  fi
done
rm -rf /etc/ntp.conf
cp /home/admin/linux/packages/ntp.conf /etc/
#启动ntp服务
systemctl start ntpd
#重启ntp服务
systemctl enable ntpd
systemctl restart ntpd
#开启123端口
firewall-cmd --zone=public --add-port=123/tcp --permanent
firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload
#关闭自带时间同步服务
systemctl disable chronyd.service
#设置开机自动启动
systemctl enable ntpd
systemctl stop firewalld.service
systemctl disable firewalld.service

上述脚本我们在网络配置文件中更改网络类型为静态ip,自行根据需求配置静态ip,如需要可动态配置,本处为测试写死。下面脚本复制编写好的配置文件替换原有的ntp.conf,开启123端口,设置ntp服务开机自启,ip根据个人项目需求自行更改。

ntp.conf(此处可根据自己需要更改)

driftfile /var/lib/ntp/drift
restrict -6 ::1
#允许内网其他机器同步时间
restrict 192.168.1.9 mask 255.255.255.0 nomodify notr
#定义使用的上游 ntp服务器
server cn.pool.ntp.org
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
#允许上层时间服务器主动修改本机时间
restrict cn.pool.ntp.org  nomodify notrap noquery
restrict ntp1.aliyun.com  nomodify notrap noquery
restrict ntp2.aliyun.com  nomodify notrap noquery
restrict ntp3.aliyun.com  nomodify notrap noquery
#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10

 本期结束下期再见!如果对您有帮忙,请花费您三秒钟点赞加关注用不迷路!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值