杨磊的博客主站,搜罗全网有用的小资源!

Search trend: frp Linux Python 阀门 炉排 无人深空

Your cart (14)

Please install WooCommerce

安装CentOS后需要操作的10个操作

Thumbnail placeholder
楊蕾 的头像

俗话说“工欲善其事,必先利其器”,相信很多的程序猿都是深有体会,不论从事什么工作,一套优秀的工具,绝对可以让你事半功倍。

其实Linux系统也是一样,如果安装完Linux系统后再进行优化一下的话,绝对可以让你用在后期的运维工作中更加得心应手。

下面开始简单的给大家介绍几个可能会需要优化的地方。

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-01Icon name: computer-vmChassis: vmMachine ID: 64592dadfdff47789bd029c4d2d2dcc9Boot ID: 1591b5ccde044469a5ff3c72c5c38b8aVirtualization: vmwareOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-957.5.1.el7.x86_64Architecture: x86-64[root@chenxuyuan ~]#

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

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

chengxuyuan

6. 安装常用软件

[root@chengxuyuan ~]# yum -y install vim net-tools wget lrzsz curl telnet tcpdump tree[root@chengxuyuan ~]# yum groupinstall -y “Development Tools”

7.配置vim编辑器

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

[root@chengxuyuan ~]# 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 服务;

[root@chengxuyuan ~]# vim /etc/ssh/sshd_configPermitRootLogin no

重启 sshd 服务

[root@chengxuyuan ~]# systemctl restart sshd

9. 设置时区

安装系统发现时间不对,需要修改时区和同步时间;

[root@chengxuyuan ~]# date -RSat, 12 Oct 2019 17:58:10 -0800[root@node01 ~]# timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海

安装ntp服务

[root@chengxuyuan ~]# yum -y install ntp

[root@chengxuyuan ~]# systemctl enable ntpd

[root@chengxuyuan ~]# systectl start ntpd

[root@chengxuyuan ~]# ntpdate ntp1.aliyun.com #校准时间

或者使用下面的命令:

查看时区 : date -R

更改时区: tzselect

列出所有时区:timedatectl list-timezones

设置时区:timedatectl set-timezone Asia/Shanghai

更改时间: date -s 11/27/2019

10. 更新系统

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

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

更新完以后,重启Server.


楊蕾 的头像

公司专车送货上门

全年无休,半夜值班

售后无忧,专业团队上门服务

为您提供专业咨询和服务