Linux服务部署之安装Lixux系统后调优以及安全设置
文章目录
前言
服务环境:CentOS Linux release 7.9.2009 (Core)
一、关闭SElinux功能
selinux(security enhanced linux)安全增强型linux系统,它是一个linux内核模块,也是linux的一个安全子系统。
selinux的主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)
- 首先查看下selinux的状态,命令:getenforce
- 查看selinux的配置文件,命令: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
- 把SELINUX=enforced改为SELINUX=disabled
vi /etc/selinux/config
- 重启服务,配置才能生效。
也可以通过命令:setenforce 0,不需要重启临时关闭SELinux服务。
二、Linux设定运行级别
1、linux的7种运行级别
运行级别 | 权限 |
---|---|
运行级别0 | 系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 |
运行级别1 | 单用户工作状态,root权限,用于系统维护,禁止远程登陆 |
运行级别2 | 多用户状态(没有NFS) |
运行级别3 | 完全的多用户状态(有NFS),登陆后进入控制台命令行模式 |
运行级别4 | 系统未使用,保留 |
运行级别5 | X11控制台,登陆后进入图形GUI模式 |
运行级别6 | 系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动 |
2、查看以及变更运行级别
runlevel <==查看运行级别
init 5 <==切换运行级别为5
三、linux可从开机到登录之前的启动流程
1.开机BIOS自检
2.MBR引导
3.grub引导菜单
4.加载内核kernel
5.启动init进程
6.读取inittab文件,执行rc.sysinit,rc等脚本
7.启动mingetty,进入系统登陆界面
四、设置字符集
CentOS7.9环境下:
[root@root ~]# echo $LANG
zh_CN.UTF-8
[root@root ~]# cat /etc/locale.conf
LANG=“zh_CN.UTF-8”
[root@root ~]# cp /etc/locale.conf /etc/locale.conf.ori
[root@root ~]# echo ‘LANG=EN’>/etc/locale.conf
[root@root ~]# echo $LANG
zh_CN.UTF-8
[root@root ~]# ./etc/locale.conf
-bash: ./etc/locale.conf: 没有那个文件或目录
[root@root ~]# ./etc/locale.conf
-bash: ./etc/locale.conf: 没有那个文件或目录
[root@root ~]# . /etc/local.conf
-bash: /etc/local.conf: 没有那个文件或目录
[root@root ~]# . /etc/locale.conf
[root@root ~]# echo $LANG
EN
[root@root ~]#
更改好后,需要. /etc/locale.conf,执行完成配置重新更新"."和“/”中间两个空格,否则报错。
五、关闭iptables防火墙
一般只有配置外网的服务器才需要开启防火墙,高并发,高流量的业务服务器仍然不能开启,因为一旦开启后会有较大性能损坏,导致网络访问特别慢,这种情况只能在更前段加硬件防火墙。
systemctl stop firewalld.service <==关闭防火墙
systemctl start firewalld.service <==开启防火墙
systemctl status firewalld.service <==查看防火墙状态
六、Linux系统安全最小化原则
- 安装Linux系统最小化,即选包最小化,yum安装软件包最小化,无用的包不安装;
- 开启自动启动服务最小化,即无用的无法不启动;
- 操作命令最小化。例如能使用“rm -f xxx.txt”, 不适用"rm -rf xxx.txt”;
- 登录用户最小化,即能不用root,就用普通用户权限;
- 普通用户权限最小化。只给必要的权限。
- 程序服务运行最小化。即服务尽量不用root用户启用;