CentOS相關

Posted by Leo Yang on 2023-02-17

CentOS常用指令

安裝

yum install 要裝的東西

網路相關工具 (檢查打開的port)

1
yum install net-tools

SSH Server (SSH 服務)

1
yum install openssh openssh-server

SSH Client (SSH Client)

1
yum install openssh-clients

firewall-cmd (設定防火牆)

1
sudo yum install firewalld

安裝可能會遇到的問題

failed to download metadata for repo…

因為CentOS7已經沒有維護了,要換一個下載套件的位置

sed -i ‘s/mirrorlist/#mirrorlist/g’ /etc/yum.repos.d/CentOS-*
sed -i ‘s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g’ /etc/yum.repos.d/CentOS-*

Errors during downloading metadata for repository ‘appstream’…:

更新SSL憑證

1
2
curl http://www.example.com/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt
curl -v https://example.com

Failed to download metadata for repo ‘appstream’: Cannot download repomd.xml: Curl error (77): Problem with the SSL CA cert (path? access rights?) for …

關閉sslverify

1
2
3
vi /etc/yum.conf
增加內容
sslverify=false

System has not been booted with systemd as init system (PID 1). Can’t operate.Failed to connect to bus: Host is down

1.系統尚未使用systemd作為初始化系統重新啟動系統,檢查systemd有沒有安裝(yum install systemd)
2.如果訊息還是出現的話,切換初始化系統從舊的SysVinit到systemd

1
systemctl enable systemd

檢查目前已經裝的東西

rpm -q 套件名稱

1
rpm -q openssh-server

啟動服務

  • 啟動SSH SERVER
1
systemctl start sshd

開機啟動服務

  • 啟動SSH SERVER
1
systemctl enable sshd

查目前IP

1
2
ip a
ip r

clear screen

1
ctrl+L

列出目前有開的所有port

1
2
(需要安裝套件net-tools : yum install net-tools)
netstat -tlnp

防火牆設定

打開某個port(–permanent 永久設定開啟,否則防火牆重啟或是重新設定時會失效)

1
firewall-cmd --permanent --zone=public --add-port=22/tcp

檢查防火牆目前打開port狀態

1
firewall-cmd --zone=public --list-all

重新讀取防火牆設定

1
firewall-cmd --reload

檢查打開的port設定是否有被加入防火牆設定

1
firewall-cmd --zone=public --list-all

SSH連線到某台機器

1
2
ssh 帳號@ip
ssh root@123.456.789

ping 某台機器確定是否可以連線

1
2
ping ip
ping 123.456.789

sudo command not found

1.檢查sudoers.d是否存在

1
find /etc/suders.d

如果不存在的話安裝sudo

1
yum install sudo

不回應Ping

sudo vi /proc/sys/net/ipv4/icmp_echo_ignore_all
1 不回應ICMP請求
0 回應ICMP請求


docker取的container ip

查container id

1
docker ps --format "table {{.ID}}\t{{.Status}}\t{{.Names}}"

查指定container ip

1
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id

<!–23–>