美文网首页DevOps我用 LinuxLinux
最小化安装CentOS 7.6后的优化

最小化安装CentOS 7.6后的优化

作者: 尘世不扰 | 来源:发表于2019-03-16 00:32 被阅读1次

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

    1. 系统内核版本

    [root@localhost ~]# cat /etc/redhat-release
    CentOS Linux release 7.6.1810 (Core)
    [root@localhost ~]# uname -r
    3.10.0-957.5.1.el7.x86_64
    

    2. 关闭防火墙

    [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# systemctl disable firewalld
    

    3. 关闭SELinux

    [root@localhost ~]# vim /etc/selinx/config
    SELINUX=enforcing           #修改此行为disabled
    

    修改后

    SELINUX=disabled 
    
    [root@localhost ~]# setenforce 0            #临时关闭SELinux,不需要重启即可生效
    

    4. 配置网络

    [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
    

    修改 ONBOOT=noONBOOT=yes

    重启网络生效

    [root@localhost ~]# systemctl restart network.service
    

    5. 修改主机名

    通过 hostnamectl set-hostname [HOSTNAME] 可以直接永久修改主机名,相当于直接修改 /etc/hostname 文件,不需要重启服务器,需要退出终端,重新登录即可生效;而 hostname 只是临时修改主机名;

    其实主机名定义包括三种:静态的(Static hostname)、瞬态的(Tansient hostname)、灵活的(Pretty hostname),分别使用 --static--transient
    --pretty 选项来查看主机名;

    [root@localhost ~]# hostnamectl set-hostname node01  #退出重新登录生效
    
    [root@node01 ~]# 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
    [root@node01 ~]# 
    

    或者直接修改 /etc/hostname 配置文件

    [root@node01 ~]# vim /etc/hostname    #修改完重启生效
    node01
    

    6. 安装常用软件包

    [root@node01 ~]# yum -y install vim net-tools wget lrzsz curl
    
    [root@node01 ~]# yum groupinstall -y "Development Tools"
    

    7.配置vim编辑器

    不建议直接修改全局配置文件 /etc/vimrc ,只需在用户根目录下添加 .vimrc 文件,输入以下内容:

    [root@node01 ~]# cat > ~/.vimrc << EOF
    > " 显示行号
    > 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 服务;

    [root@node01 ~]# vim /etc/ssh/sshd_config
    
    PermitRootLogin no
    

    重启 sshd 服务

    [root@node01 ~]# systemctl restart sshd
    

    9. 更新系统

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

    [root@node01 ~]#  yum -y update
    
    [root@node01 ~]# reboot
    

    更新完以后,重启Server.

    相关文章

      网友评论

        本文标题:最小化安装CentOS 7.6后的优化

        本文链接:https://www.haomeiwen.com/subject/oxydmqtx.html