常用Linux系统优化脚本

简介:
#!/bin/sh
 
# 服务优化,(sshd、network、crond、syslog、rsyslog)服务保持默认开机启动
ServiceList=$(chkconfig --list |  grep  '0'  awk  '{print $1}'  grep  -Ev  'sshd|network|crond|syslog' )
 
for  Service  in  $ServiceList
do
     /etc/init .d/$Service stop
     chkconfig --level 0123456 $Service off
done
 
# 内核参数调优
grep  -q  "vm.swappiness = 0"  /etc/sysctl .conf ||  cat  >>  /etc/sysctl .conf << EOF
########################################
vm.swappiness = 0
net.core.rmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_default = 262144
net.core.wmem_max = 16777216
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 786432 1048576 1572864
fs.aio-max-nr = 1048576
fs. file -max = 6815744
kernel.sem = 250 32000 100 128
fs.inotify.max_user_watches = 1048576
EOF
sysctl -p
 
grep  -q  "* - nofile 65536"  /etc/security/limits .conf ||  cat  >>  /etc/security/limits .conf << EOF
########################################
* - nofile 1048576
* - nproc  65536
* - stack  1024
EOF
 
grep  -q  "ulimit -n 65536"  /etc/profile  ||  cat  >>  /etc/profile  << EOF
########################################
ulimit  -n 1048576
ulimit  -u 65536
ulimit  -s 1024
 
alias  grep = 'grep --color=auto'
export  HISTTIMEFORMAT= "%Y-%m-%d %H:%M:%S "
EOF
 
# 禁用并关闭selinux
sed  -i  's/SELINUX=enforcing/SELINUX=disabled/'  /etc/selinux/config
setenforce 0
 
# 优化SSH
sed  -i  's/.*UseDNS yes/UseDNS no/'  /etc/ssh/sshd_config
sed  -i  's/.*GSSAPIAuthentication yes/GSSAPIAuthentication no/'  /etc/ssh/sshd_config
/etc/init .d /sshd  restart
 
# 脚本目录加入PATH环境变量
grep  -q  "/App/script"  $HOME/.bash_profile ||  cat  >> $HOME/.bash_profile << EOF
########################################
export  PATH= /App/script :\$PATH
EOF
 
mkdir  -p  /App/script  /App/src
 
# 挂载tmpfs文件系统
mount  --bind  /dev/shm  /tmp
grep  -q  "/dev/shm"  /etc/rc . local  ||  echo  "/bin/mount --bind /dev/shm /tmp"  >>  /etc/rc . local                 
本文转自 15816815732 51CTO博客,原文链接:http://blog.51cto.com/68686789/1717608
相关文章
|
21天前
|
Ubuntu Linux
Linux(21) Linux自定义开机启动脚本或命令
Linux(21) Linux自定义开机启动脚本或命令
33 3
|
1月前
|
Linux Shell
嵌入式Linux系统脚本小技巧之启动脚本
嵌入式Linux系统脚本小技巧之启动脚本
19 2
|
1月前
|
运维 Java Shell
Linux非常详细的shell运维脚本一键启动停止状态SpringBoot打成可运行jar包
Linux非常详细的shell运维脚本一键启动停止状态SpringBoot打成可运行jar包
35 0
|
1月前
|
Shell Linux
Linux使用Shell脚本SCP批量传输脚本
Linux使用Shell脚本SCP批量传输脚本
32 0
|
1月前
|
关系型数据库 MySQL Linux
Linux系统使用定时脚本备份mysql
Linux系统使用定时脚本备份mysql
|
13天前
|
存储 Shell Linux
Linux Bash 脚本中的 IFS 是什么?
【4月更文挑战第25天】
20 0
Linux Bash 脚本中的 IFS 是什么?
|
7天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
24 5
|
8天前
|
分布式计算 大数据 Hadoop
【经验分享】用Linux脚本管理虚拟机下的大数据服务
【经验分享】用Linux脚本管理虚拟机下的大数据服务
15 1
|
8天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
15 3
|
19天前
|
监控 网络协议 数据可视化
Shell脚本查看linux系统性能瓶颈
Shell脚本查看linux系统性能瓶颈