当前位置:操作系统 > Unix/Linux >>

阿里云服务器LINUX CENTOS系统优化

适用环境

阿里云服务器经济A型/B型,标准A型/B型/C型/D型/E型
系统版本:Centos 5.4(32位)

Centos5.4 32位系统初始配置

Installed Groups:
Editors 编辑器
Games and Entertainment 游戏和娱乐
Graphics 图形
Mail Server 邮件服务
Network Servers 网络服务器
Office/Productivity 办公
Sound and Video 影音
System Tools 系统工具
Text-based Internet 基于文本的互联网
Web Server web服务器
Yum Utilities ……
Available Groups:
Administration Tools 管理员工具
Authoring and Publishing 创作和出版
Base 命令解释器Bash – 全称:Bourne Again shell
Beagle linux桌面搜索工具
Cluster Storage 集群储蓄 –你使用到吗?
Clustering 聚类
DNS Name Server DNS服务器
Development Libraries 开发库
Development Tools 开发工具
Dialup Networking Support 拨号联网支持
Eclipse Eclipse –(这个我想不用我解释了)
Engineering and Scientific 工程与科学
FTP Server FTP服务器
FreeNX and NX 类似于一个window下的3389的远程链接工具
GNOME Desktop Environment GNOME桌面环境
GNOME Software Development GNOME软件开发环境
Graphical Internet 基于图形的互联网
Horde 可以理解为是“一个函数库”
Java Development JAVA开发环境
KDE (K Desktop Environment) KDE(K桌面环境)
KDE Software Development KDE(桌面软件开发环境)
Legacy Network Server 传统(老的)网络服务器
Legacy Software Development 传统(老的)网络服务器开发环境
Legacy Software Support 传统(老的)软件支持
Mono Mono是一个集体的, 自发的开发项目, 好像是为了开发一个开放源代码的….[概念太长了记不得那么多了]
MySQL Database MySQL数据库
News Server 新闻服务器
OpenFabrics Enterprise Distribution OpenFabrics企业分布
PostgreSQL Database PostgreSQL数据库
Printing Support 打印支持
Server Configuration Tools 服务配置工具
Tomboy Tomboy 是Gnome 的一款便笺程序(……,这个东西都有!还真齐全啊)
Windows File Server Windows 文件服务器
X Software Development X 桌面的软件开发环境
X Window System X窗口系统
XFCE-4.4 Xfce 是用于Unix 类操作系统的轻量级桌面环境(好多桌面环境的程序啊)
Xen Xen是一个基于虚拟硬件监控器技术的虚拟化软件(这个我搞不懂在阿里云主机里面是做什么用处的,建议保留吧!(不过好像也没什么用处,因为虚拟化是外层,不关系统内层什么事情,也可以删除了))
Done

以下是我删除的软件包:

yum groupremove “Games and Entertainment” “System Tools” “Editors” “News Server” “DNS Name Server” “FTP Server” “GNOME Desktop Environment” “GNOME Software Development” “MySQL Database” “Windows File Server” “X Window System” “X Software Development” “Web Server” “Office/Productivity” “Graphics” “Graphical Internet” “Text-based Internet” “Printing Support” “Dialup Networking Support” “Legacy Network Server” “Legacy Software Development” “Legacy Software Support” “Sound and Video” “Mail Server” “Eclipse”
(如还需要删除其他的可以自行加入,同时需要记清楚你删除了什么,避免发生不必要的损失)

卸载一些没卸载干净的:

rpm -qa |grep mysql
rpm -qa |grep apache
rpm -qa |grep php
rpm -qa|grep x11
rpm -qa |grep avahi
rpm -qa |grep gnome

删除方式如:rpm -e gnome-games.i386 1:2.16.0-2.el5

删除没有用处的帐号:

userdel adm
userdel lp
userdel sync
userdel shutdown
userdel halt
userdel news
userdel uucp
userdel operator
userdel games
userdel gopher
userdel ftp
groupdel adm
groupdel lp
groupdel news
groupdel uucp
groupdel dip

停掉不需要的服务

下面是我停掉的,你认为那些对你有用的你就就留着吧!

linux新型电源管理标准,建议笔记本使用
chkconfig acpid off

和 cron 相似的任务调度器,只不过它并不要求系统持续运行
chkconfig anacron off

运行用户用at命令调度的任务,需要用到at的得留着
chkconfig atd off

不做打印服务器的就关了吧
chkconfig cups off

系统安装后第一次启动的配置工具
chkconfig firstboot off

ipv6防火墙
chkconfig ip6tables off

主要用于SELinux,不开SELinux的话就关了
chkconfig mcstrans off

SELinux用于监控文件
chkconfig restorecond off

邮件程序,如果不是邮件服务器就关了
chkconfig sendmail off
SELinux Troubleshooting
chkconfig setroubleshoot off

iptables防火墙(如果不使用防火墙的可以停了)
chkconfig iptables off

到这一步如果仔细看的人可能已经发现了,对就是VIM编辑器也被我们卸载了,那么我再安装回去吧
使用命令:
yum -y install vim*
(安装好就可以使用VIM编辑器了)

改SSH登陆端口号

wget http://cong5.net/download/sshport.sh
#sh sshport.sh 你需要修改的端口号
如:#sh sshport.sh 22456

(不要直接复制,填写你自己想修改的端口号,端口可选范围:22 – 65535 以内,为了系统的安全性尽量往高设置)
(如果信不过上面的Sheell脚本的可以自己去Google搜索:“Linux修改ssh登陆端口”)

开启防火墙iptables

先清除已经有的iptables规则:
iptables -F
iptables -X
iptables -Z

开放指定端口:
(需要在防火墙里面留下你修改的SSH登陆端口:修改第4行,把22修改为你更换的端口)

iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -j ACCEPT
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
iptables -A INPUT -p tcp –dport 80 -j ACCEPT
iptables -A INPUT -p tcp –dport 21 -j ACCEPT
iptables -A INPUT -p tcp –dport 20 -j ACCEPT
iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT

说明解释:
#允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

# 允许已建立的或相关连的通行
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

#允许所有本机向外的访问
iptables -A OUTPUT -j ACCEPT

# 允许访问22端口
iptables -A INPUT -p tcp –dport 22 -j ACCEPT

#允许访问80端口
iptables -A INPUT -p tcp –dport 80 -j ACCEPT

#允许FTP服务的21和20端口
iptables -A INPUT -p tcp –dport 21 -j ACCEPT
iptables -A INPUT -p tcp –dport 20 -j ACCEPT
#如果有其他端口的话,规则也类似,稍微修改上述语句就行

#禁止其他未允许的规则访问
iptables -A INPUT -j REJECT (注意:如果22端口未加入允许规则,SSH链接会直接断开。)
iptables -A FORWARD -j REJECT

iptables屏蔽IP:
#如果只是想屏蔽IP的话“3、开放指定的端口”可以直接跳过。
#屏蔽单个IP的命令是
iptables -I INPUT -s 123.45.6.7 -j DROP
#封整个段即从123.0.0.1到123.255.255.254的命令
iptables -I INPUT -s 123.0.0.0/8 -j DROP
#封IP段即从123.45.0.1到123.45.255.254的命令
iptables -I INPUT -s 124.45.0.0/16 -j DROP
#封IP段即从123.45.6.1到123.45.6.254的命令是
iptables -I INPUT -s 123.45.6.0/24 -j DROP

查看已添加的iptables规则:
iptables -L -n

删除已添加的iptables规则
将所有iptables以序号标记显示,执行:
iptables -L -n –line-numbers
比如要删除INPUT里序号为5的规则,执行:
iptables -D INPUT 5

添加iptables防火墙为开机启动:
chkconfig –level 345 iptables on

保存防火墙规则:
service iptables save

重启Iptables:
service iptables restart

以上的优化文章内容仅供大家参考,记得在操作前如果服务器有数据的先备份全部数据,同时优化过程中产生的一切后果须有其本人负责,与作者无关

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,