基础优化(linux)

本文介绍了对安装了CentOS系统的服务器进行基础优化的方法,包括关闭SElinux、精简开机启动项、关闭防火墙、最小化安装、调整SSH服务配置、控制sudo用户权限、设置时间同步、增加文件描述符限制和禁止ping响应等措施,旨在提高系统性能和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装CenTos系统后,给服务器进行基础优化:

关闭SElinux

SElinux是美国国家安全局NSA对于强制访问控制的实现

[root@192 ~]# vim /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@192 ~]# sed -i 's#STLINUX=.*#SELINUX=disabled#g' /etc/selinux/config 
[root@192 ~]# setenforce 0
[root@192 ~]# 


精简开机系统启动

linux服务器在运行过程中,会有很多默认的服务在运行,而且这些服务通常是没用,这些服务占用了系统资源,存在安全隐患,关闭这些没用的服务
重要的服务,需要开启:

1) sshd
远程连接服务,需要开启,要不然无法连接linux。
2) rsyslog
是操作系统中提供的一种机制,系统的守护程序通常会使用rsyslog 将各种信息写到系统日志文件中,
3) . network
系统启动时,若想关闭或者激活各个网络接口,就必须启动该服务

4) cron
一次性计划任务: at
周期计划任务: crontab

5) sysstat
该服务包括监控系统性能及效率的一组工具。这些工具对于收集系统的性能数据很有帮助:核心工具包:
iostat : cpu使用率及硬盘吞吐效率工具
mpstat:提供单个或者多个处理器的数据
sar 负责收集,报告并存储系统活跃的信息

关闭防火墙

[root@192 ~]# iptables -F
[root@192 ~]# /etc/init.d/iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
[root@192 ~]# chkconfig iptables off
[root@192 ~]# service iptables stop
[root@192 ~]# 

最小化原则安装

1 )linux系统最小化安装,最选包最小化,yum安装软件包也要最小化,没用的包不安装。
2) 操作系统命令最小化
登录linux用户量最小化,不要使用root,使用普通用户即可
4) 普通授权最小化,即只给必须的管理系统的命令
5)linux系统文件及目录权限设置最小化,禁止随便修改,更改,删除。

更改ssh服务端远程登录的配置

1) 端口不要使用22
2) UseDNS no 是否使用DNS,设置为no之后登录速度会快
3)#PermitRootLogin no 设置不允许root登录
4)GSSAPIAuthentication no 解决ssh链接慢的问题
5) PasswordAuthentication yes 密码验证是必须的,默认yes
PermitEmptyPasswords no 空密码是否允许登录
7)#LoginGraceTime 2m 当使用者连接上ssh server的时候,会出现输入密码的画面,在这个画面中,多久没有成功连接上就强迫断线

[root@192 ~]# service sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]

[root@192 ~]# ssh 192.168.148.156 root@192.168.148.156 password:123456
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
root@192.168.148.156's password: 
bash: root@192.168.148.156: command not found
[root@192 ~]# 

8) #PrintMotd yes //登入后是否显示一些信息,比如上次登录时间,地点。

[root@192 ~]# ssh 192.168.148.156
The authenticity of host '192.168.148.156 (192.168.148.156)' can't be established.
RSA key fingerprint is f0:2c:f5:f3:70:a4:45:b0:e9:bb:9f:ea:fc:76:02:d7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.148.156' (RSA) to the list of known hosts.
Nasty PTR record "192.168.148.156" is set up for 192.168.148.156, ignoring
root@192.168.148.156's password: 
Last login: Fri Mar 13 11:00:47 2020 from 192.168.148.1
[root@192 ~]# 

sudo控制用户对系统命令的最小化

设置Linux服务器的时间同步

[root@192 ~]# echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@192 ~]# 

关于ntp服务

加大服务器文件描述符

[root@192 ~]# vim /etc/security/limits.conf 
[root@192 ~]# ulimit -n
1024
[root@192 ~]# 

禁止 ping

[root@192 ~]# echo 'net.ipv4.icmp_echo_ignore_all = 1' >>/etc/sysctl.conf
[root@192 ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.icmp_echo_ignore_all = 1
[root@192 ~]# 

等等…
https://blog.youkuaiyun.com/xinshuzhan/article/details/104694546
https://blog.youkuaiyun.com/fanren224/article/details/79971359

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值