平时写的各种linux shell脚本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

4 years ago
#!/bin/bash
##### 新系统初始化 #####
#同步时间
function sync_time() {
4 years ago
echo '正在执行时间同步......'
4 years ago
yum -y install ntpdate
#设置时区
timedatectl set-local-rtc 1
timedatectl set-timezone Asia/Shanghai
#同步时间
ntpdate -u pool.ntp.org
ntpd=(`which ntpdate`)
#定时任务
echo "*/20 * * * * ${ntpd} pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/root
systemctl reload crond
echo "同步成功,当前时间:" `date`
}
4 years ago
#修改SSH端口
function change_port() {
echo '正在修改SSH端口......'
config_file="/etc/ssh/sshd_config"
if grep -q "^Port" $config_file;then
sed -i "/^Port/c Port 1993" $config_file
else
echo "Port 1993" >> $config_file
fi
systemctl restart sshd
firewall-cmd --zone=public --add-port=1993/tcp --permanent
firewall-cmd --reload
echo 'SSH端口修改完毕......'
}
4 years ago
#安装BBR
function insrall_bbr() {
4 years ago
echo '正在安装BBR......'
4 years ago
yum -y install wget
wget https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm --import RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
#升级最新内核
yum --enablerepo=elrepo-kernel install kernel-ml -y
#设置最新内核
grub2-set-default 0
#写入配置文件
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
#清理工作
rm -rf RPM-GPG-KEY-elrepo.org bbr.sh
4 years ago
echo 'BBR安装完毕,10s后重启...'
4 years ago
#重启服务器
reboot
}
4 years ago
sync_time
change_port
insrall_bbr