Linux環(huán)境初始優(yōu)化

前提:先裝好系統(tǒng),可以連接公網(wǎng)。

====================================================================

關(guān)閉防火墻和SELinux

systemctl stop firewalld

systemctl disable firewalld

systemctl status firewalld

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

setenforce 0 //先臨時關(guān)閉selinux

getenforce

====================================================================

配置yum,因為系統(tǒng)默認(rèn)yum下載軟件的時候是從隨機地址下載,速度都很慢,有時還無法建立鏈接下載超時失敗等;

配置yum源,從國內(nèi)下載,可以大大提高我們的使用體驗。(這里選擇阿里云,CentOS 7 版本,其他版本參考https://developer.aliyun.com/mirror/)

第一步:先備份

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

第二步:下載新的?CentOS-Base.repo 到 /etc/yum.repos.d/(還有epel源)

# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //選項-O:下載改名,存到目錄里

清緩存:

yum clean all

yum repolist //查看源

接下來就可以用yum安裝常用工具了:

# yum -y install tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs expect sl cowsay

注:最后兩個是娛樂命令,執(zhí)行完命令可以運行一下,看是否正常安裝。

# cowsay hello

# sl

====================================================================

優(yōu)化SSH連接速度(有時個連接半天一直卡著不動)

sed -i '/^GSSAPIAuthentication/s@^@#@g' /etc/ssh/sshd_config

cat? >>/etc/ssh/sshd_config << EOF

UseDNS no #相當(dāng)于網(wǎng)絡(luò)命令的-n選項.

GSSAPIAuthentication no #關(guān)閉GSS認(rèn)證.

EOF

#重新啟動

systemctl restart sshd

#檢查

egrep '^(GSSAPIAuthentication|UseDNS)'? /etc/ssh/sshd_config

====================================================================

修改命令行顏色

# echo? "export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\# '" >> /etc/profile

# source /etc/profile //更新,使之當(dāng)前生效

====================================================================

修改主機名

hostnamectl set-hostname 新主機名 //這種方法永久生效

例:# hostnamectl set-hostname lianxi.test.cn

hostname 新主機名 //這種方法臨時生效,重啟無效

--------------------------------------------------

對于老系統(tǒng)(如CentOS 6)

先通過命令行臨時修改生效:hostname 新主機名

再修改文件永久生效:/etc/hostname

====================================================================

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

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

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