天天看點

Linux系統優化

檢視系統版本、修改使用者、關閉selinux、關閉iptables、遠端連接配接亂碼

1.1 檢視Linux版本

1.1.1 系統版本

[root@znix ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)      

1.1.2 核心版本

[root@znix ~]# uname -r
2.6.32-696.el6.x86_64      

1.1.3 系統架構

[root@znix ~]# uname -m
x86_64      

1.2 添加使用者、設定密碼

1.2.1 添加使用者

[root@znix ~]# useradd clsn      

1.2.2 設定密碼

[root@znix ~]# passwd clsn
Changing password for user clsn. ###修改clsn使用者密碼
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple  ###密碼太簡單
Retype new password:
passwd: all authentication tokens updated successfully(成功).      

1.3 切換使用者

1.3.1 使用這個使用者 切換使用者

[root@znix ~]# su - clsn      

1.3.2 顯示你是誰?

[clsn@znix ~]$ whoami
clsn      

1.4 su 與su- 的差別

su隻是切換了root身份,但Shell環境仍然是普通使用者的Shell

su-連使用者和Shell環境一起切換成root身份了。

隻有切換了Shell環境才不會出現PATH環境變量錯誤。

su切換成root使用者以後,pwd一下,發現工作目錄仍然是普通使用者的工作目錄;而用su -指令切換以後,工作目錄變成root的工作目錄了。

1.5 關閉selinux

1.5.1 永久生效

修改配置檔案: /etc/selinux/config的

[root@znix ~]# vim /etc/selinux/config      

/etc/selinux/config 文檔内容含義:

#enforcing     selinux預設狀态 selinux已經開啟,正在運作

#permissive    selinux臨時關閉,顯示警告

#disabled      selinux徹底關閉   

使用sed指令對/etc/selinux/conifg 檔案進行修改

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config      

讓配置檔案的修改生效,使用source指令

[root@znix ~]# source /etc/selinux/config      

永久修改的配置生效需要重新開機伺服器。

使用的伺服器不可以随意重新開機!

1.5.2 臨時關閉

使用getenforce 指令檢視selinux的

[root@znix ~]# getenforce
Enforcing(正在運作)      

使用setenforce 指令修改selinux配置臨時關閉selinux。

[root@znix ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]

[root@znix ~]# setenforce 0
[root@znix ~]# getenforce
Permissive(臨時關閉)      

1.6 關閉防火牆

1.6.1 臨時關閉

1)         查詢防火牆是否正在運作

[root@znix ~]# /etc/init.d/iptables status      

2)         關閉防火牆

a)      一般需要關兩次,確定完全關閉。

[root@znix ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                            [  OK  ]

[root@znix ~]# /etc/init.d/iptables stop      

3)         檢查一下是否關閉

[root@znix ~]# /etc/init.d/iptables status
iptables: Firewall is not running.      

1.6.2 永久關閉

確定開機防火牆不再啟動

在chkconfig中查找iptables 的行,看他的狀态。on是開,off是關。

[root@znix ~]# chkconfig|grep "ipta"
iptables         0:off      1:off      2:on       3:on       4:on       5:on       6:off      

使用chkconfig的指令關閉iptables

[root@znix ~]# chkconfig iptables off      

檢查一下是否關閉了。

[root@znix ~]# chkconfig|grep "ipta"
iptables         0:off      1:off      2:off      3:off      4:off      5:off      6:off      

1.7 顯示亂碼解決

1.7.1 檢視linux系統字元集

[root@znix ~]# echo $LANG
en_US.UTF-8      

1.7.2 檢視遠端軟體的字元集

連接配接軟體的字元集是否與系統的一緻 

1.7.3 亂碼解決辦法

1)         linux系統字元集修改

a)      使用export 對變量進行修改

[root@znix ~]# export LANG=en_US.utf8
[root@znix ~]# echo $LANG
en_US.utf8      

      b)修改配置檔案,将/etc/sysconfig/i18n修改為utf-8字元集。

[root@znix ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"      

      c)使用source或. /etc/sysconfig/i18n  讓配置生效

[root@znix ~]# source /etc/sysconfig/i18n
[root@znix ~]# . /etc/sysconfig/i18n      

作者:慘綠少年

出處:http://clsn.io

本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。

繼續閱讀