系统基础优化--iptables selinux 系统字符集

1.2、系统优化讲解

1.2.1、查看系统环境

   01、查看系统版本

[root@shhaioldboy02-NB ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[root@shhaioldboy02-NB ~]#


   02、查看系统架构信息

[root@shhaioldboy02-NB ~]# uname -m
x86_64
[root@shhaioldboy02-NB ~]#


   03、查看内核信息

[root@shhaioldboy02-NB ~]# uname -r
2.6.32-696.el6.x86_64
[root@shhaioldboy02-NB ~]#


   04uname参数


image.png

1.2.2、基础优化-创建系统管理用户(普通用户)

   用户分类:

      root用户---超级管理员用户-->皇帝

      oldboy用户---普通用户--->平民

   01、创建用户

[root@shhaioldboy02-NB ~]# useradd oldboy
[root@shhaioldboy02-NB ~]#


   02、从用户直接切换到oldboy用户

[root@shhaioldboy02-NB ~]# su - oldboy
[oldboy@shhaioldboy02-NB ~]$


   03、查看当前用户

[oldboy@shhaioldboy02-NB ~]$ whoami 
oldboy
[oldboy@shhaioldboy02-NB ~]$


   04、为普通用户设置密码

   说明:如果用户需要重置密码。需要以root身份执行passwd命令

[root@shhaioldboy02-NB ~]# 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.    #表示密码设置成功
[root@shhaioldboy02-NB ~]#


   06、免交互创建用户密码

[root@shhaioldboy02-NB ~]# useradd oldgirl
[root@shhaioldboy02-NB ~]# echo 123456|passwd --stdin oldgirl
Changing password for user oldgirl.
passwd: all authentication tokens updated successfully.
[root@shhaioldboy02-NB ~]#


  

   07、切换用户说明

image.png

总结:su – 切换用户命令说明

   01root用户   切换   普通用户     不需要密码

   02、普通用户    切换   root用户    需要密码

   03、普通用户    切换   普通用户     需要密码

1.2.3、命令提示符的优化

   知识铺垫

   变量信息  环境变量信息

  

   变量概念实践说明

[root@shhaioldboy02-NB ~]# oldboy=123456
[root@shhaioldboy02-NB ~]# echo $oldboy
123456
[root@shhaioldboy02-NB ~]# oldboy=aaaaaaaaaaaaaaaaa
[root@shhaioldboy02-NB ~]# echo $oldboy
aaaaaaaaaaaaaaaaa
[root@shhaioldboy02-NB ~]#


   环境变量:系统中已经定义好的变量信息,并且系统中已经定义好的变量信息,通常用大写字母表示

01、环境变量 PS1


 image.png

image.png


02、修改PS1 环境变量

   临时修改

[root@shhaioldboy02-NB ~]# echo $PS1
[\u@\h \W]\$
[root@shhaioldboy02-NB ~]# export PS1="[\u@\h \W\A]\$"
[root@shhaioldboy02-NB ~10:50]$export PS1="[\u@\h \W \T]\$"
[root@shhaioldboy02-NB ~ 10:50:47]$
[root@shhaioldboy02-NB ~ 10:51]$export PS1="[\u@\h \W \A]\$ "
[root@shhaioldboy02-NB ~ 10:51]$ 
   永久生效修改方法
[root@shhaioldboy02-NB ~ 10:53]$ echo 'export PS1="[\u@\h \W \A]\$ "' >>/etc/profile
[root@shhaioldboy02-NB ~ 10:53]$ tail -1 /etc/profile
export PS1="[\u@\h \W \A]\$ "
[root@shhaioldboy02-NB ~ 10:53]$ source /etc/profile
[root@shhaioldboy02-NB ~ 10:53]$


   查看系统所有环境变量信息并过滤出命令提示符PS1的变量

[root@shhaioldboy02-NB ~ 10:55]$ set |grep PS1
PS1='[\u@\h \W \A]$ '
[root@shhaioldboy02-NB ~ 10:56]$


1.2.4、系统基础优化---安全服务优化

   1、安全服务软件---selinux(在一定程度上限制root用户权限)

   2、安全服务软件---iptables(网络安全隔离的服务)

      ps:系统初始化使用时,尽量将安全服务关闭

1selinux软件如何关闭

01、临时关闭

   查看此时系统selinux服务状态

[root@shhaioldboy02-NB ~ 11:04]$ getenforce 
Enforcing       #处于开启状态
[root@shhaioldboy02-NB ~ 11:04]$


     

   临时关闭selinux服务

[root@shhaioldboy02-NB ~ 11:18]$ setenforce 
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@shhaioldboy02-NB ~ 11:19]$ setenforce 0
[root@shhaioldboy02-NB ~ 11:19]$ getenforce 
Permissive      #处于临时关闭状态
[root@shhaioldboy02-NB ~ 11:19]$


   查看系统selinux服务配置信息

[root@shhaioldboy02-NB ~ 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 
 
 
[root@shhaioldboy02-NB ~ 11:07]$


02、永久关闭selinux

   修改selinux配置文件

[root@shhaioldboy02-NB ~ 11:17]$ sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@shhaioldboy02-NB ~ 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 
[root@shhaioldboy02-NB ~ 11:18]$


 

其他方法

[root@shhaioldboy02-NB ~ 11:29]$ sed -i.bak '7s#enforcing#disabled#g' /etc/selinux/config
[root@shhaioldboy02-NB ~ 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


2iptables服务如何关闭

01、临时关闭iptables

[root@shhaioldboy02-NB ~ 11:45]$ /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@shhaioldboy02-NB ~ 11:47]$


  

02、查看iptables状态

[root@shhaioldboy02-NB ~ 11:47]$ /etc/init.d/iptables status
iptables: Firewall is not running.
[root@shhaioldboy02-NB ~ 11:48]$


03、永久关闭iptables

   查看iptables服务是否处于开启启动

[root@shhaioldboy02-NB ~ 11:52]$ chkconfig |grep iptables
iptables         0:off   1:off   2:on    3:on    4:on    5:on    6:off
#这里 3:on  表示在开机会自动启动 iptables
[root@shhaioldboy02-NB ~ 11:52]$


  

   关闭iptables开机自动启动

[root@shhaioldboy02-NB ~ 11:52]$ chkconfig iptables off
[root@shhaioldboy02-NB ~ 11:54]$
在检查一下是否关闭开机启动iptables服务
[root@shhaioldboy02-NB ~ 11:54]$ chkconfig |grep iptables
iptables         0:off   1:off   2:off   3:off   4:off   5:off   6:off
#这里 3:on  表示在开机不会启动iptables
[root@shhaioldboy02-NB ~ 11:55]$


1.2.5、系统基础优化---防止系统乱码

01、制造出乱码情况(字符集设定不对)

   修改一个错误的字符集环境变量


[root@shhaioldboy02-NB ~ 12:24]$
[root@shhaioldboy02-NB ~ 12:24]$
[root@shhaioldboy02-NB ~ 12:24]$
查看是否出现乱码
[root@shhaioldboy02-NB ~ 12:25]$ setup



02、避免出现乱码---正确修改字符集

[root@shhaioldboy02-NB ~ 12:28]$ LANG=en_US.UTF-8

[root@shhaioldboy02-NB ~ 12:28]$ echo $LANG

en_US.UTF-8

[root@shhaioldboy02-NB ~ 12:29]$

03、永久修改字符集

   默认字符集配置文件

vim /etc/sysconfig/i18n

修改或添加

LANG="en_US.UTF-8"

保存退出

 

使配置文件生效

source /etc/sysconfig/i18n

检查字符集是否修改正确

[root@shhaioldboy02-NB ~ 12:31]$ echo $LANG

en_US.UTF-8

[root@shhaioldboy02-NB ~ 12:32]$

04、修改中文字符集(不建议设置)

临时修改,系统中文字符集

[root@shhaioldboy02-NB ~ 12:42]$ LANG=zh_CN.UTF-8

[root@shhaioldboy02-NB ~ 12:42]$

 

检查是否设置成功

[root@shhaioldboy02-NB ~ 12:46]$ chkconfig |grep iptables

iptables         0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭

[root@shhaioldboy02-NB ~ 12:47]$

永久修改系统中文字符集

vim /etc/sysconfig/i18n

修改或添加

LANG="zh_CN.UTF-8"

保存退出

 

加载配置

[root@shhaioldboy02-NB ~ 12:47]$ source /etc/sysconfig/i18n

 

检查是否修改成功

[root@shhaioldboy02-NB ~ 12:47]$ chkconfig |grep iptables
iptables         0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
[root@shhaioldboy02-NB ~ 12:47]$
[root@shhaioldboy02-NB ~ 12:47]$ /etc/init.d/iptables status
iptables:未运行防火墙。
[root@shhaioldboy02-NB ~ 12:47]$[object Object]

猜你喜欢

转载自blog.51cto.com/13673885/2140519