9.28 linux系统基础优化

  • 关闭SELinux(是美国安全局对强制访问的实现)功能
[root@wen ~]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config            #使用sed + i 命令修改
[root@wen ~]# grep "SELINUX=disabled" /etc/selinux/config                                    #grep查看
SELINUX=disabled
[root@wen ~]# cat /etc/selinux/config

# 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@wen ~]# getenforce
Enforcing
[root@wen ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@wen ~]# setenforce 0
[root@wen ~]# getenforce
Permissive
  • 运行级别
9.28 linux系统基础优化9.28 linux系统基础优化
[root@wen ~]# 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:

[root@wen ~]# grep 3:initdefault /etc/inittab          #调整运行级别,默认3,可以调成其他
id:3:initdefault:
[root@wen ~]# runlevel                #查看当前级别
N 3
[root@wen ~]# init 0                   #切换运行级别
View Code
  • 关机
shutdown(halt) init0
参数
-r reboot after shutdown
-h halt or power off after shutdown       

shutdown -h 10    #10分钟后关闭
shutdown now     #马上
poweroff                #关闭电源


*关闭防火墙
[root@wen ~]# /etc/init.d/iptables stop                     #临时关闭
iptables:将链设置为政策 ACCEPT:filter             [确定]
iptables:清除防火墙规则:                                [确定]
iptables:正在卸载模块:                                   [确定]
[root@wen ~]# /etc/init.d/iptables status                   #查看状态
iptables:未运行防火墙。
[root@wen ~]# /etc/init.d/iptables restart                  # 重启防火墙           
iptables:应用防火墙规则:                                [确定]
[root@wen ~]# chkconfig iptables off                         #开机也不启动了
  • linux中文显示设置等
*中文显示设置
[root@wen ~]# echo ‘LANG="zh_CN.UTF-8“‘ > /etc/sysconfig/i18n
[root@wen ~]# cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8“
[root@wen ~]# echo $LANG
zh_CN.UTF-8
同时调整ssh客户端

*设置账号超时时间
[root@wen ~]# export TMOUT=5      #5秒后关机  (临时生效)
[root@wen ~]# timed out waiting for input: auto-logout

*设置命令行历史记录
[root@wen ~]# history -c         #清除所有历史记录
[root@wen ~]# history             #查看历史记录
    1  history
[root@wen ~]# echo  1
1
[root@wen ~]# echo  2
2
[root@wen ~]# echo  3
3
[root@wen ~]# echo  4
4
[root@wen ~]# echo  5
5
[root@wen ~]# history -d 3        #删除指定行记录
[root@wen ~]# history
    1  history
    2  echo  1
    3  echo  3
    4  echo  4
    5  echo  5
    6  history -d 3
    7  history
[root@wen ~]# !6                 #执行某行历史命令      
history -d 3

[root@wen ~]# export HISTSIZE=5        #控制历史记录记录数量(临时生效)#永久生效放在/etc/profile文件下,然后source以下/etc/profile
[root@wen ~]# history
    5  history
    6  echo
    7  history -d 3
    8  export HISTSIZE=5
    9  history
[root@wen ~]# cat ~/.bash_history         #即使控制了在根目录下还有
[root@wen ~]# export HISTORYSIZE=5    #命令行命令对应文件的记录数

*隐藏版本信息
[root@wen ~]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m

[root@wen ~]# > /etc/issue
[root@wen ~]# cat /etc/issue.net
CentOS release 6.7 (Final)
Kernel \r on an \m
[root@wen ~]# >/etc/issue.net
[root@wen ~]# cat /etc/issue
[root@wen ~]#

?

?
?

9.28 linux系统基础优化

上一篇:静心思考 8条秘诀助你成为个性实力摄影师详情介绍


下一篇:Photoshop将外景婚片调制出唯美秋季色调效果