帮我写一份linux优化脚本
时间: 2023-11-30 16:04:14 浏览: 156
好的,以下是一个简单的Linux系统优化脚本,你可以根据需要进行修改和调整:
```bash
#!/bin/bash
# 优化内核参数
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=16384
sudo sysctl -w net.ipv4.tcp_fin_timeout=15
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
sudo sysctl -w net.ipv4.tcp_tw_recycle=1
sudo sysctl -w net.ipv4.ip_local_port_range='1024 65535'
sudo sysctl -w net.ipv4.tcp_max_tw_buckets=6000
sudo sysctl -w net.ipv4.tcp_keepalive_time=600
sudo sysctl -w net.ipv4.tcp_keepalive_probes=3
sudo sysctl -w net.ipv4.tcp_keepalive_intvl=15
sudo sysctl -w net.ipv4.tcp_syncookies=1
# 安装优化工具
sudo apt-get update
sudo apt-get install -y htop iotop iftop sysstat
# 清理无用软件及文件
sudo apt-get autoremove -y
sudo apt-get autoclean -y
sudo apt-get clean -y
# 关闭不必要的服务
sudo systemctl disable bluetooth.service
# 修改SSH配置
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/g' /etc/ssh/sshd_config
sudo sed -i 's/#MaxSessions 10/MaxSessions 5/g' /etc/ssh/sshd_config
sudo systemctl reload sshd
# 关闭IPv6
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee /etc/sysctl.d/disableipv6.conf
sudo sysctl -p
# 设置时区为上海
sudo timedatectl set-timezone Asia/Shanghai
echo "系统优化完成!"
```
你可以将上述代码保存为一个`.sh`文件,然后使用`sudo`权限运行该脚本即可。
阅读全文