Linux系统基础优化(CentOS release 6.7 (Final))
1、关闭SELinux,通过修改配置文件进行修改
SELinux是美国安全局的一种安全访问控制功能。
[root@linux-node1 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#
# 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
将其中的SELINUX参数修改为disable
通过命令行临时关闭SELinux
[root@ linux-node1 ~]# getenforce
Enforcing
[root@ linux-node1 ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@ linux-node1 ~]#
命令说明:
setenforce :用于命令行管理SELinux的级别,后面的数字表示设置对应的级别
getenforce:查看SELinux当前的级别状态
2、设定运行级别为3(多用户模式)
[root@linux-node1 ~]# 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:
命令说明
o 查看Linux**的运行级别**
[root@linux-node1 ~]# runlevel
N 3
o 切换运行级别
[root@linux-node1 ~]# init [数字]
3、关闭防火墙
命令使用说明:
[root@linux-node1 ~]# /etc/init.d/iptables
Usage: iptables {start|stop|reload|restart|condrestart|status|panic|save}
使用stop是临时关闭。如果是要永久关闭防火墙,使用 chkconfig iptables off 。
示例:
[root@linux-node1 ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@linux-node1 ~]# chkconfig iptables off
[root@linux-node1 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@linux-node1 ~]#
4、Linux中文显示设置
[root@linux-node1 ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
a.修改字符集为中文:
echo ‘LANG="en_CN.UTF-8"’ >/etc/sysconfig/i18n
b.查看当前字符集
echo $LANG
[root@linux-node1 ~]# echo $LANG
en_US.UTF-8
c.执行命令使其生效
使用点的方式:. /etc/sysconfig/i18n
使用source的方式: source /etc/sysconfig/i18n
5、设置闲置账号的超时时间
使用export修改: export TMOUT=10 单位为秒(s)
6、历史记录命令history
清空所有的历史纪录
[root@linux-node1 ~]# history -c
[root@linux-node1 ~]# history
1 history
清空某一条历史纪录
[root@linux-node1 ~]# history –d [待清空的命令数字]
调整history记录数
使用export命令:export HISTSIZE=5 命令行历史记录数量
通过修改文件的方式:export HISTFILESIZE=5 cat ~/.bash_history 命令行对应文件的历史数量(一般设置为10~20个比较好)
涉及到的系统中的变量为
TMOUT 闲置用户连接超时时间
HISTSIZE 命令的历史记录的长度
HISTFILESIZE 命令对应文件的历史记录的长度
如果,需要使得上述的命令在系统中永久生效
a.将需要执行的命令写入到/etc/profile文件中
echo ‘export TMOUT=10’ >>/etc/profile
echo ‘export HISTSIZE=10’ >>/etc/profile
echo ‘export HISTFILESIZE=10’ >>/etc/profile
b.使配置文件生效
source /etc/profile
7、隐藏Linux版本信息
查看Linux版本和内核信息
[root@linux-node1 ~]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
[root@linux-node1 ~]# cat /etc/issue.net
CentOS release 6.7 (Final)
Kernel \r on an \m
清空/etc/issue.net文件中的信息
>/etc/issue
>