centos7系統管理和運維實戰
centos7安裝配置
yum install -y net-tools >/etc/hostname echo "sqlserver01" >/etc/hostname systemctl stop firewalld systemctl disable firewalld yum install -y iptables-services systemctl start iptables systemctl enable iptables
centos和RHEL也有很多不同之處 P2
RHEL中包含了紅帽自行開發的閉源軟件,如紅帽集群套件,這些軟件並未開放源代碼,因此也就未包含在centos發行版中
centos發行版通常會修改RHEL中存在的bug,並提供了一個yum源以便用戶可以隨時更新操作系統
centos7的最新改進 P3
centos7使用的內核是3.10.0:對swap內存空間進行壓縮,提高IO性能,優化KVM虛擬化,默認使用XFS文件系統,使用firewalld防火牆,Linux容器,systemd代替sysvinit使存在依賴的服務之間更好地並行化
P20
root密碼:密碼通常用四分之三原則來設置,即密碼要包含密碼的4種字符,大寫字母,小寫字母,數字,字符中的3種
安裝ifconfig、netstat、route命令,並關閉防火牆
yum install -y net-tools service firewalld stop Redirecting to /bin/systemctl stop firewalld.service
traceroute命令 P50
每行記錄對應一跳,每跳表示一個網關,每行有3個時間,單位是ms,星號表示ICMP信息沒有返回
traceroute一次同時發送3個UDP包來探測,最多經過30個路由器,也就是最多30跳,經過30跳還未到達目標主機traceroute就會停止
3個UDP數據包,每經過一跳,會返回3個數據包的跳步數,路由器IP或名字,數據包周轉時間
3 120.197.23.49 6.945 ms 183.233.19.205 7.164 ms 120.197.23.49 6.750 ms
3跳 第一個數據包經過的路由器ip 時間 第二個數據包經過的路由器ip 時間 第三個數據包經過的路由器ip 時間
直到收到ICMPPORT_UNREACHABLE消息或到達最大跳步數30跳
traceroute -n www.baidu.com (Linux下 -n表示只顯示ip不顯示域名)
tracert -d www.csdn.net (Windows下 -d表示只顯示ip不顯示域名)
http://network.51cto.com/art/201505/476087_all.htm
traceroute to www.baidu.com (183.232.231.173), 30 hops max, 60 byte packets
1 * * *
2 183.233.92.217 7.809 ms 183.233.19.205 7.247 ms 120.197.23.73 7.124 ms
3 120.197.23.49 6.945 ms 183.233.19.205 7.164 ms 120.197.23.49 6.750 ms
4 * 120.196.240.97 6.993 ms *
5 * 183.235.226.166 6.682 ms 211.136.208.82 9.998 ms
6 211.139.158.66 10.092 ms 183.235.225.194 6.594 ms 6.776 ms
7 120.198.207.125 6.295 ms * 120.196.241.174 8.864 ms
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
上面顯示訪問百度不通,數據包到達某一個節點時沒有返回,可以將此結果提交IDC運營商,以便解決問題
配置網卡地址 一定要設置DNS P54
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet DEFROUTE=yes PEERDNS=yes PEERROUTES=yes NAME=eno16777736 DEVICE=eno16777736 NM_CONTROLLED=yes ONBOOT=yes IPADDR=192.168.0.128 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 DNS1=114.114.114.114 DNS2=114.114.115.115
修改主機名 P55
vi /etc/hostname
cat /etc/hostname aaa
P56
使用service命令要注意,centos7使用的是systemd,因此開啟和停止服務實際執行的時候會用systemd替代service命令腳本
在最新版centos7中,系統安裝了兩個防火牆firewalld和iptables P56
切換至iptables 將默認的firewalld停止,讓系統將iptables作為默認防火牆 P58
#關閉並禁用firewalld
systemctl stop firewalld
systemctl disable firewalld
#啟動並啟用iptables
centos6 iptables是內核一部分 rpm -qf /sbin/iptables file /sbin/iptables is not owned by any package #centos7 iptables變為可選的安裝包,需要安裝 yum install -y iptables-services systemctl start iptables systemctl enable iptables
#如果使用了ipv6 還需要開啟ip6tables
systemctl start ip6tables
systemctl enable ip6tables
iproute2
iproute2提供網絡參數設置,路由設置,帶寬控制,最新GRE隧道VPN
iproute2工具包中主要管理工具為ip命令
#安裝 yum install -y iproute #查看版本號 ip -V
ip命令可以替代ifconfig和route命令
#顯示所有的ip地址,同ipconfig -a
ip addr list
ip addr list 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:22:02:4a brd ff:ff:ff:ff:ff:ff inet 10.105.9.115/18 brd 10.105.63.255 scope global eth0
#顯示路由信息ip route list可以顯示網卡地址,route -n命令只會顯示內網網段
ip route list
ip route list 10.105.0.0/18 dev eth0 proto kernel scope link src 10.105.9.115 169.254.0.0/16 dev eth0 scope link metric 1002 default via 10.105.0.1 dev eth0 10.105.9.115 :網卡地址 10.105.0.0/18:內網網段 dev eth0 :網卡名稱 default via 10.105.0.1 dev eth0 :網關
路由表管理 P92
以下命令和概念centos6也有
默認情況下Linux並發只有一個路由表,因為如果系統中只有一個路由表,策略路由許多功能無法實現
數據包轉發到哪個路由表由系統設定的規則決定,查看系統默認的規則使用命令ip rule list
[root@sqlserver01 ~]# ip rule list
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
上面顯示系統有三張路由表,local,main,default
#ip route list不加任何參數默認顯示main路由表
[root@sqlserver01 ~]# ip route list table main
default via 10.11.10.1 dev eth0 proto static metric 100
10.11.10.0/24 dev eth0 proto kernel scope link src 10.11.10.33 metric 100
[root@sqlserver01 ~]# ip route list
default via 10.11.10.1 dev eth0 proto static metric 100
10.11.10.0/24 dev eth0 proto kernel scope link src 10.11.10.33 metric 100
FTP文件共享基於TCP/IP協議 P107
21端口用戶驗證
20端口傳數據
主動模式和被動模式都是用21端口做驗證,只是傳數據端口不一樣
Systemd和systemctl
https://linux.cn/article-5926-1.html
重要:Systemctl接受服務(.service),掛載點(.mount),套接口(.socket)和設備(.device)作為單元。
7. 列出所有可用單元
# systemctl list-unit-files
9. 列出所有失敗單元
# systemctl --failed
8. 列出所有運行中單元
# systemctl list-units
上面這組命令很少用
----------------------------------------
進入系統救援模式
32. 啟動系統救援模式,機器會馬上重啟,所以要在電腦面前做
# systemctl rescue
33. 進入緊急模式
# systemctl emergency
----------------------------------------
控制系統運行等級
/etc/inittab 文件不再可用,但是init命令依然可用,可以切換運行等級
34. 列出當前使用的運行等級
# systemctl get-default
35. 設置多用戶模式或圖形模式為默認運行等級
# systemctl set-default runlevel3.target
# systemctl set-default runlevel5.target
36. 啟動運行等級5,即圖形模式
# systemctl isolate runlevel5.target
或
# systemctl isolate graphical.target
37. 啟動運行等級3,即多用戶模式(命令行)
# systemctl isolate runlevel3.target
或
# systemctl isolate multiuser.target
38. 重啟、停止、掛起、休眠系統或使系統進入混合睡眠
# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep
----------------------------------------
使用Systemctl控制並管理服務
12. 列出所有服務(包括啟用的和禁用的)
# systemctl list-unit-files --type=service
13. 查看所有已啟動的服務 看打active running 表示已經啟動
systemctl list-units --type=service |grep acpi
14. Linux中如何啟動、重啟、停止、重載服務以及檢查服務(如 httpd.service)狀態
注意:當我們使用systemctl的start,restart,stop和reload命令時,我們不會從終端獲取到任何輸出內容,只有status命令可以打印輸出。
# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service
15. 如何激活服務並在啟動時啟用或禁用服務(即系統啟動時自動啟動服務)
# systemctl is-active httpd.service
# systemctl enable httpd.service
# systemctl disable httpd.service
16. 使用systemctl命令殺死服務
# systemctl kill httpd
# systemctl status httpd
ff
F