ubuntu 16.04.7初始化脚本

#!/bin/bash
#在root用户下运行

cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sed -i "s@http://.*security.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

apt update
apt upgrade -y


sed -ri 's/^.*(UseDNS) .*$/\1 no/' /etc/ssh/sshd_config && sed -rn '/UseDNS/p' /etc/ssh/sshd_config
sed -ri 's/^.*(GSSAPIAuthentication ).*$/\1no/' /etc/ssh/sshd_config && sed -rn '/GSSAPIAuthentication/p' /etc/ssh/sshd_config

#设置时区
timedatectl set-timezone Asia/Shanghai
timedatectl status
systemctl status ntp
systemctl disable ntp
systemctl stop ntp
apt -y install chrony

sed -ri "s/^(.*pool.*)$/#\1/" /etc/chrony/chrony.conf
c=`cat /etc/chrony/chrony.conf | grep 'aliyun'|wc -l`
echo $c

if [[ $c -eq 0 ]];then
cat << EOF >> /etc/chrony/chrony.conf 
server ntp.aliyun.com iburst
server ntp.tuna.tsinghua.edu.cn iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
EOF
systemctl restart chrony
#开机自启
systemctl enable chrony
else
echo "时间同步已经配置"
fi
#强制同步一次时间
chronyc -a makestep
chronyc sources
#查看状态
chronyc sourcestats

#开启时间同步服务
timedatectl set-ntp yes


u=`cat /etc/security/limits.conf | grep 20480`
echo $u
if [[ $u -eq 0 ]];then
cat << EOF >> /etc/security/limits.conf
root     soft    nofile          45536
root     hard    nofile          45536
*        soft    nproc           20480
*        hard    nproc           20480
*        soft    nofile          45536
*        hard    nofile          45536
*        soft    memlock         unlimited
*        hard    memlock         unlimited
EOF
else
echo "ulimit已经配置"
fi
p=`cat /root/.profile | grep PS1 |wc -l`
echo $p
if [[ $p -eq 0 ]];then
cat << EOF >> /root/.profile
PS1="\[\e[1;32m\][\[\e[0m\]\t \[\e[1;33m\]\u\[\e[36m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\\\$ "
EOF
else
echo "PS1已经配置"
fi
systemctl set-default multi-user.target
apt install tree net-tools language-pack-zh-hans language-pack-en build-essential autoconf automake fakeroot  make cmake gcc openssl unzip ntp libaio-dev  gdb gdb-doc cgdb dh-make  git git-doc python-dev-is-python3 curl wget vim zlib1g-dev  -y
apt install bash-completion openssh-server ntpdate telnet lrzsz ipvsadm -y
apt install lrzsz -y
apt-get install language-pack-zh-hans -y
localectl set-locale LANG=zh_CN.utf8
apt install ubuntu-dev-tools -y
sed -ri 's/^(\$ActionFileDefaultTemplate ).*$/\1RSYSLOG_FileFormat/' /etc/rsyslog.conf && systemctl restart rsyslog.service
sed -ri "s/^weekly/monthly/" /etc/logrotate.conf
reboot

22.04脚本

#!/bin/bash
#在root用户下运行

cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sed -i "s@http://.*security.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

apt update
apt upgrade -y


sed -ri 's/^.*(UseDNS) .*$/\1 no/' /etc/ssh/sshd_config && sed -rn '/UseDNS/p' /etc/ssh/sshd_config
sed -ri 's/^.*(GSSAPIAuthentication ).*$/\1no/' /etc/ssh/sshd_config && sed -rn '/GSSAPIAuthentication/p' /etc/ssh/sshd_config

#设置时区
timedatectl set-timezone Asia/Shanghai
timedatectl status
systemctl status ntp
systemctl disable ntp
systemctl stop ntp
apt -y install chrony

sed -ri "s/^(.*pool.*)$/#\1/" /etc/chrony/chrony.conf
c=`cat /etc/chrony/chrony.conf | grep 'aliyun'|wc -l`
echo $c

if [[ $c -eq 0 ]];then
cat << EOF >> /etc/chrony/chrony.conf 
server ntp.aliyun.com iburst
server ntp.tuna.tsinghua.edu.cn iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
EOF
systemctl restart chrony
#开机自启
systemctl enable chrony
else
echo "时间同步已经配置"
fi
#强制同步一次时间
chronyc -a makestep
chronyc sources
#查看状态
chronyc sourcestats

#开启时间同步服务
timedatectl set-ntp yes


u=`cat /etc/security/limits.conf | grep 20480`
echo $u
if [[ $u -eq 0 ]];then
cat << EOF >> /etc/security/limits.conf
root     soft    nofile          45536
root     hard    nofile          45536
*        soft    nproc           20480
*        hard    nproc           20480
*        soft    nofile          45536
*        hard    nofile          45536
*        soft    memlock         unlimited
*        hard    memlock         unlimited
EOF
else
echo "ulimit已经配置"
fi
p=`cat /root/.profile | grep PS1 |wc -l`
echo $p
if [[ $p -eq 0 ]];then
cat << EOF >> /root/.profile
PS1="\[\e[1;32m\][\[\e[0m\]\t \[\e[1;33m\]\u\[\e[36m\]@\h\[\e[1;31m\] \W\[\e[1;32m\]]\[\e[0m\]\\\\$ "
EOF
else
echo "PS1已经配置"
fi
systemctl set-default multi-user.target
apt install tree net-tools language-pack-zh-hans language-pack-en build-essential autoconf automake fakeroot  make cmake gcc openssl unzip ntp libaio-dev  gdb gdb-doc cgdb dh-make  git git-doc python-dev-is-python3 curl wget vim zlib1g-dev  -y
apt install bash-completion openssh-server ntpdate telnet lrzsz ipvsadm -y
apt install lrzsz -y
apt install ubuntu-dev-tools iptables-persistent -y
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
sed -ri 's/^(\$ActionFileDefaultTemplate ).*$/\1RSYSLOG_FileFormat/' /etc/rsyslog.conf && systemctl restart rsyslog.service
sed -ri "s/^weekly/monthly/" /etc/logrotate.conf

cat > /etc/default/locale <<EOF
LANG=zh_US.UTF-8
LANGUAGE=zh_CN:zh:en_US:en
EOF
reboot
posted @   厚礼蝎  阅读(23)  评论(0编辑  收藏  举报
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示