linux系统优化脚本
2016-03-18 17:10
281 查看
#!/bin/bash
# this script is created by tangbo.
# e_mail:79313760@qq.com
# version:1.0
#################################################
#################################################
#set -x
# Set Language and must be root
export LANG="zh_CN.GB18030"
if [[ "$(whoami)" != "root" ]]
then
echo "please,Run This Script As root." >&2
exit 1
fi
#soure function library
. /etc/init.d/functions
#config YUM CentOS-Base.repo
ConfigYum(){
echo "Exchange CentOS-Base.repo"
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.backup.$(date +%F)
ping -c1 www.baidu.com &> /dev/null
[ $? -ne 0 ] && echo $"Networking not configured - exiting." && exit 1
wget --quiet -o /dev/null http://mirrors.163.com/.help/CentOS6-Base-163.repo &>/dev/null
mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all &> /dev/null
echo "Exchange CentOS-Base.repo Success"
sleep 1
}
#Install Init Packages
installTool(){
echo "Please,Wait,Installing:sysstat ntp net-snmp lrzsz"
yum -y install sysstat ntp net-snmp lrzsz >/dev/null 2>&1
echo -e "installTool\nversion information:\n`rpm -qa sysstat ntp net-snmp lrzsz`"
sleep 1
}
#Close Selinux and Iptables
initFirewall(){
echo "Close Selinux and Iptables"
cp /etc/selinux/config /etc/selinux/config.`date +"%Y-%m-%d_%H-%M-%S"`
/etc/init.d/iptables stop &> /dev/null
service iptables status
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
grep SELINUX=disabled /etc/selinux/config
echo "Close selinux ->OK iptables->OK"
sleep 1
}
#Init Auto Startup service
initService(){
echo "STOP Service"
export LANG="en_US.UTF-8"
for test in `chkconfig --list | grep 3:on | awk '{print $1}'`
do
# print $test
chkconfig --level 3 $test off
done
for tangbo in crond network syslog sshd
do
chkconfig --level 3 $tangbo on &>/dev/null
done
#export LANG="zh_CN.GB18030"
echo "stop not service->OK"
sleep 1
}
#Change SSH port and stop root
initSsh(){
echo "#---sshConfig change 22,stop root ---#"
export LANG="en_US.UTF-8"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
/etc/init.d/sshd reload && echo "ssh chang true" || echo "ssh chang false"
}
#set sync-System-Time
syncSystemTime(){
echo "set sync-system-time-success"
echo "*/2 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null 2>&1" >>/var/spool/cron/root
}
#set file limits
openFiles(){
echo "#---file=65535---#"
export LANG="en_US.UTF-8"
\cp /etc/security/limits.conf /etc/security/limits.conf.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i '/# End of file/i\*\t\t-\tnofile\t\t65535' /etc/security/limits.conf
ulimit -HSn 65535
echo "set files success"
sleep 1
}
#set alias
alias(){
echo "set alias"
echo "alias grep='grep --color'" >> /root/.bashrc
source /root/.bashrc
sleep 1
}
本文出自 “山猫” 博客,谢绝转载!
# this script is created by tangbo.
# e_mail:79313760@qq.com
# version:1.0
#################################################
#################################################
#set -x
# Set Language and must be root
export LANG="zh_CN.GB18030"
if [[ "$(whoami)" != "root" ]]
then
echo "please,Run This Script As root." >&2
exit 1
fi
#soure function library
. /etc/init.d/functions
#config YUM CentOS-Base.repo
ConfigYum(){
echo "Exchange CentOS-Base.repo"
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.backup.$(date +%F)
ping -c1 www.baidu.com &> /dev/null
[ $? -ne 0 ] && echo $"Networking not configured - exiting." && exit 1
wget --quiet -o /dev/null http://mirrors.163.com/.help/CentOS6-Base-163.repo &>/dev/null
mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all &> /dev/null
echo "Exchange CentOS-Base.repo Success"
sleep 1
}
#Install Init Packages
installTool(){
echo "Please,Wait,Installing:sysstat ntp net-snmp lrzsz"
yum -y install sysstat ntp net-snmp lrzsz >/dev/null 2>&1
echo -e "installTool\nversion information:\n`rpm -qa sysstat ntp net-snmp lrzsz`"
sleep 1
}
#Close Selinux and Iptables
initFirewall(){
echo "Close Selinux and Iptables"
cp /etc/selinux/config /etc/selinux/config.`date +"%Y-%m-%d_%H-%M-%S"`
/etc/init.d/iptables stop &> /dev/null
service iptables status
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
grep SELINUX=disabled /etc/selinux/config
echo "Close selinux ->OK iptables->OK"
sleep 1
}
#Init Auto Startup service
initService(){
echo "STOP Service"
export LANG="en_US.UTF-8"
for test in `chkconfig --list | grep 3:on | awk '{print $1}'`
do
# print $test
chkconfig --level 3 $test off
done
for tangbo in crond network syslog sshd
do
chkconfig --level 3 $tangbo on &>/dev/null
done
#export LANG="zh_CN.GB18030"
echo "stop not service->OK"
sleep 1
}
#Change SSH port and stop root
initSsh(){
echo "#---sshConfig change 22,stop root ---#"
export LANG="en_US.UTF-8"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
sed -i 's%#Port 22%Port 4022%' /etc/ssh/sshd_config
/etc/init.d/sshd reload && echo "ssh chang true" || echo "ssh chang false"
}
#set sync-System-Time
syncSystemTime(){
echo "set sync-system-time-success"
echo "*/2 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null 2>&1" >>/var/spool/cron/root
}
#set file limits
openFiles(){
echo "#---file=65535---#"
export LANG="en_US.UTF-8"
\cp /etc/security/limits.conf /etc/security/limits.conf.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i '/# End of file/i\*\t\t-\tnofile\t\t65535' /etc/security/limits.conf
ulimit -HSn 65535
echo "set files success"
sleep 1
}
#set alias
alias(){
echo "set alias"
echo "alias grep='grep --color'" >> /root/.bashrc
source /root/.bashrc
sleep 1
}
本文出自 “山猫” 博客,谢绝转载!
相关文章推荐
- centos 6.x 开机自启动ejabberd
- 加速Linux程序编译
- linux抓sip
- linux中的IDR机制
- Linux命令:less
- 谈谈Linux内核驱动的coding style
- Ubuntu/centos/redhat/SUSE sipp安装(带rtp支持,3.5.1版本)
- 如何在Linux下创建新的交换空间swap的方法
- Linux进程通信-信号学习
- linux文件属性改变
- 使用VS GDB扩充套件在VS上远端侦错Linux上的C/C++程序
- linux 下php的安全优化
- Lessong 7 纹理加载和渲染
- [linux]SSH公钥登录
- 互斥锁与条件变量的配合! (关于互斥锁和条件变量分析的比较透彻)
- linux 路由表 的一些相关资料
- linux系统学习笔记:文件、目录、用户
- Linux时间函数之gettimeofday()函数之使用方法
- Centos 创建本地yum源
- linux 下 rsync 备份/同步文件