新裝CentOS7基礎優化
資訊查看
cat /etc/centos-release #查看版本
uname -r #查看內核版本
hostnamectl set-hostname name #改計算機名
配置網路
vi /etc/sysconfig/network-scripts/ifcfg-ens33
# 最小配置就這么多,其他的都可以不配置
TYPE=Ethernet #設定網卡型別,“Ethernet”表示以太網
DEVICE=ens33 #設定網卡的名稱
ONBOOT=yes #設定網卡是否在 Linux 作業系統啟動時激活
BOOTPROTO=static #設定網卡的配置方式,“static”表示使用靜態IP地址,“dhcp”時表示動態獲取地址
IPADDR=192.168.80.3 #設定網卡的 IP 地址
NETMASK=255.255.255.0 #設定網卡的子網掩碼
GATEWAY=192.168.80.2 #設定網卡的默認網關地址
DNS1=192.168.80.2 #設定DNS服務器的 IP 地址
系統源優化
首先備份源 /ect/yum.repos.d/CentOS-Base.repo,在安裝之前我們先必須安裝wget
yum -y install wget yum-utils epel-release
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
替換為阿里源
這里是centos7和epel的源,后續還可能用到python模塊源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
如果你需要使用docker
wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安裝python更改國內源
yum install python36 -y
mkdir ~/.pip
cd ~/.pip
vim pip.conf
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
清楚快取生成新快取
yum clean all && yum makecache
系統更新
只升級包
yum -y upgrade
升級所有包,不改變軟體設定和系統設定,系統版本升級,內核不改變
全升級
yum -y update
升級所有包,改變軟體設定和系統設定,系統版本內核都升級
生產服務器千萬別這么干,總之不建議使用update,如果這么服務器上部署了好多服務,這么干你小則罰款記過,大則離職跑路,
詳細請看這里:https://blog.csdn.net/weixin_34415923/article/details/92598179
必裝依賴組件
以下是一些必裝依賴、軟體、服務,可以根據你的實際情況選擇安裝,
gcc glibc gcc-c++ make cmake net-tools screen vim lrzsz tree dos2unix lsof tcpdump bash-completion
wget ntp setuptool psmisc openssl openssl-devel bind-utils traceroute
一鍵安裝
yum -y install gcc glibc gcc-c++ make cmake net-tools screen vim lrzsz tree dos2unix lsof tcpdump bash-completion wget ntp setuptool psmisc openssl openssl-devel bind-utils traceroute
圖形化配置工具
圖形化配置網路/服務/防火墻
yum -y install setuptool ntsysvsystem-config-securitylevel-tui networkManager-tui authconfig-gtk system-config-keyboard bind-utils
關閉防火墻
搭建的時候關掉,搭建號之后再開啟,要不然很痛苦
systemctl disable firewalld
systemctl stop firewalld
sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
登錄的優化
更改遠程登錄埠
vim /etc/ssh/sshd_config
Port 22 #之前的是22
Port 22222 #這行是新增的
SSH超時時間
vim /etc/ssh/sshd_config
ClientAliveInterval 60 #server每隔60秒發送一次請求給client,然后client回應,從而保持連接
ClientAliveCountMax 3 #server發出請求后,客戶端沒有回應得次數達到3,就自動斷開連接,正常情況下,client不會不回應
禁止root遠程登錄
只能遠程登錄普通用戶,然后su到root的權限,不能讓root直接遠程登錄
vim /etc/ssh/sshd_config,
找到 PermitRootLogin
改為 PermitRootLogin no
service sshd restart
root用戶密碼輸入錯誤三次,鎖定賬戶一段時間
vim /etc/pam.d/sshd
增加
auth required pam_tally.so deny=3 unlock_time=5
設定時區并同步時間
timedatectl set-timezone 'Asia/Shanghai'
ntpdate ntp1.aliyun.com
歷史命令顯示操作時間
vim /etc/profile
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
source /etc/profile
禁止定時任務向發送郵件
sed -i 's/^MAILTO=root/MAILTO=""/' /etc/crontab
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/384442.html
標籤:其他
上一篇:關于2021/12/17國內bing不能正常訪問的解決方法。
下一篇:Windows的基礎docker
