最小化安装CentOS 7.6后的优化

欢迎来到Abooo的博客

你好! 这是一个从零基础到慢慢熟练的运维工程师的博客,这些博客都是我一点一滴的经验积累和学习积累!希望帮助到你遇到的一切困难!加油吧!下面来介绍最小化安装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/selinux/config
SELINUX=enforcing #修改此行为disabled
修改后
SELINUX=disabled

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

4. 配置网络

关闭NetworkManager服务,这是一种动态管理网络配置的守护进程,能够让网络设备保持连接状态;
[root@localhost ~]# systemctl stop NetworkManager.service
[root@localhost ~]# systemctl disable NetworkManager.service
修改网卡参数,把ONBOOT=no 改为 ONBOOT=yes
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
重启网络服务生效
[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 telnet tcpdump tree

[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 ~]# date -R
Sat, 12 Oct 2019 17:58:10 -0800

[root@node01 ~]# timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海
安装ntp服务
[root@node01 ~]# yum -y install ntp
[root@node01 ~]# systemctl enable ntpd
[root@node01 ~]# systectl start ntpd
[root@node01 ~]# ntpdate ntp1.aliyun.com #校准时间
或者使用下面的命令:

查看时区 : date -R
更改时区: tzselect
列出所有时区:timedatectl list-timezones
设置时区:timedatectl set-timezone Asia/Shanghai
更改时间: date -s 06/28/2019

10. 配置aliyun的repo源

[root@node01 ~]# cd /etc/yum.repos.d
[root@node01 yum.repos.d]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[root@node01 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清除缓存并生成新的缓存
[root@node01 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors

[root@node01 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Metadata Cache Created

11. 更新系统

更新系软件包,更新系统补丁
[root@node01 ~]# yum -y update

[root@node01 ~]# reboot
更新完以后,重启Server.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值