首頁/ 汽車/ 正文

最小化安裝CentOS 7.6後的最佳化

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

最小化安裝CentOS 7.6後的最佳化

1。 系統核心版本

[root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7。6。1810 (Core)[root@localhost ~]# uname -r3。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/configSELINUX=enforcing #修改此行為disabled

修改後

SELINUX=disabled [root@localhost ~]# setenforce 0 #臨時關閉SELinux,不需要重啟即可生效

4。 配置網路

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

修改

ONBOOT=no

ONBOOT=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_configPermitRootLogin no

重啟 sshd 服務

[root@node01 ~]# systemctl restart sshd

9。 更新系統

更新系軟體包,更新系統補丁

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

更新完以後,重啟Server。

相關文章

頂部