#!/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
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
apt -y install chrony
sed -ri "s/^(.*pool.*)$/#\1/" /etc/chrony.conf
c=`cat /etc/chrony.conf | grep 'aliyun'|wc -l`
echo $c
if [[ $c -eq 0 ]];then
cat << EOF >> /etc/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 chronyd
#开机自启
systemctl enable chronyd
else
echo "时间同步已经配置"
fi
chronyc sources
u=`cat /etc/security/limits.conf | grep 20480`
echo $u
if [[ $u -eq 0 ]];then
cat << EOF >> /etc/security/limits.conf
* 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 -y
apt install bash-completion -y
apt groups install "Development Tools" -y
apt install yum-utils.noarch -y
apt install lrzsz -y
sed -ri 's/^(\$ActionFileDefaultTemplate ).*$/\1RSYSLOG_FileFormat/' /etc/rsyslog.conf && systemctl restart rsyslog.service
sed -ri "s/^weekly/monthly/" /etc/logrotate.conf
reboot
标签:初始化,aliyun,16.04,apt,etc,sed,conf,ubuntu,com
From: https://www.cnblogs.com/guangdelw/p/17315948.html