linux系統(tǒng)優(yōu)化

1.操作系統(tǒng)的基礎(chǔ)優(yōu)化

準(zhǔn)備工作:

(1)系統(tǒng)硬件信息查看
名稱-------文件 ------- -----------------命令
CPU: ------- cat /proc/cpuinfo ------ lscpu
內(nèi)存: -------- cat /proc/meminfo -----free -h
磁盤: -------- cat /proc/mounts ------- df -h
負(fù)載: -------- cat /proc/loadavg ------ w uptime top
(2)系統(tǒng)版本信息查看
文件查看:cat /etc/redhat-release
命令查看:uname -a

2.系統(tǒng)用戶優(yōu)化部分

(1)如何創(chuàng)建用戶:useradd oldboy
(2)如何設(shè)置密碼:
方法一:利用root用戶設(shè)置密碼

 [root@linux67 tmp]# passwd oldgirl
   Changing password for user oldgirl.
    New password: 
    BAD PASSWORD: The password is shorter than 8 characters
    Retype new password: 
    passwd: all authentication tokens updated successfully.

方法二: 不同用戶自己設(shè)置密碼

[oldgirl@linux67 ~]$ passwd
 Changing password for user oldgirl.
 Changing password for oldgirl.
  (current) UNIX password: 
   New password: 
   Retype new password:

ps: 重新設(shè)置的密碼盡量不要和原有密碼太相似
方法三:批量修改用戶密碼
①單個用戶免交互修改密碼:
echo 123456|passwd --stdin oldboy
②批量修改多個用戶密碼:
for user in oldboy oldgirl olddog oldbaby;do echo 123456|passwd --stdin $user;done
③腳本

   [root@linux67 tmp]# vi set_pass.sh
       #!/bin/bash
       for user in oldboy oldgirl olddog oldbaby
       do 
         echo 123456|passwd --stdin $user
       done

(3)如何刪除用戶
例如:userdel oldboy
(4)檢查用戶信息
例如:id oldboy

3.系統(tǒng)命令提示符號優(yōu)化

PS1----用于設(shè)置系統(tǒng)命令提示符
[root@linux67 ~]#echo PS1 [ \u @ \h \W ]\

\u  --- 當(dāng)前登錄用戶
         @   --- 分割符號
         \h  --- 顯示系統(tǒng)主機(jī)名稱
         \W  --- 顯示當(dāng)前路徑信息
         \$  --- 顯示登錄系統(tǒng)用戶信息   
                 # 管理員用戶 root  
                 $ 普通用戶   oldboy

(1)優(yōu)化提示符顯示信息
臨時設(shè)置

PS1="[\u@\h \t \W]\\$ "
PS1='[\u@\h \t \W]\$ '

永久設(shè)置

vi /etc/profile 
        PS1='[\u@\h \t \W]\$ '

(2)提示符顏色優(yōu)化

\[\033[01;32m\]   --- 開始給字符添加顏色
 \033[0m\]         --- 結(jié)束添加顏色過程

例如:PS1="[[\e[31;1m]\u@[\e[0m][\e[33;1m]\H[\e[0m][\e[32;1m] \w[\e[0m]]\$ "(臨時設(shè)置)
例如:vi /etc/profile
RED='[\033[01;31m]'
Yello='[\033[01;33m]'
Green='[\033[01;32m]'
End='\033[0m]'

   PS1="[$RED\u$End@$Yello\h$End $Green\W$End]\\$ (永久設(shè)置)

4.yum源優(yōu)化

重要目錄: /etc/yum.repos.d/ --- 保存yum源文件目錄
Base yum源優(yōu)化

 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
       或者
       curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

epel

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
       或者
       curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 

5.系統(tǒng)安全優(yōu)化

安全服務(wù): firewalld(防火墻)-centos7 iptables(防火墻)-centos6
安全服務(wù): selinux (限制root用戶行為) 系統(tǒng)權(quán)限概念 root管理員
(1)防火墻服務(wù)如何關(guān)閉:
臨時關(guān)閉

centos7                                    
       systemctl stop firewalld                   
       systemctl is-active firewalld  
centos6   
        /etc/init.d/iptables stop       
       /etc/init.d/iptables status
       services stop iptables

永久關(guān)閉:

centos7                                  
       systemctl disable firewalld                
       systemctl is-enabled firewalld             
  centos6  
          chkconfig  iptables  off
           chkconfig  --list iptables4

(2) selinux安全服務(wù)如何關(guān)閉
臨時關(guān)閉:

 setenforce 
       usage:  setenforce [ Enforcing | Permissive | 1 | 0 ] ?? 
       setenforce  Permissive | 0
       # getenforce 
       Permissive   

永久關(guān)閉:

  vim /etc/selinux/config
       SELINUX=disabled
       enforcing  - SELinux security policy is enforced.
                    selinux安全策略會被強(qiáng)制執(zhí)行
                    
       permissive - SELinux prints warnings instead of enforcing.
                    selinux輸出警告信息代替強(qiáng)制執(zhí)行
       
       disabled   - No SELinux policy is loaded.
                    不加載Selinux策略
    
       sed -i '7s#enforcing#disabled#g'  /etc/selinux/config

6.系統(tǒng)字符集優(yōu)化

(1)避免出現(xiàn)字符亂碼---字符編碼信息如何調(diào)整
臨時調(diào)整:
LANG="en_US.GBK"
永久調(diào)整:
方法一: 將配置信息放入到/etc/profile
LANG="en_US.GBK"
方法二: 將配置信息放入到/etc/locale.conf
LANG="zh_CN.gbk"
ps:配置的字符編碼必須是系統(tǒng)可以識別的
localectl list-locales
即臨時修改, 又永久修改
localectl set-locale LANG="en_US.iso88591"
(2)可以中文顯示信息
localectl set-locale LANG="zh_CN.utf8"

7. 系統(tǒng)時間信息優(yōu)化

timedatectl (查看時間)
(1)修改時間信息和真正時間同步的原因
① 時區(qū)不正確:
timedatectl set-timezone ZONE
調(diào)整時間信息:
a 手動調(diào)整時間信息
timedatectl set-time TIME
b 自動調(diào)整時間信息
yum install -y chrony
timedatectl set-ntp 1

      timedatectl 參數(shù)信息:
      status                   Show current time settings
                               顯示目前時間設(shè)置信息
      set-time TIME            Set system time
                               設(shè)置系統(tǒng)時間
                               timedatectl set-time "2019-10-10 10:57"
      set-timezone ZONE        Set system time zone
      list-timezones           Show known time zones
                               顯示出已知系統(tǒng)時區(qū)信息
                               timedatectl set-timezone America/Los_Angeles
                               timedatectl set-timezone Asia/Shanghai
      set-local-rtc BOOL       Control whether RTC is in local time   
                               set-local-rtc 0  rtc功能是關(guān)閉
                               set-local-rtc 1  rtc功能是開啟
      1 2 3 30        整數(shù)
      1.11 1.12 1.13  浮點(diǎn)數(shù)
      1(true) 0(false)布爾型
      RTC: 設(shè)置硬件時間信息, 設(shè)置為1開啟, 將系統(tǒng)信息自動同步給硬件
      
      set-ntp BOOL             Control whether NTP is enabled
                               是否設(shè)置開啟網(wǎng)絡(luò)時間同步功能(NTP: 網(wǎng)絡(luò)時間協(xié)議)
                               yum install -y chrony

8.遠(yuǎn)程連接優(yōu)化

第一步: 修改遠(yuǎn)程服務(wù)配置文件:
vim /etc/ssh/sshd_config -- :set nu
79 GSSAPIAuthentication no -- 遠(yuǎn)程認(rèn)證方式
115 UseDNS no -- 遠(yuǎn)程訪問時根據(jù)IP地址進(jìn)行反向解析過程
第二步: systemctl restart sshd

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容