安装系统后的简单调优
1关闭SELINUX
SELinux 是美国安全局NSA对于强制访问控制的安全工具,控制比较严格,生产环境不用。
[root@oldboy ~]# cat /etc/selinux/config #查看SELINUX配置文件
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@oldboy ~]# sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config #修改SELINUX配置文件
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@oldboy ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@oldboy ~]# getenforce #查看SELINUX运行状态
Enforcing
[root@oldboy ~]# setenforce #设置SELINUX运行状态
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboy ~]# setenforce 0 #设置SELINUX运行状态permissive
[root@oldboy ~]# getenforce
Permissive
注意:修改配置文件后必须要重启生效,而 setenforce设置SELINUX运行状态只是保证现在生效。两者结合起来保证SELINUX关闭永久生效。
2设置LINUX运行级别
1)运行级别是什么:runlevel :linux运行时的一种状态标识用数字表示。
0 halt 关机状态
1 single user 单用户
2 multisuser without nfs 多用户没有NFS网络文件系统
3 fullmutiuser mode 文本模式 (工作模式)
4 unused 保留
5 x11 图形,桌面
6 reboot 重启
2)如何查看当前系统的运行级别
[root@oldboy ~]# runlevel #查看LINUX运行级别
N 3 #第一个为前一次的运行级别 第二个为当前的运行级别
3)查看LINUX启动时候的LINUX级别
[root@oldboy ~]# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault: #设置LINUX开机运行级别为3
3.精简自启动服务 (预习补充)
1>设置开机自启动
节省开机时间,加快启动速度节省资源开销,减少安全隐患(服务越少漏洞越少)。
2>需要保留的开机自启动服务
1.SSHD
2.rsyslog
是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog将各种信息写到各个系统日志文件中。
3.network
4.crond
周期性处理一些重复的问题计划任务服务。
5.Sysstat
是一个软件包,包括监控系统性能及效率的一组工具包括了iostat mpstat sar
3>设置开机自启动服务的常见方法
1.setup>system service在弹出来的窗口进行设置
2.执行ntsysv,在弹出来的窗口进行设置
3.chkconfig 保证必须的服务开启就可以了
[root@oldboy ~]# chkconfig --list |grep "3:on"|awk '{print$1}'|grep -EV "sshd|rsyslog|network|crond|sysstat"|sed -r 's#(.*)#chkconfig 1 off#g'|bash
chkconfig --list 查看开启的服务
chkconfig ntp on 开启ntp服务
grep ”3:on” (匹配3级别下开启的)。
awk ’{print $1}’ (打印第一列 即服务的名字)。
grep -Ev ”sshd|rsyslog|network|crond|sysstat” (-E 同时过滤 -v 排除)。
sed -r ’s#(.*)#chkconfig 1 off#g’ |bash (r表示支持正则 后面是sed的一个后向引用)。
也可以用 awk ’{print ”chkconfig “ $1 ” off”}’ |bash 来替代sed。
4 shell for 循环
4.关闭防火墙
[root@oldboy ~]# /etc/init.d/iptables stop #临时关闭
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@oldboy ~]# /etc/init.d/iptables status #查看状态
iptables: Firewall is not running.
[root@oldboy ~]# chkconfig iptables off #开机也不启动
跟关闭SELINUX一样,关闭防火墙也是修改配置文件和设置临时关闭两者结合起来保证防火墙永久关闭。
5.LINUX 中文显示
调整字符集为UTF-8既可。
[root@oldboy ~]# cat /etc/sysconfig/i18n #查看当前字符集设置
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[root@oldboy ~]# echo 'LANG="zh_CN.UTF-8"' >/etc/sysconfig/i18n #修改设置
[root@oldboy ~]# . /etc/sysconfig/i18n #执行配置文件
[root@oldboy ~]# cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"
客户端上CRT的字符串配置也要修改
6.历史记录数及登录超时环境变量设置
1设置闲置帐号超时时间
export TMOUT=10
[root@oldboy ~]# export TMOUT=10 #设置超时时间为10秒
[root@oldboy ~]# timed out waiting for input: auto-logout #10秒后超时提示
不过这个配置仅临时生效要想永久生效需要
export TMOUT=10 加入到/etc/profile
[root@oldboy ~]# echo "export TMOUT=10" >> /etc/profile
[root@oldboy ~]# . /etc/profile
[root@oldboy ~]# timed out waiting for input: auto-logout
2 设置LINUX命令行历史记录数
export HISTSIZE=5
[root@oldboy ~]# export HISTSIZE=5 #设置历史记录只记录5个
[root@oldboy ~]# history
529 . /etc/profile
530 echo "export TMOUT=910" >> /etc/profile
531 . /etc/profile
532 export HISTSIZE=5
533 history
不过这个配置仅临时生效要想永久生效需要
export HISTSIZE=5
加入到/etc/profile
[root@oldboy ~]# echo "export HISTSIZE=5" >> /etc/profile
[root@oldboy ~]# . /etc/profile
linux特殊变量
临时生效
export TMOUT=10 连接的时间时间控制变量
export HISTSIZE=5 命令行历史记录数量
export HISTFILESIZE=5 命令行命令对应文件的记录数
永久生效
将上述的命令追加到/etc/profile
[root@oldboy ~]# source /etc/profile #使配置文件生效
或者
[root@oldboy ~]# . /etc/profile
7.隐藏LINUX版本信息
[root@oldboy ~]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel on an m
[root@oldboy ~]# >/etc/issue.net #清空/etc/issue.net 内容
[root@oldboy ~]# > /etc/issue
[root@oldboy ~]# cat /etc/issue.net
网络状态说明及优化命令和优化细节参考资料请看:
http://yangrong.blog.51cto.com/6945369/1321594
老男孩教育的优秀学生博文
http://oldboy.blog.51cto.com/2561410/1336488