首頁>技術>

俗話說的好“工欲善其事,必先利其器”,相信程式猿和運維人員深有體會。不論從事什麼工作,能有一套優秀的工具,對我們的工作更能事半功倍,下面來介紹最小化安裝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 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_configPermitRootLogin no

重啟 sshd 服務

[root@node01 ~]# systemctl restart sshd

9. 設定時區

安裝系統發現時間不對,需要修改時區和同步時間;

[root@node01 ~]# date -RSat, 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.

  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 開源免費的22款漂亮的Bootstrap主題,給你的專案錦上添花