配置網絡地址,yum源


配置靜態網絡地址

1.1 問題

本例要求為虛擬機 server 配置以下靜態地址參數:

  1. 主機名:server0.example.com
  2. IP地址:172.25.0.11
  3. 子網掩碼:255.255.255.0
  4. 默認網關:172.25.0.254
  5. DNS服務器:172.25.254.254

1.2 方案

使用nmcli配置網絡連接時的基本操作,

查看網絡連接、連接詳情:

  • nmcli con show
  • nmcli con show "連接名"

修改網絡連接參數:

  • nmcli con modify "連接名" ipv4.method auto|manual
  • nmcli con modify "連接名" ipv4.addresses "IP地址/掩碼長度 [默認網關]" ipv4.dns DNS服務器地址
  • nmcli con modify "連接名" connection.autoconnect yes|no

1.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:配置固定主機名

1)配置前, 檢查是否設置靜態主機名

  1. [root@server0 ~]# hostnamectl
  2. Static hostname: n/a                         //未設置靜態主機名
  3. Transient hostname: server0.example.com

2)設置為指定的主機名

  1. [root@server0 ~]# vim /etc/hostname             //建立主機名配置文件
  2. server0.example.com

3)配置后,檢查結果

  1. [root@server0 ~]# hostnamectl
  2. Static hostname: server0.example.com         //已設置靜態主機名
  3. Icon name: computer
  4. .. ..

步驟二:配置靜態IP地址參數

1)查看當前主機的網卡設備、網絡連接

  1. [root@server0 ~]# nmcli connection show
  2. 名稱 UUID 類型 設備
  3. System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0

2)修改連接“System eth0”的配置

將配置方式指定為manual,指定IP地址、默認網關、DNS地址,並配置自動連接:

  1. [root@server0 ~]# nmcli connection modify "System eth0" ipv4.method manual ipv4.addresses "172.25.0.11/24 172.25.0.254" ipv4.dns 172.25.254.254 connection.autoconnect yes

3)重新激活連接“System eth0”

通過up指令激活連接配置,必要時也可以先down再up:

  1. [root@server0 ~]# nmcli connection up "System eth0"         //激活連接
  2. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)

確保系統服務NetworkManager開機自啟:

  1. [root@server0 ~]# systemctl restart NetworkManager
  2. [root@server0 ~]# systemctl enable NetworkManager

4)檢查修改結果,確認無誤

檢查IP地址:

  1. [root@server0 ~]# ifconfig eth0
  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 172.25.0.11 netmask 255.255.255.0 broadcast 172.25.0.255
  4. inet6 fe80::5054:ff:fe00:b prefixlen 64 scopeid 0x20<link>
  5. ether 52:54:00:00:00:0b txqueuelen 1000 (Ethernet)
  6. RX packets 1394 bytes 138855 (135.6 KiB)
  7. RX errors 0 dropped 0 overruns 0 frame 0
  8. TX packets 944 bytes 98495 (96.1 KiB)
  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

檢查默認網關地址:

  1. [root@server0 ~]# route -n
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags Metric Ref Use Iface
  4. 0.0.0.0 172.25.0.254 0.0.0.0 UG 1024 0 0 eth0
  5. 172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

檢查DNS服務器地址:

  1. [root@server0 ~]# cat /etc/resolv.conf
  2. # Generated by NetworkManager
  3. search example.com
  4. nameserver 172.25.254.254

如果在使用nmcli修改網絡連接時並未指定ipv4.dns,也可以直接修改DNS客戶端配置文件/etc/resolv.conf,確保添加有上述記錄即可。

步驟三:驗證網絡配置結果

通過ssh遠程訪問server0:

  1. [root@room9pc13 ~]# ssh -X root@server0.example.com
  2. Warning: Permanently added 'server0.example.com' (ECDSA) to the list of known hosts.
  3. Last login: Fri Dec 23 19:00:12 2016 from 172.25.0.250
  4. [root@server0 ~]# hostname                             //確認自己的主機名
  5. server0.example.com

在虛擬機server0上,可以查詢server0、desktop0、content等站點:

  1. [root@server0 ~]# host server0.example.com
  2. server0.example.com has address 172.25.0.11
  3. [root@server0 ~]# host desktop0.example.com
  4. desktop0.example.com has address 172.25.0.10
  5. desktop0.example.com mail is handled by 10 smtp0.example.com.
  6. [root@server0 ~]# host content.example.com
  7. content.example.com has address 172.25.254.254

2 案例2:使用yum軟件源

2.1 問題

本例要求為虛擬機 server0指定可用的yum軟件源,相關要求如下:

  1. YUM軟件庫源為 http://content.example.com/rhel7.0/x86_64/dvd
  2. 將此配置為虛擬機 server0 的默認軟件倉庫

2.2 步驟

實現此案例需要按照如下步驟進行。

步驟一:檢查現有yum倉庫,去除不可用的設置

1)列出yum庫

  1. [root@server0 ~]# yum repolist
  2. 已加載插件:langpacks
  3. rhel_dvd | 4.1 kB 00:00:00
  4. (1/2): rhel_dvd/group_gz | 134 kB 00:00:00
  5. (2/2): rhel_dvd/primary_db | 3.4 MB 00:00:00
  6. 源標識 源名稱 狀態
  7. rhel_dvd Remote classroom copy of dvd 4,305
  8. repolist: 4,305

2)移除不可用的yum庫配置文件

當執行yum repolist操作報錯時,才執行此步驟(否則此步可跳過)。

  1. [root@server0 ~]# mkdir /etc/yum.repos.d/repobak
  2. [root@server0 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repobak/

步驟二:添加指定的yum倉庫配置

1)使用yum-config-manager工具建立新配置文件

  1. [root@server0 ~]# yum-config-manager --add-repo http://content.example.com/rhel7.0/x86_64/dvd
  2. 已加載插件:langpacks
  3. adding repo from: http://content.example.com/rhel7.0/x86_64/dvd
  4. [content.example.com_rhel7.0_x86_64_dvd]
  5. name=added from: http://content.example.com/rhel7.0/x86_64/dvd
  6. baseurl=http://content.example.com/rhel7.0/x86_64/dvd
  7. enabled=1

2)修改新建的倉庫配置,添加gpgcheck=0以禁用GPG簽名檢查

  1. [root@server0 ~]# vim /etc/yum.repos.d/content.example.com_rhel7.0_x86_64_dvd
  2. [content.example.com_rhel7.0_x86_64_dvd]
  3. name=added from: http://content.example.com/rhel7.0/x86_64/dvd
  4. baseurl=http://content.example.com/rhel7.0/x86_64/dvd
  5. enabled=1
  6. gpgcheck=0

步驟三:確認新配置的yum源可用

  1. [root@server0 ~]# yum clean all                         //清理緩存
  2. 已加載插件:langpacks
  3. 正在清理軟件源: content.example.com_rhel7.0_x86_64_dvd
  4. Cleaning up everything
  5. [root@server0 ~]# yum repolist                         //重新列出可用的源
  6. 已加載插件:langpacks
  7. content.example.com_rhel7.0_x86_64_dvd | 4.1 kB 00:00:00
  8. (1/2): content.example.com_rhel7.0_x86_64_dvd/group_gz | 134 kB 00:00:00
  9. (2/2): content.example.com_rhel7.0_x86_64_dvd/primary_db | 3.4 MB 00:00:00
  10. 源標識 源名稱 狀態
  11. content.example.com_rhel7.0_x86_64_dvd added from: http://content.example.com 4,305
  12. repolist: 4,305

3 案例3:升級Linux內核

3.1 問題

本例要求為虛擬機 server0安裝升級版的新內核:

  1. 新版本的內核安裝文件可以從以下地址獲取:
  2. http://classroom/content/rhel7.0/x86_64/errata/Packages/
  3. 升級內核,並滿足下列要求:當系統重新啟動后,升級的新內核應該作為默認內核;原來的內核要被保留,並且仍然可以正常啟動

3.2 步驟

實現此案例需要按照如下步驟進行。

步驟一:下載新版內核的安裝文件

1)確認新版內核的下載地址

如果給定的下載地址中未包含kernel-...rpm文件路徑,則打開firefox瀏覽器,訪問指定的網址(如圖-5所示)。

圖-5

在打開的網頁上找到需要的內核文件,右擊對應的鏈接,選擇“Copy Link Location”復制下載地址(如圖-6所示)。

圖-6

2)下載新版內核安裝文件

根據前一步獲取到的內核下載地址,使用wget命令下載:

  1. [root@server0 ~]# wget http://classroom/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
  2. --2016-12-23 22:13:47-- http://classroom/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
  3. 正在解析主機 classroom (classroom)... 172.25.254.254
  4. 正在連接 classroom (classroom)|172.25.254.254|:80... 已連接。
  5. 已發出 HTTP 請求,正在等待回應... 200 OK
  6. 長度:30266784 (29M) [application/x-rpm]
  7. 正在保存至: “kernel-3.10.0-123.1.2.el7.x86_64.rpm”
  8. 100%[=========================================>] 30,266,784 40.4MB/s 用時 0.7s
  9. 2016-12-23 22:13:47 (40.4 MB/s) - 已保存 “kernel-3.10.0-123.1.2.el7.x86_64.rpm” [30266784/30266784])
  10. [root@server0 ~]# ls -lh kernel-*.rpm                 //確認下載結果
  11. -rw-r--r--. 1 root root 29M 6月 11 2014 kernel-3.10.0-123.1.2.el7.x86_64.rpm

步驟二:安裝新版內核

Linux系統支持安裝多個不同版本的內核,開機引導時可以選擇使用哪個版本。因此只需要正常安裝新版內核即可。

1)查看現有內核版本

  1. [root@server0 ~]# uname -r
  2. 3.10.0-123.el7.x86_64

2)安裝新版本內核

  1. [root@server0 ~]# rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm
  2. 警告:kernel-3.10.0-123.1.2.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID fd431d51: NOKEY
  3. 准備中... ################################# [100%]
  4. 正在升級/安裝...
  5. 1:kernel-3.10.0-123.1.2.el7 ################################# [100%]
  6.                                         //此處需耐心等待,千萬別強行終止
  7. [root@server0 ~]#

步驟三:確認新內核版本

1)重啟系統

  1. [root@server0 ~]# reboot
  2. .. ..

2)登入系統,確認使用的內核已是新版本

  1. [root@server0 ~]# uname -r
  2. 3.10.0-123.1.2.el7.x86_64

4 案例4:查找並處理文件

4.1 問題

本例要求采用不少於兩種方法完成以下任務:

  1. 找出所有用戶 student 擁有的文件
  2. 把它們拷貝到 /root/findfiles/ 文件夾中

4.2 步驟

實現此案例需要按照如下步驟進行。

步驟一:確認能找到指定的文件

1)確認新版內核的下載地址

  1. [root@server0 ~]# find / -user student -type f
  2. find: ‘/proc/1853/task/1853/fdinfo/6’: 沒有那個文件或目錄
  3. find: ‘/proc/1853/fdinfo/6’: 沒有那個文件或目錄
  4. /var/spool/mail/student
  5. /home/student/.bash_logout
  6. /home/student/.bash_profile
  7. /home/student/.bashrc
  8. /home/student/.ssh/authorized_keys
  9. /home/student/.config/gnome-initial-setup-done
  10. /home/student/.config/monitors.xml

對於上述操作中出現的/proc信息忽略即可。

步驟二:處理找到的文件

1)創建目標文件夾

  1. [root@server0 ~]# mkdir /root/findfiles

2)拷貝找到的文件到目標文件夾

以下兩種方法任選一種:

  1. [root@server0 ~]# find / -user student -type f -exec cp -p {} /root/findfiles/ \;
  2. .. ..
  3. 或者
  4. [root@server0 ~]# \cp -p $(find / -user student -type f) /root/findfiles/
  5. .. ..

3)確認拷貝結果

  1. [root@server0 ~]# ls -lhA /root/findfiles/
  2. 總用量 24K
  3. -rw-------. 1 student student 1.7K 7月 11 2014 authorized_keys
  4. -rw-r--r--. 1 student student 18 1月 29 2014 .bash_logout
  5. -rw-r--r--. 1 student student 193 1月 29 2014 .bash_profile
  6. -rw-r--r--. 1 student student 231 1月 29 2014 .bashrc
  7. -rw-r--r--. 1 student student 4 7月 11 2014 gnome-initial-setup-done
  8. -rw-r--r--. 1 student student 1.5K 7月 11 2014 monitors.xml
  9. -rw-rw----. 1 student mail 0 7月 11 2014 student

5 案例5:查找並提取文件內容

5.1 問題

本例要求在文件/usr/share/dict/words中查找到所有包含字符串seismic的行,並滿足下列要求:

  1. 將找到的行按原文順序拷貝到 /root/wordlist 文件中
  2. 文件 /root/wordlist 不要包含空行,並且其中所有行的內容必須是 /usr/share/dict/words 文件中原始行的准確副本

5.2 步驟

實現此案例需要按照如下步驟進行。

1)使用grep命令查找指定的關鍵詞,並通過重定向輸出保存到指定的文件:

  1. [root@serverX ~]# grep 'seismic' /usr/share/dict/words > /root/wordlist

2)確認提取結果

  1. [root@server0 ~]# cat /root/wordlist
  2. anaseismic
  3. antiseismic
  4. aseismic
  5. aseismicity
  6. bradyseismic
  7. .. ..


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM