当前位置:首页 > linux运维

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

14324472932年前 (2024-10-26)linux运维1524

支持内容:
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&…

Docker配置可视化Portainer(汉化版)

docker pull 6053537/portainer-ce使用docker拉取portainer汉化版,拉取其他版本自行百度拉取后利用以下命令查询拉取的镜像IDdocker images…

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+ /…

旁路由模式下(群晖或其他设备)docker无法访问hub.docker.com解决方案

旁路由模式下(群晖或其他设备)docker无法访问hub.docker.com解决方案

1.使用openwrt中的passwall插件,配置好其他相关数据后,在此处Socks配置中配置。 配置好后当状态为两个对号表示配置成功。 此时旁路由即开启了http端口,使用方式为:旁路由ip:3434 如果使用群晖,在群晖:控制面板-网络-常规中配置代理无服器即可 ![](https://ww…

使用自定义docker加速地址下载镜像

1.例如加速地址为:https://docker.1ms.run2.配置docker加速地址cat > /etc/docker/daemon.json <<EOF > {"registry-mirrors":&nb…

发表评论

访客

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