系統優化方法(基礎優化)
一、查看了解系統信息
1、uname -a 查看內核信息
2、cat /proc/version 查看內核信息
3、cat /etc/redhat-release 查看系統版本
4、cat /proc/cpuinfo 查看cpu信息
5、hostname 查看計算機名稱
6、lsmod 查看內核模塊
7、free -h 查看內存使用情況
8、df -h 查看各分區使用情況
二、用戶賬號管理
1、添加一個普通用戶賬號
useradd tom 添加tom
password tom 修改tom用戶的密碼
2、切換用戶
su 切換用戶名命
su - tom 切換到tom用戶
3、id 查看信息
4、whoami 查看當前身份
三、操作系統優化---命令提示符優化
01. 修改命令提示符的內容:
vi /etc/profile 把export PS1='[\u@\H \w]\$ '追加到最后一行
[root@localhost.localdomain ~]# tail -5 /etc/profile export PS1='[\u@\H \w]\$ '
\u --- 顯示當前登錄用戶名稱
\H --- 顯示系統完整主機名稱
\W --- 顯示當前所在目錄信息(目錄結構的最后結尾信息)
02. 命令提示符如何修改顏色:
Linxu系統中如何給信息加顏色
\[\e[F;Bm] 文字內容 \e[m
”[\[\e[31;40m]\u\e[m @\h \W]\$ “
[root@oldboyedu ~]# tail -5 /etc/profile export PS1='\[\e[32;1m\][\u@\h \W]\$ \[\e[0m\]'
設置顏色 內容 結束
export PS1='\[\e[30;1m\][\u@\h \W]\$ \[\e[0m\]' -- 黑色提示符
export PS1='\[\e[31;1m\][\u@\h \W]\$ \[\e[0m\]' -- 紅色提示符
export PS1='\[\e[32;1m\][\u@\h \W]\$ \[\e[0m\]' -- 綠色提示符
export PS1='\[\e[33;1m\][\u@\h \W]\$ \[\e[0m\]' -- 黃色提示符
export PS1='\[\e[34;1m\][\u@\h \W]\$ \[\e[0m\]' -- 藍色提示符
export PS1='\[\e[35;1m\][\u@\h \W]\$ \[\e[0m\]' -- 粉色
export PS1='\[\e[36;1m\][\u@\h \W]\$ \[\e[0m\]' -- 淺藍
export PS1='\[\e[37;1m\][\u@\h \W]\$ \[\e[0m\]' -- 白色
四、操作系統優化---yum下載源優化
0、安裝wget工具
yum install wget -y
1、首先備份/etc/yum.repos.d/CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下載對應版本repo文件, 放入/etc/yum.repos.d/(操作前請做好相應備份)
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
3、運行以下命令生成緩存
yum clean all
yum makecache
4、檢查可用的yum主機
yum repolist
國內比較好的源地址:
https://developer.aliyun.com/mirror/
http://mirrors.163.com/.help/centos.html
5、安裝常用工具:yum install -y vim tree wget net-tools nmap bash-completion sysstat
6、查看己安裝的工具
rpm -aq -q表示查詢 -a表提所有
[root@localhost.localdomain /etc/yum.repos.d]# rpm -aq tree
tree-1.6.0-10.el7.x86_64
7、查看某個工具的安裝目錄
rpm -aql -l列表顯示
[root@localhost.localdomain /etc/yum.repos.d]# rpm -aql tree /usr/bin/tree /usr/share/doc/tree-1.6.0 /usr/share/doc/tree-1.6.0/LICENSE /usr/share/doc/tree-1.6.0/README /usr/share/man/man1/tree.1.gz
8、查看某個目錄屬於哪個軟件包
rpm -qf
[root@localhost.localdomain ~]# rpm -qf /usr/bin/ssh openssh-clients-7.4p1-16.el7.x86_64
五、系統安全相關優化(將一些安全服務進行關閉)
1、防火牆服務程序
centos7 查看防火牆服務狀態:systemctl status firewalld
臨時關閉防火牆:systemctl stop firewalld
永久關閉防火牆:systemctl disable firewalld
確認防火牆是否關閉:systemctl is-active firewalld
systemctl status firewalld
確認防火牆是否開機自啟動: systemctl is-enabled firewalld
2、 系統的selinux服務程序
selinux服務對root用戶權限進行控制
getenforce 確認selinux服務時否開啟還是關閉的
臨時開啟或關閉selinux
[root@localhost.localdomain ~]# setenforce ?
setenforce [ Enforcing | Permissive | 1 | 0 ]
Enforcing 或 1 ----臨時開啟selinux
Permissive 或 0 ----臨時關閉selinux
永久關閉:
enforcing - SELinux security policy is enforced.
selinux服務處於正常開啟狀態
permissive - SELinux prints warnings instead of enforcing.
selinux服務被臨時關閉了
disabled - No SELinux policy is loaded.
selinux服務徹底關閉
vi /etc/selinux/config
SELINUX=disabled
PS: 如果想讓selinux配置文件生效,重啟系統
六、系統中字符集編碼設置方法
centos7
查看默認編碼信息
[root@localhost.localdomain ~]# echo $LANG
en_US.UTF-8
臨時修改:
[root@localhost.localdomain ~]# echo $LANG
en_US.UTF-8
[root@localhost.localdomain ~]# LANG=UTF-8
永入修改:
方法一: 更加有先
[root@localhost.localdomain ~]# echo "export LANG='en_US.UTF-8'" >> /etc/profile
[root@localhost.localdomain ~]# tail -5 /etc/profile
unset i
unset -f pathmunge
export PS1='[\u@\H \w]\$ '
export LANG='en_US.UTF-8'
方法二:
[root@localhost.localdomain ~]# echo "LANG="zh_CN.UTF-8"" >> /etc/locale.conf
[root@localhost.localdomain ~]# cat /etc/locale.conf
LANG="en_US.UTF-8"
LANG="zh_CN.UTF-8"
補充:一條命令即臨時設置,又永久設置
localectl set-locale LANG=zh_CN.GBK
七. 使xshell軟件遠程連接速度加快
第一個步驟:修改ssh服務配置文件
vi /etc/ssh/sshd_config
79 GSSAPIAuthentication no
115 UseDNS no
第二個步驟:修改hosts文件
[root@mrxiong ~]# vi /etc/hosts
10.0.0.200 mrxiong.com
第三個步驟:重啟ssh遠程服務
systemctl restart sshd