一键最大限度优化CentOS系统服务

根据各自实际情况增减。复制下面内容粘贴到你的终端,回车就可以。
也可以保存为脚本,文件头加上#!/bin/sh,另存为.sh文件运行就可以。

service acpid off
service atd stop
service auditd stop
service avahi-daemon stop
service avahi-dnsconfd stop
service bluetooth stop
service conman stop
service cpuspeed stop
service cups stop
service dnsmasq stop
service dund stop
service firstboot stop
service hidd stop
service httpd stop
service ibmasm stop
service ip6tables stop
service irda stop
service kdump stop
service lm_sensors stop
service mcstrans stop
service messagebus stop
service microcode_ctl stop
service netconsole stop
service netfs stop
service netplugd stop
service nfs stop
service nfslock stop
service nscd stop
service ntpd stop
service oddjobd stop
service pand stop
service pcscd stop
service portmap stop
service psacct stop
service rdisc stop
service restorecond stop
service rpcgssd stop
service rpcidmapd stop
service rpcsvcgssd stop
service saslauthd stop
service sendmail stop
service setroubleshoot stop
service smb stop
service vncserver stop
service winbind stop
service wpa_supplicant stop
service xfs stop
service ypbind stop
service yum-updatesd stop
chkconfig acpid off
chkconfig atd off
chkconfig auditd off
chkconfig avahi-daemon off
chkconfig avahi-dnsconfd off
chkconfig bluetooth off
chkconfig conman off
chkconfig cpuspeed off
chkconfig cups off
chkconfig dnsmasq off
chkconfig dund off
chkconfig firstboot off
chkconfig hidd off
chkconfig httpd off
chkconfig ibmasm off
chkconfig ip6tables off
chkconfig irda off
chkconfig kdump off
chkconfig lm_sensors off
chkconfig mcstrans off
chkconfig messagebus off
chkconfig microcode_ctl off
chkconfig netconsole off
chkconfig netfs off
chkconfig netplugd off
chkconfig nfs off
chkconfig nfslock off
chkconfig nscd off
chkconfig ntpd off
chkconfig oddjobd off
chkconfig pand off
chkconfig pcscd off
chkconfig portmap off
chkconfig psacct off
chkconfig rdisc off
chkconfig restorecond off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig rpcsvcgssd off
chkconfig saslauthd off
chkconfig sendmail off
chkconfig setroubleshoot off
chkconfig smb off
chkconfig vncserver off
chkconfig winbind off
chkconfig wpa_supplicant off
chkconfig xfs off
chkconfig ypbind off
chkconfig yum-updatesd off

Centos小内存VPS优化

删除不必要的软件包,服务,用户,文件等

1、删除不需要的软件包。

yum remove Deployment_Guide-en-US finger cups-libs cups
bluez-libs desktop-file-utils ppp rp-pppoe wireless-tools irda-utils
nfs-utils nfs-utils-lib rdate fetchmail eject ksh mkbootdisk mtools
syslinux tcsh startup-notification talk apmd rmt dump setserial portmap yp-tools
ypbind
rpm -qa (列出所有安装了的包)
rpm -e package (删除某个包)
rpm -qi package (查询某个包)
rpm -qf command (根据程序查询包的名字)
rpm -ql package (查询某个包所有的安装文件)

2、删除一些不安全的软件包,并且用相应安全的软件替代,如: ssh/sftp/scp 替代 telnet, rsh, ftp, rcp
注意系统需要一个默认的 MAT,删除 Sendmail MAT 之前必须先安装一个,如: Postfix。

yum remove telnet rsh ftp rcp
yum install postfix
yum remove sendmail
/sbin/chkconfig postfix off

3、停掉并且删除一些不需要的 xinetd 服务。

/sbin/service xinetd stop
/sbin/chkconfig xinetd off
rm -rf /etc/xinetd.d

4、禁止一些 /etc/init.d/ 下面不需要的服务.

/sbin/chkconfig –list
for a in acpid anacron apmd atd autofs avahi-daemon bluetooth cpuspeed
cups firstboot gpm haldaemon hidd ip6tables irqbalance isdn kdump
kudzumcstrans messagebus microcode_ctl netfs nfs nfslock pcscd portmap
readahead_early readahead_later rpcgssd rpcidmapd sendmail
setroublesshoot smartd xfs xinetd yum-updatesd;
do /sbin/chkconfig $a off; done

5、重启系统后,检查一下正在运行中的服务,看看是不是都是必须的。

netstat -an | grep LISTEN
netstat -atunp

6、为了安全起见,删除一些不需要的用户。

cp /etc/passwd /etc/passwd.sav
cp /etc/group /etc/group.sav
for a in adm lp sync news uucp operator games gopher mailnull nscd rpc;
do /usr/sbin/userdel $a -f; done
for a in lp news uucp games gopher users floopy nscd rpc rpcuser nfsnobody;
do /usr/sbin/groupdel $a -f; done

加固和优化系统

7、打开防火墙。

system-config-securitylevel-tui

8、检查和禁止全局可写的 SUID 文件。

find / -perm +4000 -user root -type f -print
find / -perm +2000 -group root -type f -print
chmod u-s /full/path/to/filename
chmod g-s /full/path/to/filename

9、只允许 root 在一个 terminal 上登录,如: tty1。

>vi /etc/securetty

10、避免其他用户按 Ctrl+Alt+Del 重启。

vi /etc/inittab

注释掉
#ca::ctrlaltdel:/sbin/shutdown -t3 -r now
11、/etc/security/console.apps/ 下面有 root 用户登录 console 后可以运行的程序,全部删除。

rm -f /etc/security/console.apps/*

12、删除一些登录信息。

vi /etc/issue (warning at login prompt)
vi /etc/motd (warning after successful login)

13、只运行一个 virtual terminal,如果是VPS 的话,自己不可能物理登录终端,可以全部禁止掉。

vi /etc/inittab
# Run gettys in standard runlevels
#1:2345:respawn:/sbin/mingetty tty1
#2:2345:respawn:/sbin/mingetty tty2

14、加固 SSH 安全。

vi /etc/ssh/sshd_config
Port 2222
Protocol 2
PermitRootLogin no
PermitEmptyPasswords no
X11Forwarding no
UsePAM no
UseDNS no
AllowUsers vpsee
Banner /etc/issue

15、安装 Bastille 软件包帮助加固。

rpm -Uvh perl-Curses-1.15-1.el5.rf.i386.rpm
rpm -ivh Bastille-3.0.9-1.0.noarch.rpm
/usr/sbin/bastille -c

16、优化 Linux 内核。

vi /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0