NO13 Linux的基础优化-关闭SELinux功能-Linux的7种运行级别-防火墙设置-中文显示设置

2023-07-29,,

壹  安装Linux系统后调优及安全设置

1 关闭SELinux功能:

[root@localhost data]# sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config  (先用sed命令修改输出内容,再加-i修改文件内容,生产环境中也是要这样操作的)

# 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 three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost data]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config    (确认改输出成功后,再加-i执行改文件内容)
[root@localhost data]# grep "SELINUX=disabled" /etc/selinux/config       (再用grep命令检测一下)
SELINUX=disabled

*以上只是修改配置文件,还需重启才能生效,但生产环境是不允许服务器重启的,影响客户访问,这时就需要另一个命令。

 [root@localhost data]# getenforce   (查看SElinux状态的)
Enforcing
[root@localhost data]# setenforce (设置状态)
usage: setenforce [ Enforcing | Permissive | | ] (Enforcing是1 ,Permissive是0的意思)
[root@localhost data]# setenforce
[root@localhost data]# getenforce
Permissive

·这样作:重启前是Permissive,但之前配置文件是改成disabled,一旦重启就是disabled,但因是实际不允许重启,所以配置文件和命令行都改,而disabled和Permissive都是不影响的状态。

贰:Linux的7种运行级别,及对应作用。

·企业场景面试题:Linux的7种运行级别,及对应作用。(要牢记)
·企业场景面试题:要把Linux的运营级别从3改成5,要修改哪个文件?
答案:/etc/inittab

Default runlevel.The runlevels used are:
-halt(Do NOT set initdefault to this)      关机。
-Single user mode          单用户状态,需要维护服务器时用,比如密码丢失。
-Multiuser,without NFS(The same as 3,if you not have networking)   多用户模式。
-Full multiuser mode      完整多用户模式,命令行模式.工作环境一般用3级别。
-unused     没有使用,保留的。
-Xll        带桌面的模式。
-reboot (Do NOT set initdefault to this)   重启。

查看当前Linux运行模式:
[root@localhost ~]# runlevel
N 5
运行级别是可以切换的:
[root@localhost ~]# init 输入数字0-6,就切换到你要的模式。

·runlevel:查看当前系统运行级别。
·init:切换运行级别,后面接对应级别的数字,例如init 6就是重启linux服务器。

叁:关机重启命令和防火墙设置:

· shutdown   #关机。 halt,init0 也是关机的命令。
               关机:shutdown -h now(或指定时间)。
· rboot      #重启。init6也是重启。
               重启:shutdowm -r now

关闭防火墙命令:[root@localhost ~]# /etc/init.d/iptables stop   临时关闭
永久关闭防火墙:[root@localhost ~]# chkconfig iptables off      下次开机也不会自动启动。
查看防火墙命令:[root@localhost ~]# /etc/init.d/iptables status

CentOS 7默认使用的是firewall作为防火墙
# service firewalld status; #查看防火墙状态
(disabled 表明 已经禁止开启启动 enable 表示开机自启,inactive 表示防火墙关闭状态 activated(running)表示为开启状态)
# service firewalld start;  或者 #systemctl start firewalld.service;#开启防火墙
# service firewalld stop;  或者 #systemctl stop firewalld.service;#关闭防火墙
# service firewalld restart;  或者 #systemctl restart firewalld.service;  #重启防火墙
# systemctl disable firewalld.service#禁止防火墙开启自启

# systemctl enable firewalld#设置防火墙开机启动
#yum remove firewalld#卸载firewall

肆  Linux中文显示设置:
此项优化为可选项,即调整Linux系统的字符集设置。
字符集就是一套文字符号及其编码。目前Linux下常用的字符集有:
·GBKL:定长,双字节,不是国际标准,支持的系统不少,实际企业用的不多。
·UTF-8:非定长,1-4字节,广泛支持,MYSQL也使用UTF-8,企业广泛使用。

在CentOS 7以前的版本下,默认的字符集的路径一般保存在/etc/sysconfig/i18n文件中。
但是在CentOS 7版本中,字符集配置文件位于/etc/locale.conf。

下面演示在Centos7中使Linux中文显示:

 [root@localhost ~]# cat /etc/locale.conf  (查看字符集配置文件)
LANG="en_US.UTF-8"
[root@localhost ~]# cp //etc/locale.conf /etc/locale.conf.ori (最好备份)
[root@localhost ~]# echo 'LANG="zh_CN.UTF-8"' >/etc/locale.conf (使用echo命令追加输出,替换内容)
[root@localhost ~]# cat /etc/locale.conf (查看字符集配置文件)
LANG="zh_CN.UTF-8"
[root@localhost ~]# echo $LANG (查看字符集配置文件)
en_US.UTF-
[root@localhost ~]# . /etc/locale.conf (还需要使用. 或者source命令使修改生效)
[root@localhost ~]# echo $LANG (查看变量$LANG)
zh_CN.UTF-
[root@localhost ~]# source /etc/locale.conf
[root@localhost ~]# echo $LANG
zh_CN.UTF-

最后还要再此虚拟机的属性-外观里把字符编码改成UTF-8,重新连接,这样使服务器端和客户端对应,就确保对话字符一致。

 [root@localhost ~]# echo $LANG
zh_CN.UTF-
[root@localhost ~]# cat /etc/locale.conf
LANG="zh_CN.UTF-8"
[root@localhost ~]# touch 老男孩。txt
[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg oldboy.txt 老男孩。txt
[root@localhost ~]#

注意:不要在Linux系统里使用任何中文信息。

伍  设置闲置账号超时时间的命令,仅临时生效:
[root@localhost ~]#  export TMOUT=5
[root@localhost ~]# timed out waiting for input: auto-logout

陆  清空所有历史命令:
[root@localhost ~]# history -c
删除指定的一个命令:
[root@localhost ~]# history -d 数字(要删的那一行的数字)

[root@localhost ~]# export HISTSIZE=5设置命令行记录显示数
[root@localhost ~]# cat ~/.bash_bash_history (但还是可以从命令行文件看到所有历史命令)
[root@localhost ~]# export HISTFILESIZE=5 (设置命令行文件历史记录数量)

history    #查看及清理历史记录。-c 清空所有,-d删除指定历史记录。

     export HISTORY=    命令行历史记录数量。(Linux特殊变量)。
export HISTFILESIZE= 命令行文件历史记录数量。
cat ~/.bash_bash_history 查看命令行文件历史记录

把上述命令放入配置文件,使其可以永久生效:

 [root@localhost ~]# echo 'export TMOUT=300' >>/etc/profile
[root@localhost ~]# echo 'export HISTSIZE=5' >>/etc/profile
[root@localhost ~]# echo 'export HISTFILESIZE=5' >>/etc/profile
[root@localhost ~]# tail - /etc/profile
export TMOUT=
export HISTSIZE=
export HISTFILESIZE=
[root@localhost ~]# source /etc/profile (使配置文件生效)

柒   隐藏Linux版本信息显示:

 [root@localhost ~]# cat /etc/issue  查看版本信息
\S
Kernel \r on an \m
[root@localhost ~]# cat /etc/issue.net
\S
Kernel \r on an \m
[root@localhost ~]# > /etc/issue 用>把信息清掉
[root@localhost ~]# > /etc/issue。net

NO13 Linux的基础优化-关闭SELinux功能-Linux的7种运行级别-防火墙设置-中文显示设置的相关教程结束。

《NO13 Linux的基础优化-关闭SELinux功能-Linux的7种运行级别-防火墙设置-中文显示设置.doc》

下载本文的Word格式文档,以方便收藏与打印。