linux基本优化脚本,linux系统优化脚本

#!/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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值