当前位置:首页 > linux运维

linux基线配置脚本(自己更具需求书写,并不适合所有人)

14324472931年前 (2024-10-26)linux运维1287

支持内容:
1.检查更新系统时间,并设置时区为北京时区。

#!/bin/bash  
  
# 更新系统时间(假设你有NTP服务或者可以访问互联网时间服务器)  
echo "Updating system time using NTP..."  
sudo timedatectl set-ntp true  
  
# 检查是否成功设置了NTP,如果失败则尝试手动同步时间(需要安装ntpdate或chrony)  
if ! timedatectl status | grep -q "NTP synchronized: yes"; then  
    echo "NTP synchronization failed, trying to manually synchronize time..."  
    # 安装ntpdate(如果未安装)  
    if ! command -v ntpdate &> /dev/null; then  
        echo "Installing ntpdate..."  
        sudo apt-get update -y && sudo apt-get install -y ntpdate  # 对于Debian/Ubuntu系统  
        # 对于RedHat/CentOS系统,使用以下命令:  
        # sudo yum install -y ntpdate  
    fi  
      
    # 使用ntpdate从时间服务器同步时间  
    sudo ntpdate pool.ntp.org  
fi  
  
# 设置系统时区为北京时区  
echo "Setting timezone to Asia/Shanghai (Beijing time)..."  
sudo timedatectl set-timezone Asia/Shanghai  
  
# 验证时间和时区设置  
echo "System time and timezone settings:"  
timedatectl status  
  
echo "System time and timezone have been updated successfully."

扫描二维码推送至手机访问。

版权声明:本文由爱开发博客发布,如需转载请注明出处。

本文链接:https://www.lovekf.cn/?id=33

分享给朋友:

“linux基线配置脚本(自己更具需求书写,并不适合所有人)” 的相关文章

linux 基线配置常用命令

vi /etc/selinux/config SELINUX=disabled vi /etc/sysctl.conf net.ipv6.conf.all.disable_ipv6 =1 net.ipv6.conf.default.disable_ipv6&…

Xray VLESS+TCP+XTLS/TLS+Nginx+WebSocket 一键安装脚本 By wulabing

Xray VLESS+TCP+XTLS/TLS+Nginx+WebSocket 一键安装脚本 By wulabing

Xray 基于 Nginx 的 VLESS + XTLS 一键安装脚本,支持VLESS + TCP + TLS + Nginx + VLESS + TCP + XTLS / TLS + Nginx等多种组合一键安装,系统支持Debian 9+ / Ubuntu 18.04+ / Centos7+ /…

nas 里好用的docker 推荐

</head><body>1.adguard/adguardhome这是一个广告拦截项目,具备dns功能,特别适合在局域网部署,防止dns污染和用于做开发测试的时候对测试域名进行host。   --restart unless-stop…

自建内网穿透服务器-基于Docker的FRP内网穿透部署

创建配置文件# 创建存放目录 sudo mkdir /etc/frp # 创建frps.ini文件 vim /etc/frp/frps.tomlfrps.toml文件配置内容[common] # 监听端口 bind_port&nb…

openvpn服务端一键搭建

需求: 搭建openvpn目的是安全访问内网和匿名访问其他网站,确保隐私信息不会泄露。 搭建方法: 1.复制以下脚本命名为“openvpn-install.sh”,在ssh中执行。 ```bash#!/bin/bash shellcheck disable=SC1091,SC2164,SC…

aria2配置文件和bt-tracker定期更新脚本

# # https://github.com/P3TERX/aria2.conf # File name:aria2.conf # Description: Awesome Aria2 configuration file # Version: 2021.09.15 # # Copyright (c…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。