线上Linux服务器基础优化

1、如何最小化安装系统
仅安装需要的,按需安装、不用不装,必须安装的有开发包、基本网络包、基本应用包。
2、ssh登录系统策略
vim /etc/ssh/sshd_config
#SSH链接默认端口,修改默认22端口为1万以上端口号,避免被扫描和攻击。
Port 22221
#不使用DNS反查,可提高ssh连接速度
UseDNS no
#关闭GSSAPI验证,可提高ssh连接速度
GSSAPIAuthentication no
#禁止root账号登陆
PermitRootLogin no

当然在那个/etc/ssh/sshd_config.d/下也可以写想写的文件,比如echo “PermitRootLogin yes” > /etc/ssh/sshd_config.d/01-permitrootlogin.conf

3、selinux, iptables策略设置
[root@localhost ~]# cat /etc/selinux/config
Selinux的状态:
enforcing 开启状态、permissive 提醒的状态 、disabled 关闭状态
命令行关闭:setenforce 0(临时生效)
[root@localhost ~]# grubby –update-kernel ALL –args selinux=0 (永久生效)
[root@localhost ~]# iptables -L -n
4、更新yum源及必要软件安装
常用的几个yum源
阿里云centos源:https://mirrors.aliyun.com/centos/、https://mirrors.aliyun.com/centos-vault/
阿里云rockylinux源: https://mirrors.aliyun.com/rockylinux/
[root@localhost ~]# yum update #更新系统所以软件和内核

RockyLinux9的镜像源更换阿里云方法:
[root@localhost ~]# sed -e ‘s|^mirrorlist=|#mirrorlist=|g’ \
-e ‘s|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g’ \
-i.bak \
/etc/yum.repos.d/rocky*.repo ######最好是去官方网站看一下最好

5、定时自动更新服务器时间
阿里云时间服务器:ntp1.aliyun.com、ntp2.aliyun.com
Centos7版本:
/usr/sbin/ntpdate ntp1.aliyun.com >> /var/log/ntp.log 2>&1; /sbin/hwclock -w
rockylinux9/almalinux9版本:
配置chronyc时间同步:
[root@localhost ~]# yum install chrony
[root@localhost ~]# systemctl start chronyd
[root@localhost ~]# systemctl enable chronyd
[root@localhost ~]# chronyc sources -v
[root@localhost ~]# chronyc -a makestep

6、重要文件加锁
chattr +i /etc/sudoers
chattr +i /etc/shadow
chattr +i /etc/passwd
chattr +i /etc/grub2.conf

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注