RHEL8系统配置优化

本文介绍了Docker容器的--restart参数及其不同策略,包括no、on-failure、on-failure:3、always和unless-stopped。详细阐述了如何设置容器为自启动以及如何取消自启动,并提供了相应的命令示例。建议使用--restart=always以确保容器在退出时自动重启。此外,还提供了链接以便进一步学习Docker。

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

配置主机名

# 配置主机名
hostnamectl set-hostname el8

配置locale.conf

https://blog.csdn.net/omaidb/article/details/131728293

https://blog.csdn.net/omaidb/article/details/120104853

vi /etc/locale.conf

配置内容如下

# 覆盖系统所有语言设置
LC_ALL=zh_CN.UTF-8
# 设置默认语言
LANG=zh_CN.uft8

配置yum国内源

参考: https://gitcode.com/liqiaofei/centos7_yum_repo

# 备份yum源
mv /etc/yum.repos.d{,.bak} && mkdir -p /etc/yum.repos.d && cd /etc/yum.repos.d

# 下载CentOS-Base.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-Base.repo

# 下载elrepo.repo
curl -o /etc/yum.repos.d/elrepo.repo https://raw.gitcode.com/liqiaofei/centos7_yum_repo/raw/main/el8-el9/elrepo.repo

# 下载epel.repo
curl -o /etc/yum.repos.d/epel.repo https://raw.gitcode.com/liqiaofei/centos7_yum_repo/raw/main/el8-el9/epel.repo

# 下载CentOS-SCLo-scl-rh.repo
curl -o /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-SCLo-scl-rh.repo

# 下载CentOS-SCLo-scl.repo
curl -o /etc/yum.repos.d/CentOS-SCLo-scl.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/CentOS-SCLo-scl.repo

# 下载ius.repo
curl -o /etc/yum.repos.d/ius.repo https://raw.gitcode.com/liqiaofei/Linux_software_sources/raw/main/Centos7/ius.repo

安装常用软件

# 安装dnf插件
dnf install -y dnf-utils dnf-plugin-versionlock

# 安装常用软件
dnf install -y bash-completion mlocate rsync vim wget net-tools

关闭防火墙和SELinux

# 关闭防火墙
systemctl disable --now firewalld

# 关闭selinux
sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config

# 临时关闭SELinux
setenforce 0

性能调优

  • 配置tuned自动性能调优
  • 关闭不必要服务

美化系统


vim美化

# 下载vim配置文件
wget -cP $HOME/ https://raw.gitcode.com/liqiaofei/vim-config/raw/main/.vimrc

美化cat

https://blog.csdn.net/omaidb/article/details/146552972


美化ps1

# 下载ps1优化配置文件
wget -cP /etc/profile.d https://raw.gitcode.com/liqiaofei/profile.d/raw/main/ps1.sh

配置git命令自动补全

# 下载git-completion.sh
wget -cP /etc/profile.d/ https://raw.github.com/git/git/master/contrib/completion/git-completion.bash

配置系统欢迎语

/etc/issue/etc/motd区别

特性/etc/issue/etc/motd (Message Of The Day)
显示时机登录前(在登录提示符上方显示)登录后(用户成功登录后显示)
主要用途显示系统标识、警告或登录前的法律声明显示动态系统消息、维护通知或欢迎信息
内容更新通常为静态文本支持动态生成(通过脚本或 /etc/motd.d/>)
典型应用场景法律声明、SSH登录前的安全警告系统状态、维护通知、每日提示
修改方式直接编辑文件可编辑文件或通过 /etc/motd.d/ 分片管理

配置/etc/issue.net登陆前欢迎语

tee /etc/issue.net <<-'EOF'
【法律警告】
本系统仅供授权人员访问。所有登录尝试和系统内的操作行为都将被实时监控、记录和审计。未经授权的访问、使用、修改或传播系统信息属于非法行为,将承担严厉的法律责任,包括但不限于民事赔偿、行政处罚乃至刑事起诉。继续登录表示您已阅读、理解并同意接受上述条款和相关信息安全策略的约束。
EOF

修改sshd配置

# 使用sed命令修改SSH配置文件中的Banner设置(需管理员权限)
# sed -i:直接修改目标文件(不生成备份)
# - 's/^#\s*Banner\s*none/Banner \/etc\/issue.net/g':正则表达式替换规则
#   分解:
#     ^#\s*        : 匹配以#开头且后面有任意空格的注释行
#     Banner\s*    : 匹配Banner关键字及后面任意空格
#     none         : 匹配原始配置的"none"参数
#     Banner \/etc\/issue.net : 替换为指定路径的banner文件(转义斜杠)
#     g            : 全局替换(防止重复配置项)
# - /etc/ssh/sshd_config:SSH服务主配置文件路径
sudo sed -i 's/^#\s*Banner\s*none/Banner \/etc\/issue.net/g' /etc/ssh/sshd_config

查看Banner配置

grep Banner /etc/ssh/sshd_config

# 重启sshd服务
systemctl restart sshd

配置/etc/motd登陆后欢迎语

tee /etc/motd.d/00-welcome <<-'EOF'
【法律警告】
本系统仅供授权人员访问。所有登录尝试和系统内的操作行为都将被实时监控、记录和审计。未经授权的访问、使用、修改或传播系统信息属于非法行为,将承担严厉的法律责任,包括但不限于民事赔偿、行政处罚乃至刑事起诉。继续登录表示您已阅读、理解并同意接受上述条款和相关信息安全策略的约束。
EOF

安全配置


使用fail2ban防止ssh穷举爆破 :

https://blog.csdn.net/omaidb/article/details/120231345


配置ipset

配置IP白名单IP黑名单
https://blog.csdn.net/omaidb/article/details/120405741


rm删除到回收站

https://blog.csdn.net/omaidb/article/details/148346377


Linux服务器防止误关机

https://blog.csdn.net/omaidb/article/details/148352044

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

教Linux的李老师

赞赏是第一生产力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值