APP下载

最小化安装CentOS 7.6后的优化

消息来源:baojiabao.com 作者: 发布时间:2026-05-20

报价宝综合消息最小化安装CentOS 7.6后的优化

俗话说的好“工欲善其事,必先利其器”,相信程式猿和运维人员深有体会。不论从事什么工作,能有一套优秀的工具,对我们的工作更能事半功倍,下面来介绍最小化安装CentOS 7.6后的优化;

1. 系统核心版本[[email protected] ~]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

[[email protected] ~]# uname -r

3.10.0-957.5.1.el7.x86_64

2. 关闭防火墙[[email protected] ~]# systemctl stop firewalld

[[email protected] ~]# systemctl disable firewalld

3. 关闭SELinux[[email protected] ~]# vim /etc/selinx/config

SELINUX=enforcing #修改此行为disabled

修改后

SELINUX=disabled

[[email protected] ~]# setenforce 0 #临时关闭SELinux,不需要重启即可生效

4. 配置网络[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33

修改ONBOOT=no为ONBOOT=yes重启网络生效

[[email protected] ~]# systemctl restart network.service

5. 修改主机名通过hostnamectl set-hostname [HOSTNAME]可以直接永久修改主机名,相当于直接修改/etc/hostname档案,不需要重启服务器,需要退出终端,重新登入即可生效;而hostname其实主机名定义包括三种:静态的(Static hostname)、瞬态的(Tansient hostname)、灵活的(Pretty hostname),分别使用--static,--transient

或--pretty选项来检视主机名;[[email protected] ~]# hostnamectl set-hostname node01 #退出重新登入生效

[[email protected] ~]# hostnamectl #或者使用hostnamectl status 检视三种主机名

Static hostname: node-01

Icon name: computer-vm

Chassis: vm

Machine ID:64592dadfdff47789bd029c4d2d2dcc9

Boot ID:1591b5ccde044469a5ff3c72c5c38b8a

Virtualization: vmware

Operating System: CentOS Linux 7 (Core)

CPE OS Name:cpe:/o:centos:centos:7

Kernel: Linux 3.10.0-957.5.1.el7.x86_64

Architecture: x86-64

[[email protected] ~]#

或者直接修改/etc/hostname配置档案[[email protected] ~]# vim /etc/hostname #修改完重启生效

node01

6. 安装常用软件包[[email protected] ~]# yum -y install vim net-tools wget lrzsz curl

[[email protected] ~]# yum groupinstall -y "Development Tools"

7.配置vim编辑器不建议直接修改全域性配置档案/etc/vimrc,只需在使用者根目录下新增.vimrc档案,输入以下内容:[[email protected] ~]# cat > ~/.vimrc > " 显示行号

> set number

> " 高亮游标所在行

> set cursorline

> " 开启语法显示

> syntax on

> " 关闭备份

> set nobackup

> " 没有储存或档案只读时弹出确认

> set confirm

> " tab缩排

> set tabstop=4

> set shiftwidth=4

> set expandtab

> set smarttab

> " 预设缩排4个空格大小

> set shiftwidth=4

> " 档案自动检测外部更改

> set autoread

> " 高亮查询匹配

> set hlsearch

> " 显示匹配

> set showmatch

> " 背景色设定为黑色

> set background=dark

> " 浅色高亮显示当前行

> autocmd InsertLeave * se nocul

> " 显示输入的命令

> set showcmd

> " 字元编码

> set encoding=utf-8

> " 开启终端256色显示

> set t_Co=256

> " 增量式搜寻

> set incsearch

> " 设定预设进行大小写不敏感查询

> set ignorecase

> " 如果有一个大写字母,则切换到大小写敏感查询

> set smartcase

> " 不产生swap档案

> set noswapfile

> " 关闭提示音

> set noerrorbells

> " 历史记录

> set history=10000

> " 显示行尾空格

> set listchars=tab:»■,trail:■

> " 显示非可见字元

> set list

> " c档案自动缩排

> set cindent

> " 档案自动缩排

> set autoindent

> " 检测档案型别

> filetype on

> " 智慧缩排

> set smartindent

> EOF

8. 禁用 root 账号远端登入为了安全考虑,生产环境最好禁用root账号直接登入,修改配置档案/etc/ssh/sshd_config把#PermitRootLogin yes更改为PermitRootLogin no然后重启sshd服务;[[email protected] ~]# vim /etc/ssh/sshd_config

PermitRootLogin no

重启 sshd 服务

[[email protected] ~]# systemctl restart sshd

9. 更新系统更新系软件包,更新系统补丁

[[email protected] ~]# yum -y update

[[email protected] ~]# reboot

更新完以后,重启Server.

2019-12-28 16:51:00

相关文章