1.2、系统优化讲解
1.2.1、查看系统环境
01、查看系统版本
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [[email protected] ~]#
02、查看系统架构信息
[[email protected] ~]# uname -m x86_64 [[email protected] ~]#
03、查看内核信息
[[email protected] ~]# uname -r 2.6.32-696.el6.x86_64 [[email protected] ~]#
04、uname参数
1.2.2、基础优化-创建系统管理用户(普通用户)
用户分类:
root用户---超级管理员用户-->皇帝
oldboy用户---普通用户--->平民
01、创建用户
[[email protected] ~]# useradd oldboy [[email protected] ~]#
02、从用户直接切换到oldboy用户
[[email protected] ~]# su - oldboy [[email protected] ~]$
03、查看当前用户
[[email protected] ~]$ whoami oldboy [[email protected] ~]$
04、为普通用户设置密码
说明:如果用户需要重置密码。需要以root身份执行passwd命令
[[email protected] ~]# passwd oldboy Changing password for user oldboy. New password: BAD PASSWORD: it is too simplistic/systematic #这里两行都是提示密码太简单 BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully. #表示密码设置成功 [[email protected] ~]#
06、免交互创建用户密码
[[email protected] ~]# useradd oldgirl [[email protected] ~]# echo 123456|passwd --stdin oldgirl Changing password for user oldgirl. passwd: all authentication tokens updated successfully. [[email protected] ~]#
07、切换用户说明
总结:su – 切换用户命令说明
01、root用户 切换 普通用户 不需要密码
02、普通用户 切换 root用户 需要密码
03、普通用户 切换 普通用户 需要密码
1.2.3、命令提示符的优化
知识铺垫
变量信息 环境变量信息
变量概念实践说明
[[email protected] ~]# oldboy=123456 [[email protected] ~]# echo $oldboy 123456 [[email protected] ~]# oldboy=aaaaaaaaaaaaaaaaa [[email protected] ~]# echo $oldboy aaaaaaaaaaaaaaaaa [[email protected] ~]#
环境变量:系统中已经定义好的变量信息,并且系统中已经定义好的变量信息,通常用大写字母表示
01、环境变量 PS1
02、修改PS1 环境变量
临时修改
[[email protected] ~]# echo $PS1 [\[email protected]\h \W]\$ [[email protected] ~]# export PS1="[\[email protected]\h \W\A]\$" [[email protected] ~10:50]$export PS1="[\[email protected]\h \W \T]\$" [[email protected] ~ 10:50:47]$ [[email protected] ~ 10:51]$export PS1="[\[email protected]\h \W \A]\$ " [[email protected] ~ 10:51]$ 永久生效修改方法 [[email protected] ~ 10:53]$ echo 'export PS1="[\[email protected]\h \W \A]\$ "' >>/etc/profile [[email protected] ~ 10:53]$ tail -1 /etc/profile export PS1="[\[email protected]\h \W \A]\$ " [[email protected] ~ 10:53]$ source /etc/profile [[email protected] ~ 10:53]$
查看系统所有环境变量信息并过滤出命令提示符PS1的变量
[[email protected] ~ 10:55]$ set |grep PS1 PS1='[\[email protected]\h \W \A]$ ' [[email protected] ~ 10:56]$
1.2.4、系统基础优化---安全服务优化
1、安全服务软件---selinux(在一定程度上限制root用户权限)
2、安全服务软件---iptables(网络安全隔离的服务)
ps:系统初始化使用时,尽量将安全服务关闭
1、selinux软件如何关闭
01、临时关闭
查看此时系统selinux服务状态
[[email protected] ~ 11:04]$ getenforce Enforcing #处于开启状态 [[email protected] ~ 11:04]$
临时关闭selinux服务
[[email protected] ~ 11:18]$ setenforce usage: setenforce [ Enforcing | Permissive | 1 | 0 ] [[email protected] ~ 11:19]$ setenforce 0 [[email protected] ~ 11:19]$ getenforce Permissive #处于临时关闭状态 [[email protected] ~ 11:19]$
查看系统selinux服务配置信息
[[email protected] ~ 11:07]$ 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. #selinux服务处于开启状态 # permissive - SELinux prints warnings instead of enforcing. #selinux临时关闭状态,还会有安全告警提示信息 # disabled - No SELinux policy is loaded. #selinux彻底关闭状态 SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted [[email protected] ~ 11:07]$
02、永久关闭selinux
修改selinux配置文件
[[email protected] ~ 11:17]$ sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config [[email protected] ~ 11:17]$ grep SELINUX /etc/selinux/config # SELINUX= can take one of these three values: SELINUX=disabled # SELINUXTYPE= can take one of these two values: SELINUXTYPE=targeted [[email protected] ~ 11:18]$
其他方法
[[email protected] ~ 11:29]$ sed -i.bak '7s#enforcing#disabled#g' /etc/selinux/config [[email protected] ~ 11:29]$
03、临时关闭与永久关闭一起
setenforce 0 sed -i.bak '7s#enforcing#disabled#g' /etc/selinux/config sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
2、iptables服务如何关闭
01、临时关闭iptables
[[email protected] ~ 11:45]$ /etc/init.d/iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [[email protected] ~ 11:47]$
02、查看iptables状态
[[email protected] ~ 11:47]$ /etc/init.d/iptables status iptables: Firewall is not running. [[email protected] ~ 11:48]$
03、永久关闭iptables
查看iptables服务是否处于开启启动
[[email protected] ~ 11:52]$ chkconfig |grep iptables iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off #这里 3:on 表示在开机会自动启动 iptables [[email protected] ~ 11:52]$
关闭iptables开机自动启动
[[email protected] ~ 11:52]$ chkconfig iptables off [[email protected] ~ 11:54]$ 在检查一下是否关闭开机启动iptables服务 [[email protected] ~ 11:54]$ chkconfig |grep iptables iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off #这里 3:on 表示在开机不会启动iptables [[email protected] ~ 11:55]$
1.2.5、系统基础优化---防止系统乱码
01、制造出乱码情况(字符集设定不对)
修改一个错误的字符集环境变量
[[email protected] ~ 12:24]$ [[email protected] ~ 12:24]$ [[email protected] ~ 12:24]$ 查看是否出现乱码 [[email protected] ~ 12:25]$ setup
02、避免出现乱码---正确修改字符集
[[email protected] ~ 12:28]$ LANG=en_US.UTF-8
[[email protected] ~ 12:28]$ echo $LANG
en_US.UTF-8
[[email protected] ~ 12:29]$
03、永久修改字符集
默认字符集配置文件
vim /etc/sysconfig/i18n
修改或添加
LANG="en_US.UTF-8"
保存退出
使配置文件生效
source /etc/sysconfig/i18n
检查字符集是否修改正确
[[email protected] ~ 12:31]$ echo $LANG
en_US.UTF-8
[[email protected] ~ 12:32]$
04、修改中文字符集(不建议设置)
临时修改,系统中文字符集
[[email protected] ~ 12:42]$ LANG=zh_CN.UTF-8
[[email protected] ~ 12:42]$
检查是否设置成功
[[email protected] ~ 12:46]$ chkconfig |grep iptables
iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[[email protected] ~ 12:47]$
永久修改系统中文字符集
vim /etc/sysconfig/i18n
修改或添加
LANG="zh_CN.UTF-8"
保存退出
加载配置
[[email protected] ~ 12:47]$ source /etc/sysconfig/i18n
检查是否修改成功
[[email protected] ~ 12:47]$ chkconfig |grep iptables iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 [[email protected] ~ 12:47]$ [[email protected] ~ 12:47]$ /etc/init.d/iptables status iptables:未运行防火墙。 [[email protected] ~ 12:47]$[object Object]
原文地址:http://blog.51cto.com/13673885/2140519