Linux system optimization Scripts

Source: Internet
Author: User
Tags snmp ssh port

#!/bin/bash

# This script was created by Tangbo.

# E_mail:[email Protected]

# 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 '} '

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 article from "Bobcat" blog, declined reprint!

Linux system optimization Scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.