1+X雲計算平臺運維與開發認證(中級)樣卷B-實操過程

個人博客地址:http://www.mwbdtth.club/

選擇題可能有些題目有點小問題,請酌情參考,主要還是以實操爲主

單選題(200分):

1.下面關於軟件項目開發過程,敘述錯誤的是?(10分)
A、敏捷開發從需求、計劃、開發、測試,直到項目結束,整個週期一直在迭代中
B、敏捷開發中開發、測試、發佈又可以單獨迭代多次
C、瀑布式模型分爲計劃、分析、設計、程序開發、測試、修改和整合,一個階段結束,另一個階段接着開始
D、瀑布式模型着重迭代式開發,分析、設計、開發、測試和發佈(正確答案)



 

2.敏捷開發從需求、計劃、開發、測試,直到項目結束,整個週期一直在迭代中,而其中可以單獨迭代多次的不包括哪個過程?(10分)
A、開發
B、測試
C、計劃(正確答案)
D、發佈



 

3.以下關於STP協議的描述中,哪項是正確的? (10分)
A、STP運行在交換機和網橋設備上
B、STP協議是一個二層鏈路管理協議
C、STP在選定根網橋,讓一些端口進入阻塞工作模式,這些被阻塞端口沒有被激活(正確答案)
D、STP的主要功能是在保證網絡中沒有迴路的基礎上,允許在第二層鏈路中提供冗餘路徑



 

4.以下哪個狀態不是RSTP的工作狀態? (10分)
A、監聽狀態(正確答案)
B、丟棄狀態
C、轉發狀態
D、學習狀態



 

5.在常用的數據庫表單管理命令當中,“use 數據庫;”名稱的作用是?(10分)
A、描述表單
B、指定使用的數據庫(正確答案)
C、顯示當前已有的數據庫
D、更新表單中的數據



 

6.在mysqldump備份命令當中,參數-u的作用是?(10分)
A、數據庫的用戶名稱(正確答案)
B、密碼提示符
C、只導出表結構
D、備份完成後將不再允許修改數據



 

7.basic paxos流程中server的主要功能是什麼?(10分)
A、對投票結果進行統計(正確答案)
B、進行投票
C、篩選無用的投票
D、無任何功能



 

8.選完Leader以後,ZooKeeper就進入狀態同步過程,具體方式如下:① Leader等待Server連接;② Follower連接Leader,將最大的zxid發送給Leader;③ Leader根據Follower的zxid確定同步點;④ 完成同步後通知Follower已經成爲uptodate狀態;⑤ Follower收到uptodate消息後,又可以重新接受client的請求進行服務了。請問正確的順序是什麼?(10分)
A、12345(正確答案)
B、13245
C、12435
D、21345



 

9.Keystone爲OpenStack平臺提供了什麼服務?(10分)
A、認證服務(正確答案)
B、存儲服務
C、鏡像服務
D、計算服務



 

10.什麼是私有云計算基礎架構的基石?(10分)
A、虛擬化(正確答案)
B、分佈式
C、並行
D、集中式



 

11.Swift將Object存儲在節點(Node)上,每個節點都是由多個硬盤組成的,並保證對象在多個節點上有備份,默認情況下,Swift會給所有數據保存多少個副本?(10分)
A、1
B、2
C、3(正確答案)
D、4



 

12.以下關於行業雲的描述中,錯誤的是哪項?(10分)
A、能爲行業的業務作專門的優化
B、能進一步方便用戶
C、能進一步降低成本
D、可同時支持的範圍較大,如金融雲、政務雲、醫療雲、衛生雲等(正確答案)



 

13.以下哪個不是小微企業使用雲計算可以帶來的好處?(10分)
A、省下基礎設施投資
B、省去底層人才投資
C、隨時可用最新的資源
D、獲得大量的機房管理經驗(正確答案)



 

14.下列關於彈性伸縮服務中,描述正確的是?(10分)
A、彈性伸縮服務中的服務器採用特殊軟性材質生產
B、彈性伸縮的收費形式包括按需付費和包年包月兩種
C、彈性伸縮是一種可以根據服務器壓力的不同自動增加或減少實例的服務(正確答案)
D、以上皆爲錯誤



 

15.以下關於不同租戶間網絡描述正確的是?(10分)
A、在騰訊雲中,不同租戶之間可以設置衝突的IP地址(正確答案)
B、在騰訊雲中,不同租戶之間不可以設置衝突的IP地址
C、不同租戶間網絡默認可以互相通信
D、不同租戶間無法通信



 

16.下面哪個是Docker用到的命名空間?(10分)
A、 PID命名空間
B、 NET命名空間
C、 IPC命名空間
D、以上都是(正確答案)



 

17.在Docker的描述文件Dockerfile中,RUN的含義是?(10分)
A、 定義基礎鏡像
B、 作者或者維護者
C、 運行的Linux命令(正確答案)
D、 增加文件或目錄



 

18.用戶按照Shell語言規範編寫程序並將其保存爲?(10分)
A、文件(正確答案)
B、目錄
C、壓縮包
D、圖片



 

19.Ansible的參數中inventory文件的位置在哪個目錄下_。(10分)
A、/etc/ansible.cfg
B、/etc/ansible
C、/etc/ansible/hosts(正確答案)
D、 /var/log/ansible



 

20.Python模塊,是一個Python文件,它的後綴是以_結尾。(10分)
A、.yml
B、.py(正確答案)
C、.cpp
D、.dll



 

多選題(200分):

1.下面對項目需求階段表述正確的是?(10分)
A、在軟件需求階段,要分析客戶的業務活動,確定系統的目的、範圍、定義和功能(正確答案)
B、求的調研、挖掘和整理必須由項目經理牽頭,由產品經理負責收集客戶需求(正確答案)
C、測試人員也需要參與需求分析、評審和總結(正確答案)
D、需求也是項目的靈魂,有了需求才有項目開展的可能(正確答案)



 

2.關於變更階段下面敘述錯誤的是?(10分)
A、在整個軟件開發過程中,需求變更會帶來不確定性,但是是可以避免的(正確答案)
B、按照變更的影響程度和客戶投入,可以分爲關鍵性需求、後續關鍵性需求、後續重要需求、改良型需求和可選性需求等。在時間優先級上進行管理和控制。
C、對一個需求分析做得很好的項目來說,需求規格說明書定義的範圍越詳細越清晰,用戶跟項目經理提出需求變更的機率就越小。
D、合作雙方在簽訂協議之初,書面約定不需要編寫修改要求和執行過程。(正確答案)



 

3.WLAN中常用的加密方式有? (10分)
A、wap(正確答案)
B、wep(正確答案)
C、wep2(正確答案)
D、tkip



 

4.交換網絡中的冗餘鏈路會產生? (10分)
A、廣播風暴(正確答案)
B、MAC地址表不穩定(正確答案)
C、多幀複製(正確答案)
D、交換機無法工作



 

5.下列有關Nginx配置文件nginx.conf的敘述正確的是?(10分)
A、nginx進程數設置爲CPU總核心數最佳(正確答案)
B、虛擬主機配置多個域名時,各域名間應用逗號隔開
C、sendfile on;表示爲開啓高效文件傳輸模式,對於執行下載操作等相關應用時,應設置爲on
D、設置工作模式與連接數上限時,應考慮單個進程最大連接數(最大連接數=連接數*進程數)(正確答案)



 

6.Linux系統上,下面哪些文件是與用戶管理相關的配置文件?(10分)
A、/etc/passwd(正確答案)
B、/etc/shadow(正確答案)
C、/etc/group(正確答案)
D、/etc/password



 

7.下面哪些是Swift對象存儲的特點?(10分)
A、彈性可伸縮(正確答案)
B、高可用(正確答案)
C、分佈式(正確答案)
D、集羣式



 

8.下列選項當中,哪些不是Glance查看鏡像列表的命令?(10分)
A、glance iamges-show(正確答案)
B、glance image-list
C、glance images-list(正確答案)
D、glance image-show(正確答案)



 

9.下列選項當中,哪些說法是正確的?(10分)
A、nova start是創建雲主機
B、nova restart是重啓雲主機(正確答案)
C、nova boot是啓動雲主機
D、nova reset是重建雲主機(正確答案)



 

10.AP註冊失敗的原因? (10分)
A、AP沒有上電(正確答案)
B、AP連接的網線存在問題(正確答案)
C、AP設備提供的信息不匹配(正確答案)
D、交換機設備不通(正確答案)



 

11.塊存儲服務(cinder)爲實例提供塊存儲。存儲的分配和消耗是由塊存儲驅動器,或者多後端配置的驅動器決定的。下面那些是可用的驅動程序。(10分)
A、NAS/SAN(正確答案)
B、NFS(正確答案)
C、NTFS
D、Ceph(正確答案)



 

12.下列選項當中,哪些不是Glance查看鏡像列表的命令(10分)
A、glance iamges-show(正確答案)
B、glance image-list
C、glance images-list(正確答案)
D、glance image-show(正確答案)



 

13.關於openstack組件的描述以下正確的是?(10分)
A、Heat是一個基於模板來編排複合雲應用的服務。(正確答案)
B、Cinder的核心功能是對卷的管理,允許對卷、卷的類型、快照進行處理。(正確答案)
C、Neutron網絡服務是OpenStack管理所有的網絡方面的物理網絡基礎設施和訪問層方面的虛擬網絡基礎設施
D、網絡也支持安全組。安全組允許管理員在組內定義防火牆規則。(正確答案)



 

14.騰訊雲服務器分爲上一代實例、當前一代實例、最新一代實例,若無特殊需求,一般建議新建實例時使用當前一代實例類型,下列哪些屬於當前一代實例?(10分)
A、高IO型I2(正確答案)
B、計算型C2(正確答案)
C、標準型 S1
D、內存型 M3



 

15.下列關於專用宿主機與黑石物理服務器的描述正確的是?(10分)
A、專用宿主機是基於虛擬化技術的雲服務器。黑石物理服務器屬於裸金屬架構(正確答案)
B、黑石物理服務器提供的是可以按需購買、按量付費的物理服務器租賃服務(正確答案)
C、專用宿主機是提供以獨享宿主機資源的方式購買、創建雲主機的服務(正確答案)
D、專用宿主機無法和雲服務器互相通信



 

16.相較於傳統IDC,雲計算具有哪些優勢?(10分)
A、沒有硬件購買和運維成本(正確答案)
B、無需部署和配置實體硬件,資源交付時效性高(正確答案)
C、資源可在短時間內按需彈性分配,減少資源閒置和浪費(正確答案)
D、無需部署和維護用戶自己開發的軟件



 

17.以下哪些場景適合選擇預付費(包年包月)的計費方式?(10分)
A、具有較穩定的業務場景(正確答案)
B、業務發展有較大波動性,且無法進行準確預測
C、需要長期使用雲資源,追求低成本(正確答案)
D、資源使用有臨時性和突發性



 

18.下面關於Docker容器的說法,正確的是?(10分)
A、 容器是一個鏡像的運行實例(正確答案)
B、 可以通過運行用戶指定的指令進行啓動、停止、刪除(正確答案)
C、 通過命令分配一個僞終端可以進入容器操作(正確答案)
D、 容器都是相互可見的



 

19.常見的Python網頁解析技術有_。(10分)
A、正則表達式(正確答案)
B、html.parser(正確答案)
C、lxml(正確答案)
D、Beautiful Soup(正確答案)



 

20.以下哪些是常見的Shell的種類_。(10分)
A、Bourne Shell(正確答案)
B、Bourne-Again Shell(正確答案)
C、Korn Shell(正確答案)
D、Z Shell(正確答案)



 

實操題(600分):

 

1.交換機管理(40分)

在eNSP中使用S5700交換機進行配置,通過一條命令劃分vlan 2、vlan 3、vlan 1004,通過端口組的方式配置端口1-5爲access模式,並添加至vlan2中。配置端口10爲trunk模式,並放行vlan3。創建三層vlan 2,配置IP地址爲:172.16.2.1/24,創建三層vlan1004,配置IP地址爲:192.168.4.2/30。通過命令添加默認路由,下一跳爲192.168.4.1。(使用完整命令)將上述操作命令及返回結果以文本形式提交到答題框。

SW1配置:

<Huawei>system-view
[Huawei]sysname SW1
[SW1]vlan batch 2 3 1004
[SW1]port-group 1
[SW1-port-group-1]group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/5
[SW1-port-group-1]port link-type access
[SW1-port-group-1]port default vlan 2
[SW1]interface GigabitEthernet 0/0/10
[SW1-GigabitEthernet0/0/10]port link-type trunk
[SW1-GigabitEthernet0/0/10]port trunk allow-pass vlan 3
[SW1-GigabitEthernet0/0/10]quit
[SW1]interface Vlanif 2
[SW1-Vlanif2]ip address 172.16.2.1 24
[SW1-Vlanif2]quit
[SW1]interface Vlanif 1004
[SW1-Vlanif1004]ip address 192.168.4.2 30
[SW1-Vlanif1004]quit
[SW1]ip route-static 0.0.0.0 0 192.168.4.1

 

2.交換機管理(40分)

交換機配置:交換機g0/0/1端口連接R1路由器,所屬vlan1001,配置地址192.168.1.2/30,與路由器通信。配置g0/0/2連接PC1機,所屬vlan101,配置PC1機網關地址爲172.16.101.254/24。配置默認路由下一跳爲路由器地址。路由器配置:R1路由器g0/0/1端口配置地址12.12.12.1/30,配置端口多路複用PAT配置。R1路由器g0/0/2端口配置地址192.168.1.1/30,連接交換機。路由器配置默認路由訪問外部網絡,配置靜態路由訪問PC機網絡。(所有配置命令使用完整命令)將上述操作命令及返回結果以文本形式提交到答題框。

 

架構圖(考試時命令對就行了,只用 一臺SW1和R1就夠了,但爲了學到東西所以練習時採用完整的部署方案)

SW1配置:

system-view
[Huawei]sysname SW1
[SW1]vlan batch 101 1001
[SW1]interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1]port link-type access
[SW1-GigabitEthernet0/0/1]port default vlan 1001
[SW1-GigabitEthernet0/0/1]quit
[SW1]interface vlan 1001
[SW1-Vlanif1001]ip address 192.168.1.2 30
[SW1-Vlanif1001]quit
[SW1]interface GigabitEthernet 0/0/2
[SW1-GigabitEthernet0/0/2]port link-type access
[SW1-GigabitEthernet0/0/2]port default vlan 101
[SW1-GigabitEthernet0/0/2]quit
[SW1]interface vlan 101
[SW1-Vlanif101]ip address 172.16.101.254 24
[SW1-Vlanif101]quit
[SW1]ip route-static 0.0.0.0 0 192.168.1.1

 

R1配置:

system-view
[Huawei]sysname R1
[R1]acl number 2000
[R1-acl-basic-2000]rule 1 permit
[R1-acl-basic-2000]quit
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 12.12.12.1 30
[R1-GigabitEthernet0/0/1]nat outbound 2000
[R1-GigabitEthernet0/0/1]quit
[R1]interface GigabitEthernet 0/0/2
[R1-GigabitEthernet0/0/2]ip address 192.168.1.1 30
[R1-GigabitEthernet0/0/2]quit
[R1]ip route-static 0.0.0.0 0 GigabitEthernet 0/0/1
[R1]ip route-static 172.16.101.0 255.255.255.0 192.168.1.2

 

結果(看一下連通性):

先查看PC1能不能ping通交換機和路由

在使用R1路由看看能不能ping通外網

 

3.YUM源管理(40分)

假設當前有一個centos7.2-1511.iso的鏡像文件,使用這個文件配置yum源,要求將這個鏡像文件掛載在/opt/centos目錄。還存在一個ftp源,IP地址爲192.168.100.200,ftp配置文件中配置爲anon_root=/opt,/opt目錄中存在一個iaas目錄(該目錄下存在一個repodata目錄)請問如何配置自己的local.repo文件,使得可以使用這兩個地方的軟件包,安裝軟件。請將local.repo文件的內容以文本形式提交到答題框。

Xserver1:

[root@xserver1 ~]# yum install -y vsftpd
[root@xserver1 ~]# vim /etc/vsftpd/vsftpd.conf 
anon_root=/opt
[root@xserver1 ~]# systemctl restart vsftpd
[root@xserver1 ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@xserver1 ~]# systemctl stop firewalld
[root@xserver1 ~]# systemctl disable firewalld
# 註釋:selinux防火牆,設置訪問模式(得重啓才生效):
[root@xserver1 ~]# vim /etc/selinux/config 
SELINUX=Permissive
# 註釋:配置臨時訪問模式(無需重啓):
[root@xserver1 ~]# setenforce 0
[root@xserver1 ~]# getenforce 
Permissive

 

Xserver2:

[root@xserver2 ~]# systemctl stop firewalld
[root@xserver2 ~]# systemctl disable firewalld
# 註釋:selinux防火牆,設置訪問模式(得重啓才生效):
[root@xserver2 ~]# vim /etc/selinux/config 
SELINUX=Permissive
# 註釋:配置臨時訪問模式(無需重啓):
[root@xserver2 ~]# setenforce 0
[root@xserver2 ~]# getenforce 
Permissive
[root@xserver2 ~]# mount -o loop CentOS-7-x86_64-DVD-1511.iso /opt/centos/
mount: /dev/loop0 is write-protected, mounting read-only
[root@xserver2 ~]# cat /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[iaas]
name=iaas
baseurl=ftp://192.168.100.200/iaas
enabled=1
gpgcheck=0

 

4.Raid存儲管理(40分)

登錄雲主機,在雲主機中,存在一個大小爲20G的硬盤爲/dev/vdb,使用fdisk命令對該硬盤進形分區,要求分出兩個大小爲5G的分區。使用這兩個分區,創建名爲/dev/md0、raid級別爲1的磁盤陣列。創建完成後使用xfs文件系統進形格式化,並掛載到/mnt目錄下。將mdadm -D /dev/md0命令和df -h命令返回得結果以文本形式提交到答題框。

  • 因爲我用的是CentOS7系統做的實驗所以磁盤是sdb,CentOS6磁盤是vdb:
[root@xiandian ~]# fdisk /dev/sdb 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb7634785.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (10487808-41943039, default 10487808): 
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 GiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (20973568-41943039, default 20973568): 
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +5G
Partition 3 of type Linux and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@xiandian ~]# yum install -y mdadm
[root@xserver1 ~]# mdadm -Cv /dev/md0 -l1 -n2 /dev/sdb[1-2]
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: size set to 5237760K
Continue creating array? y
mdadm: Fail create md0 when using /sys/module/md_mod/parameters/new_array
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# 註釋:可以查看一下進度:
[root@xserver1 ~]# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sdb2[1] sdb1[0]
      5237760 blocks super 1.2 [2/2] [UU]
      [======>..............]  resync = 30.5% (1601792/5237760) finish=0.3min speed=200224K/sec 
unused devices: <none>
[root@xserver1 ~]# mkfs.xfs /dev/md0 
meta-data=/dev/md0               isize=256    agcount=4, agsize=327360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=1309440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@xserver1 ~]# mount /dev/md0 /mnt/
[root@xserver1 ~]# mdadm -D /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Thu May 14 09:15:04 2020
        Raid Level : raid1
        Array Size : 5237760 (5.00 GiB 5.36 GB)
     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent
       Update Time : Thu May 14 09:20:57 2020
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0
Consistency Policy : unknown
              Name : xserver1:0  (local to host xserver1)
              UUID : 8440d04c:3cf2e84a:4d524020:1072f7b4
            Events : 17
    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2
[root@xserver1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   32G  5.2G   27G  17% /
devtmpfs                 903M     0  903M   0% /dev
tmpfs                    913M     0  913M   0% /dev/shm
tmpfs                    913M  8.6M  904M   1% /run
tmpfs                    913M     0  913M   0% /sys/fs/cgroup
/dev/sda1                509M  125M  384M  25% /boot
/dev/mapper/centos-home  4.0G   33M  4.0G   1% /home
tmpfs                    183M     0  183M   0% /run/user/0
/dev/md0                 5.0G   33M  5.0G   1% /mnt

 

5.主從數據庫管理(40分)

使用提供的兩臺虛擬機,在虛擬機上安裝mariadb數據庫,並配置爲主從數據庫,實現兩個數據庫的主從同步。配置完畢後,請在從節點上的數據庫中執行“show slave status \G”命令查詢從節點複製狀態,將查詢到的結果以文本形式提交到答題框。

  • 上傳gpmall-repo中有mariadb子文件的文件到/root目錄下:

Mysql1:

[root@xiandian ~]# hostnamectl set-hostname mysql1
[root@mysql1 ~]# login
[root@mysql1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.111    mysql1
192.168.1.112    mysql2
[root@mysql1 ~]# systemctl stop firewalld
[root@mysql1 ~]# systemctl disable firewalld
[root@mysql1 ~]# setenforce 0
[root@mysql1 ~]# vim /etc/selinux/config 
SELINUX=Permissive
[root@mysql1~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[mariadb]
name=mariadb
baseurl=file:///root/gpmall-repo
enabled=1
gpgcheck=0
[root@mysql1 ~]# yum install -y mariadb mariadb-server
[root@mysql1 ~]# systemctl restart mariadb
[root@mysql1 ~]# mysql_secure_installation
[root@mysql1 ~]# vim /etc/my.cnf
# 註釋:在[mysqld]下添加:
log_bin = mysql-bin
binlog_ignore_db = mysql
server_id = 10
[root@mysql1 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '000000';
Query OK, 0 rows affected (0.00 sec)

# 註釋:如果你不想配置上面的host文件可以不使用主機名mysql2的形式,可以直接打IP地址,用戶可以隨意指定,只是一個用於連接的而已
MariaDB [(none)]> grant replication slave on *.* to 'user'@'mysql2' identified by '000000';
Query OK, 0 rows affected (0.00 sec)

 

Mysql2:

[root@xiandian ~]# hostnamectl set-hostname mysql2
[root@mysql2 ~]# login
[root@mysql2 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.111   mysql1
192.168.1.112   mysql2
[root@mysql2 ~]# systemctl stop firewalld
[root@mysql2 ~]# systemctl disable firewalld
[root@mysql2 ~]# setenforce 0
[root@mysql2 ~]# vim /etc/selinux/config 
SELINUX=Permissive
[root@mysql2~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[mariadb]
name=mariadb
baseurl=file:///root/gpmall-repo
enabled=1
gpgcheck=0
[root@mysql2 ~]# yum install -y mariadb mariadb-server
[root@mysql2 ~]# systemctl restart mariadb
[root@mysql2 ~]# mysql_secure_installation
[root@mysql2 ~]# vim /etc/my.cnf
# 註釋:在[mysqld]下添加:
log_bin = mysql-bin
binlog_ignore_db = mysql
server_id = 20
[root@mysql2 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 註釋:如果你不想配置上面的host文件可以不使用主機名mysql1的形式,可以直接打IP地址,這裏的用戶,密碼必須和上面mysql1配置的user一致
MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql1
Master_User: user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 245
Relay_Log_File: mariadb-relay-bin.000005
Relay_Log_Pos: 529
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 245
Relay_Log_Space: 1256
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 30
1 row in set (0.00 sec)

 

驗證結果(主從是否同步):

Mysql1:

[root@mysql1 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database test;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> use test;
Database changed
MariaDB [test]> create table demotables(id int not null primary key,name varchar(10),addr varchar(20));
Query OK, 0 rows affected (0.01 sec)
MariaDB [test]> insert into demotables values(1,'zhangsan','lztd');
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> select * from demotables;
+----+----------+------+
| id | name     | addr |
+----+----------+------+
|  1 | zhangsan | lztd |
+----+----------+------+
1 rows in set (0.00 sec)

 

Mysql2:

[root@mysql2 ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| demotables     |
+----------------+
1 row in set (0.00 sec)
MariaDB [test]> select * from demotables;
+----+----------+------+
| id | name     | addr |
+----+----------+------+
|  1 | zhangsan | lztd |
+----+----------+------+
1 rows in set (0.00 sec)

 

6.讀寫分離數據庫管理(40分)

使用提供的虛擬機與軟件包,基於上一題構建的主從數據庫,進一步完成Mycat讀寫分離數據庫的配置安裝。需要用的配置文件schema.xml文件如下所示(server.xml文件不再給出): select user() 配置讀寫分離數據庫完畢後,使用netstat -ntpl命令查詢端口啓動情況。最後將netstat -ntpl命令的返回結果以文本形式提交到答題框。

Mycat & Mysql1 & Mysql2都執行以下操作:

# 註釋:這個其實配不配都可以,看個人喜歡用主機名還是IP地址咯
[root@mycat ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.111    mysql1
192.168.1.112    mysql2
192.168.1.113    mycat

 

Mycat:

  • 上傳gpmall-repo中有mariadb子文件的文件和Mycat-server-1.6-RELEASE-20161028204710-linux.gz到/root目錄下,並配置yum源:
[root@mycat ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.111   mysql1
192.168.1.112   mysql2
192.168.1.113   mycat
[root@mycat~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[mariadb]
name=mariadb
baseurl=file:///root/gpmall-repo
enabled=1
gpgcheck=0
[root@mycat ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@mycat ~]# tar -zvxf Mycat-server-1.6-RELEASE-20161028204710-linux.gz -C /usr/local/
[root@mycat ~]# chown -R 777 /usr/local/mycat/
[root@mycat ~]# vim /etc/profile
export MYCAT_HOME=/usr/local/mycat/
[root@mycat ~]# source /etc/profile
[root@mycat ~]# vim /usr/local/mycat/conf/schema.xml
<?xml version='1.0'?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!--註釋:name=USERDB指的是邏輯數據庫,在後面添加一個dataNode="dn1",dn1上綁定的是真是數據庫-->
<schema name="USERDB" checkSQLschema="true" sqlMaxLimit="100" 
dataNode="dn1"></schema>
<!--註釋:name="dn1"上面與邏輯數據庫引用的名稱,database="test"真實數據庫名字-->
<dataNode name="dn1" dataHost="localhost1" database="test" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" dbType="mysql" 
dbDriver="native" writeType="0" switchType="1" slaveThreshold="100">
 <heartbeat>select user()</heartbeat>
 <writeHost host="hostM1" url="192.168.1.111:3306" user="root" password="000000">
 <readHost host="hostS1" url="192.168.1.112:3306" user="root" password="000000" />
 </writeHost>
</dataHost>
</mycat:schema>
[root@mycat ~]# chown root:root /usr/local/mycat/conf/schema.xml
# 註釋:修改root用戶的訪問密碼與數據庫
[root@mycat ~]# vim /usr/local/mycat/conf/server.xml
        <user name="root">
                <property name="password">000000</property>
                <property name="schemas">USERDB</property>

                <!-- 表級 DML 權限設置 -->
                <!--            
                <privileges check="false">
                        <schema name="TESTDB" dml="0110" >
                                <table name="tb01" dml="0000"></table>
                                <table name="tb02" dml="1111"></table>
                        </schema>
                </privileges>           
                 -->
        </user>
# 註釋:刪除之後的<user name="user"></user>的標籤與內容
[root@mycat ~]# /bin/bash /usr/local/mycat/bin/mycat start
Starting Mycat-server...
[root@mycat ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1114/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1992/master         
tcp        0      0 127.0.0.1:32000         0.0.0.0:*               LISTEN      3988/java           
tcp6       0      0 :::45929                :::*                    LISTEN      3988/java           
tcp6       0      0 :::9066                 :::*                    LISTEN      3988/java           
tcp6       0      0 :::40619                :::*                    LISTEN      3988/java           
tcp6       0      0 :::22                   :::*                    LISTEN      1114/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1992/master         
tcp6       0      0 :::1984                 :::*                    LISTEN      3988/java           
tcp6       0      0 :::8066                 :::*                    LISTEN      3988/java   
# 註釋:驗證結果(讀寫分離是否成功):
[root@mycat ~]# yum install -y MariaDB-client
# 註釋:查看邏輯庫
[root@mycat ~]# mysql -h 127.0.0.1 -P8066 -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| USERDB   |
+----------+
1 row in set (0.003 sec)

MySQL [(none)]> use USERDB
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [USERDB]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| demotables     |
+----------------+
1 row in set (0.007 sec)

MySQL [USERDB]> select * from demotables;
+----+----------+------+
| id | name     | addr |
+----+----------+------+
|  1 | zhangsan | lztd |
|  2 | xiaohong | lztd |
|  3 | xiaoli   | lztd |
|  4 | lihua    | nnzy |
+----+----------+------+
4 rows in set (0.060 sec)

MySQL [USERDB]> insert into demotables values(5,'tomo','hfdx');
Query OK, 1 row affected (0.013 sec)

MySQL [USERDB]> select * from demotables;
+----+----------+------+
| id | name     | addr |
+----+----------+------+
|  1 | zhangsan | lztd |
|  2 | xiaohong | lztd |
|  3 | xiaoli   | lztd |
|  4 | lihua    | nnzy |
|  5 | tomo     | hfdx |
+----+----------+------+
5 rows in set (0.004 sec)

MySQL [USERDB]> exit;
Bye
# 註釋:查詢對數據庫讀寫操作的分離信息
[root@mycat ~]# mysql -h 127.0.0.1 -P9066 -uroot -p000000 -e 'show @@datasource;'
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+
| DATANODE | NAME   | TYPE  | HOST          | PORT | W/R  | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD |
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+
| dn1      | hostM1 | mysql | 192.168.1.111 | 3306 | W    |      0 |   10 | 1000 |      45 |         0 |          1 |
| dn1      | hostS1 | mysql | 192.168.1.112 | 3306 | R    |      0 |    6 | 1000 |      43 |         4 |          0 |
+----------+--------+-------+---------------+------+------+--------+------+------+---------+-----------+------------+

 

一些參數註釋:

sqlMaxLimit 配置默認查詢數量
database 爲真實數據庫名
balance="0" 不開啓讀寫分離機制,所有讀操作都發送到當前可用的writeHost上
balance="1" 全部的readHost與stand by writeHost參與select語句的負載均衡,簡單來說,當雙主雙從模式(M1->S1,M2->S2,並且M1與M2互爲主備),正常情況下,M2、S1、S2都參與select語句的負載均衡
balance="2" 所有讀操作都隨機的在writeHost、readhost上分發
balance="3" 所有讀請求隨機地分發到wiriterHost對應的readhost執行,writerHost不負擔讀壓力,注意balance=3只在1.4及其以後版本有,1.3版本沒有
writeType="0" 所有寫操作發送到配置的第一個writeHost,第一個掛了需要切換到還生存的第二個writeHost,重新啓動後已切換後的爲準,切換記錄在配置文件dnindex.properties中
writeType="1" 所有寫操作都隨機的發送到配置的writeHost






 

7.Zookeeper集羣(40分)

使用提供的三臺虛擬機和軟件包,完成Zookeeper集羣的安裝與配置,配置完成後,在相應的目錄使用./zkServer.sh status命令查看三個Zookeeper節點的狀態,將三個節點的狀態以文本形式提交到答題框。

Zookeeper1:

[root@xiandian ~]# hostnamectl set-hostname zookeeper1
[root@xiandian ~]# bash
[root@zookeeper1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.10    zookeeper1
192.168.1.20    zookeeper2
192.168.1.30    zookeeper3
# 註釋:在zookeeper1節點上傳gpmall-repo,然後做vsftp進行共享,我上傳到/opt
[root@zookeeper1 ~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
enabled=1
gpgcheck=0
[root@zookeeper1 ~]# yum repolist
[root@zookeeper1 ~]# yum install -y vsftpd
[root@zookeeper1 ~]# vim /etc/vsftpd/vsftpd.conf 
# 註釋:添加:
anon_root=/opt
[root@zookeeper1 ~]# systemctl restart vsftpd
[root@zookeeper1 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@zookeeper1 ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
# 註釋:將zookeeper-3.4.14.tar.gz上傳至三個節點或者設置nfs進行共享
[root@zookeeper1 ~]# tar -zvxf zookeeper-3.4.14.tar.gz
[root@zookeeper1 ~]# cd zookeeper-3.4.14/conf/
[root@zookeeper1 conf]# mv zoo_sample.cfg zoo.cfg
[root@zookeeper1 conf]# vim zoo.cfg 
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.1.10:2888:3888
server.2=192.168.1.20:2888:3888
server.3=192.168.1.30:2888:3888
[root@zookeeper1 conf]# grep -n '^'[a-Z] zoo.cfg 
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/tmp/zookeeper
14:clientPort=2181
29:server.1=192.168.1.10:2888:3888
30:server.2=192.168.1.20:2888:3888
31:server.3=192.168.1.30:2888:3888
[root@zookeeper1 conf]# cd 
[root@zookeeper1 ~]# mkdir /tmp/zookeeper
[root@zookeeper1 ~]# vim /tmp/zookeeper/myid
1
[root@zookeeper1 ~]# cat /tmp/zookeeper/myid 
1
[root@zookeeper1 ~]# cd zookeeper-3.4.14/bin/
[root@zookeeper1 bin]# ./zkServer.sh start
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper1 bin]# ./zkServer.sh status
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

 

Zookeeper2:

[root@xiandian ~]# hostnamectl set-hostname zookeeper2
[root@xiandian ~]# bash
[root@zookeeper2 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.10    zookeeper1
192.168.1.20    zookeeper2
192.168.1.30    zookeeper3
[root@zookeeper2 ~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[gpmall]
name=gpmall
baseurl=ftp://zookeeper1/gpmall-repo
enabled=1
gpgcheck=0
[root@zookeeper2 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@zookeeper2 ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
# 註釋:將zookeeper-3.4.14.tar.gz上傳至三個節點或者設置nfs進行共享
[root@zookeeper2 ~]# tar -zvxf zookeeper-3.4.14.tar.gz
[root@zookeeper2 ~]# cd zookeeper-3.4.14/conf/
[root@zookeeper2 conf]# mv zoo_sample.cfg zoo.cfg
[root@zookeeper2 conf]# vim zoo.cfg 
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.1.10:2888:3888
server.2=192.168.1.20:2888:3888
server.3=192.168.1.30:2888:3888
[root@zookeeper2 conf]# grep -n '^'[a-Z] zoo.cfg 
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/tmp/zookeeper
14:clientPort=2181
29:server.1=192.168.1.10:2888:3888
30:server.2=192.168.1.20:2888:3888
31:server.3=192.168.1.30:2888:3888
[root@zookeeper2 conf]# cd 
[root@zookeeper2 ~]# mkdir /tmp/zookeeper
[root@zookeeper2 ~]# vim /tmp/zookeeper/myid
2
[root@zookeeper1 ~]# cat /tmp/zookeeper/myid 
2
[root@zookeeper2 ~]# cd zookeeper-3.4.14/bin/
[root@zookeeper2 bin]# ./zkServer.sh start
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper2 bin]# ./zkServer.sh status
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader

 

Zookeeper3:

[root@xiandian ~]# hostnamectl set-hostname zookeeper3
[root@xiandian ~]# bash
[root@zookeeper3 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.10    zookeeper1
192.168.1.20    zookeeper2
192.168.1.30    zookeeper3
[root@zookeeper3 ~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[gpmall]
name=gpmall
baseurl=ftp://zookeeper1/gpmall-repo
enabled=1
gpgcheck=0
[root@zookeeper3 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@zookeeper3 ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
# 註釋:將zookeeper-3.4.14.tar.gz上傳至三個節點或者設置nfs進行共享
[root@zookeeper3 ~]# tar -zvxf zookeeper-3.4.14.tar.gz
[root@zookeeper3 ~]# cd zookeeper-3.4.14/conf/
[root@zookeeper3 conf]# mv zoo_sample.cfg zoo.cfg
[root@zookeeper3 conf]# vim zoo.cfg 
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.1.10:2888:3888
server.2=192.168.1.20:2888:3888
server.3=192.168.1.30:2888:3888
[root@zookeeper3 conf]# grep -n '^'[a-Z] zoo.cfg 
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/tmp/zookeeper
14:clientPort=2181
29:server.1=192.168.1.10:2888:3888
30:server.2=192.168.1.20:2888:3888
31:server.3=192.168.1.30:2888:3888
[root@zookeeper3 conf]# cd 
[root@zookeeper3 ~]# mkdir /tmp/zookeeper
[root@zookeeper3 ~]# vim /tmp/zookeeper/myid
3
[root@zookeeper3 ~]# cat /tmp/zookeeper/myid 
3
[root@zookeeper3 ~]# cd zookeeper-3.4.14/bin/
[root@zookeeper3 bin]# ./zkServer.sh start
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@zookeeper3 bin]# ./zkServer.sh status
zookeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

 

8.Kafka集羣(40分)

使用提供的三臺虛擬機和軟件包,完成Kafka集羣的安裝與配置,配置完成後,在相應的目錄使用 ./kafka-topics.sh --create --zookeeper 你的IP:2181 --replication-factor 1 --partitions 1 --topic test創建topic,將輸入命令後的返回結果以文本形式提交到答題框。

  • 將kafka_2.11-1.1.1.tgz上傳至三個節點:(可以在上體的基礎上做kafka,因爲kafka依賴於zookeeper)

Zookeeper1:

[root@zookeeper1 ~]# tar -zvxf kafka_2.11-1.1.1.tgz
[root@zookeeper1 ~]# cd kafka_2.11-1.1.1/config/
[root@zookeeper1 config]# vim server.properties
把broker.id=0和zookeeper.connect=localhost:2181使用#註釋掉可以使用在vim中/加要搜索的名字,來查找,並添加三行新的內容:
#broker.id=0
#zookeeper.connect=localhost:2181
broker.id = 1
zookeeper.connect = 192.168.1.10:2181,192.168.1.20:2181,192.168.1.30:2181
listeners = PLAINTEXT://192.168.1.10:9092

[root@zookeeper1 config]# cd /root/kafka_2.11-1.1.1/bin/
[root@zookeeper1 bin]# ./kafka-server-start.sh -daemon ../config/server.properties 
[root@zookeeper1 bin]# jps
17645 QuorumPeerMain
18029 Kafka
18093 Jps
# 註釋:創建topic(下面的IP請設置爲自己節點的IP):
[root@zookeeper1 bin]# ./kafka-topics.sh --create --zookeeper 192.168.1.10:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
# 註釋:測試結果:
[root@zookeeper1 bin]# ./kafka-topics.sh --list --zookeeper 192.168.1.10:2181
test

 

Zookeeper2:

[root@zookeeper2 ~]# tar -zvxf kafka_2.11-1.1.1.tgz
[root@zookeeper2 ~]# cd kafka_2.11-1.1.1/config/
[root@zookeeper2 config]# vim server.properties
# 註釋:把broker.id=0和zookeeper.connect=localhost:2181使用#註釋掉可以使用在vim中/加要搜索的名字,來查找,並添加三行新的內容:
#broker.id=0
#zookeeper.connect=localhost:2181
broker.id = 2
zookeeper.connect = 192.168.1.10:2181,192.168.1.20:2181,192.168.1.30:2181
listeners = PLAINTEXT://192.168.1.20:9092

[root@zookeeper2config]# cd /root/kafka_2.11-1.1.1/bin/
[root@zookeeper2 bin]# ./kafka-server-start.sh -daemon ../config/server.properties 
[root@zookeeper2 bin]# jps
3573 Kafka
3605 Jps
3178 QuorumPeerMain
# 註釋:測試結果:
[root@zookeeper2 bin]# ./kafka-topics.sh --list --zookeeper 192.168.1.20:2181
test

 

Zookeeper3:

[root@zookeeper3 ~]# tar -zvxf kafka_2.11-1.1.1.tgz
[root@zookeeper3 ~]# cd kafka_2.11-1.1.1/config/
[root@zookeeper3 config]# vim server.properties
# 註釋:把broker.id=0和zookeeper.connect=localhost:2181使用#註釋掉可以使用在vim中/加要搜索的名字,來查找,並添加三行新的內容:
#broker.id=0
#zookeeper.connect=localhost:2181
broker.id = 3
zookeeper.connect = 192.168.1.10:2181,192.168.1.20:2181,192.168.1.30:2181
listeners = PLAINTEXT://192.168.1.30:9092

[root@zookeeper3 config]# cd /root/kafka_2.11-1.1.1/bin/
[root@zookeeper3 bin]# ./kafka-server-start.sh -daemon ../config/server.properties 
[root@zookeeper3 bin]# jps 
3904 QuorumPeerMain
4257 Kafka
4300 Jps
# 註釋:測試結果:
[root@zookeeper3 bin]# ./kafka-topics.sh --list --zookeeper 192.168.1.30:2181
test

 

9.應用商城系統(40分)

繼續使用上題的三臺虛擬機,使用提供的軟件包,基於集羣應用系統部署。部署完成後,進行登錄,(訂單中填寫的收貨地址填寫自己學校的地址,收貨人填寫自己的實際聯繫方式)最後使用curl命令去獲取商城首頁的返回信息,將curl http://你自己的商城IP/#/home獲取到的結果以文本形式提交到答題框。

  • 將所需的zookeep,kafka和gpmall-repo的包上傳到mall虛擬機(按題目要求的答案,其實單節點也一樣,推薦單節點部署,集羣部署,看大家是否需要,需要的話評論一下,我到時候更新集羣部署):
[root@mall ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.111   mall
192.168.1.111   kafka.mall
192.168.1.111   redis.mall
192.168.1.111   mysql.mall
192.168.1.111   zookeeper.mall
[root@mall ~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[gpmall]
name=gpmall
baseurl=file:///root/gpmall-repo
enabled=1
gpgcheck=0 
[root@mall ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@mall ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
[root@mall ~]# yum install -y redis
[root@mall ~]# yum install -y nginx
[root@mall ~]# yum install -y mariadb mariadb-server
[root@mall ~]# tar -zvxf zookeeper-3.4.14.tar.gz
[root@mall ~]# cd zookeeper-3.4.14/conf
[root@mall conf]# mv zoo_sample.cfg zoo.cfg
[root@mall conf]# cd /root/zookeeper-3.4.14/bin/
[root@mall bin]# ./zkServer.sh start
[root@mall bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
[root@mall bin]# cd
[root@mall ~]# tar -zvxf kafka_2.11-1.1.1.tgz
[root@mall ~]# cd kafka_2.11-1.1.1/bin/
[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@mall bin]# jps 
7249 Kafka
17347 Jps
6927 QuorumPeerMain
[root@mall bin]# cd
[root@mall ~]# vim /etc/my.cnf
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
[root@mall ~]# systemctl restart mariadb
[root@mall ~]# systemctl enable mariadb
[root@mall ~]# mysqladmin -uroot password 123456
[root@mall ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> source /root/gpmall-xiangmubao-danji/gpmall.sql
MariaDB [gpmall]> Ctrl-C -- exit!
[root@mall ~]# vim /etc/redis.conf
# 註釋:將bind 127.0.0.1這一行註釋掉;將protected-mode yes 改爲 protected-mode no
#bind 127.0.0.1
Protected-mode no
[root@mall ~]# systemctl restart redis
[root@mall ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[root@mall ~]# rm -rf /usr/share/nginx/html/*
[root@mall ~]# cp -rf gpmall-xiangmubao-danji/dist/* /usr/share/nginx/html/
[root@mall ~]# vim /etc/nginx/conf.d/default.conf
# 註釋:在server塊中添加三個location塊
server {
...
    location /user {
        proxy_pass http://127.0.0.1:8082;
    }   

    location /shopping {
        proxy_pass http://127.0.0.1:8081;
    }

    location /cashier {
        proxy_pass http://127.0.0.1:8083;
    }
...
}
[root@mall ~]# systemctl restart nginx
[root@mall ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@mall ~]# cd gpmall-xiangmubao-danji/
[root@mall gpmall-xiangmubao-danji]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 3531
[root@mall gpmall-xiangmubao-danji]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-xiangmubao-danji]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 3571
[root@mall gpmall-xiangmubao-danji]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-xiangmubao-danji]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 3639
[root@mall gpmall-xiangmubao-danji]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-xiangmubao-danji]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 3676
[root@mall gpmall-xiangmubao-danji]# nohup: ignoring input and appending output to ‘nohup.out’

[root@mall gpmall-xiangmubao-danji]# jobs
[1]   Running          nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[2]   Running          nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[3]-   Running          nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[4]+  Running          nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[root@mall gpmall-xiangmubao-danji]# curl http://192.168.1.111/#/home
<!DOCTYPE html><html><head><meta charset=utf-8><title>1+x-示例項目</title><meta name=keywords content=""><meta name=description content=""><meta http-equiv=X-UA-Compatible content="IE=Edge"><meta name=wap-font-scale content=no><link rel="shortcut icon " type=images/x-icon href=/static/images/favicon.ico><link href=/static/css/app.8d4edd335a61c46bf5b6a63444cd855a.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.2d17a82764acff8145be.js></script><script type=text/javascript src=/static/js/vendor.4f07d3a235c8a7cd4efe.js></script><script type=text/javascript src=/static/js/app.81180cbb92541cdf912f.js></script></body></html><style>body{
min-width:1250px;}</style>

 

10.Keystone管理(40分)

使用提供的“all-in-one”虛擬機,在keystone中創建用戶testuser,密碼爲password,創建好之後,查看testuser的詳細信息,以文本形式提交以上操作命令到答題框。

[root@xiandian~]# source /etc/keystone/admin-openrc.sh
[root@xiandian~]# openstack user create  --domain xiandian  --password password testuser
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | 5a486c51bc8e4dffa4a181f6c54e0938 |
| enabled   | True                             |
| id        | ec6d67cdb3ac4b3ca827587c14be0a3e |
| name      | testuser                         |
+-----------+----------------------------------+
[root@xiandian~]# openstack user show testuser
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | 639e7d52170d4759b5438e3b29bbf339 |
| enabled   | True                             |
| id        | df8ca15f17a8435d8889987b4b78c7a2 |
| name      | testuser                         |
+-----------+----------------------------------+ 

 

11.對象存儲管理(40分)

使用提供的“all-in-one”虛擬機,使用openstack命令,創建名爲examtest的容器並查詢,上傳一個aaa.txt(可自行創建)文件到這個容器中並查詢。依次將操作命令和返回結果以文本形式提交到答題框。

[root@xiandian ~]# openstack container create examtest
+---------------------------------------+-----------+------------------------------------+
| account                               | container | x-trans-id                         |  
+---------------------------------------+-----------+------------------------------------+
| AUTH_0ab2dbde4f754b699e22461426cd0774 | examtest  | tx9e7b54f8042d4a6ca5ccf-005a93daf3 |
+---------------------------------------+-----------+------------------------------------+
[root@xiandian ~]# openstack container list
+----------+
| Name     |
+----------+
| examtest |
+----------+
[root@xiandian ~]# openstack object create examtest aaa.txt
+---------+-----------+----------------------------------+
| object  | container | etag                             |
+---------+-----------+----------------------------------+
| aaa.txt | examtest  | 45226aa24b72ce0ccc4ff73eefe2e26f |
+---------+-----------+----------------------------------+
[root@xiandian ~]# openstack object list examtest
+---------+
| Name    |
+---------+
| aaa.txt |
+---------+

 

12.Glance管理(40分)

登錄“all-in-one”節點,使用crt的傳輸工具將提供的cirros-0.3.4-x86_64-disk.img鏡像上傳至“all-in-one”節點的/root目錄下;使用glance命令將鏡像上傳,並命名爲mycirros,最後使用glance命令查看該鏡像的詳細信息。將上述所有操作命令和返回結果以文本形式提交到答題框。

[root@xiandian ~]# source /etc/keystone/admin-openrc.sh
[root@xiandian ~]# glance image-create  --name mycirros  --disk-format qcow2  --container-format bare  --progress  <  cirros-0.3.4-x86_64-disk.img
[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2019-10-24T10:16:52Z                 |
| disk_format      | qcow2                                |
| id               | d3663be2-3ebf-443a-b3fc-b3e39bda8783 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | mycirros                             |
| owner            | 0ab2dbde4f754b699e22461426cd0774     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2019-10-24T10:16:52Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+
[root@xiandian ~]# glance image-show d3663be2-3ebf-443a-b3fc-b3e39bda8783
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2019-10-24T10:16:52Z                 |
| disk_format      | qcow2                                |
| id               | d3663be2-3ebf-443a-b3fc-b3e39bda8783 |
| min_disk         | 0                                    | 
| min_ram          | 0                                    |
| name             | mycirros                             |
| owner            | 0ab2dbde4f754b699e22461426cd0774     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2019-10-24T10:16:52Z                 |
| virtual_size     | None                                 |
| visibility       | private                              |
+------------------+--------------------------------------+

 

13.Docker安裝(40分)

使用提供的虛擬機和軟件包,自行配置YUM源,安裝docker-ce服務。安裝完畢後執行docker info命令的返回結果以文本形式提交到答題框。

  • 先上傳Docker.tar.gz到/root目錄,並解壓:
[root@xiandian ~]# tar -zvxf Docker.tar.gz
[root@xiandian ~]# vim /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
[docker]
name=docker
baseurl=file:///root/Docker
enabled=1
gpgcheck=0
[root@xiandian ~]# iptables -F
[root@xiandian ~]# iptables -X
[root@xiandian ~]# iptables -Z
[root@xiandian ~]# iptables-save 
# Generated by iptables-save v1.4.21 on Fri May 15 02:00:29 2020
*filter
:INPUT ACCEPT [20:1320]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [11:1092]
COMMIT
# Completed on Fri May 15 02:00:29 2020
[root@xiandian ~]# vim /etc/selinux/config 
SELINUX=disabled
# 註釋:關閉交換分區:
[root@xiandian ~]# vim /etc/fstab 
#/dev/mapper/centos-swap swap            swap    defaults        0 0
[root@xiandian ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1824          95        1591           8         138        1589
Swap:             0           0           0
# 註釋:在配置路由轉發前,先升級系統並重啓,不然會有兩條規則可能報錯:
[root@xiandian ~]# yum upgrade -y
[root@xiandian ~]# reboot
[root@xiandian ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
[root@xiandian ~]# modprobe br_netfilter
[root@xiandian ~]# sysctl -p
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
[root@xiandian ~]# yum install -y yum-utils device-mapper-persistent-data
[root@xiandian ~]# yum install -y docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io
[root@xiandian ~]# systemctl daemon-reload
[root@xiandian ~]# systemctl restart docker
[root@xiandian ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@xiandian ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.09.6
Storage Driver: devicemapper
 Pool Name: docker-253:0-100765090-pool
 Pool Blocksize: 65.54kB
 Base Device Size: 10.74GB
 Backing Filesystem: xfs
 Udev Sync Supported: true
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 11.73MB
 Data Space Total: 107.4GB
 Data Space Available: 24.34GB
 Metadata Space Used: 17.36MB
 Metadata Space Total: 2.147GB
 Metadata Space Available: 2.13GB
 Thin Pool Minimum Free Space: 10.74GB
 Deferred Removal Enabled: true
 Deferred Deletion Enabled: true
 Deferred Deleted Device Count: 0
 Library Version: 1.02.164-RHEL7 (2019-08-27)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-1127.8.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.777GiB
Name: xiandian
ID: OUR6:6ERV:3UCH:WJCM:TDLL:5ATV:E7IQ:HLAR:JKQB:OBK2:HZ7G:JC3Q
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
         Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.

 

14.Docker Harbor安裝(40分)

使用提供的虛擬機與軟件包,部署Docker Harbor鏡像倉庫服務。安裝完畢後,將執行./install.sh --with-notary --with-clair命令返回結果中的[step4]的內容以文本形式提交到答題框。
之前安裝docker-cd時解壓Docker.tar.gz時會產生有一個image.sh的腳本(是一個自動上傳鏡像到本地倉庫的腳本):

[root@zookeeper1 ~]# ./image.sh
[root@zookeeper1 ~]# mkdir  -p  /data/ssl
[root@zookeeper1 ~]# cd /data/ssl/
[root@zookeeper1 ssl]# which openssl
/usr/bin/openssl
[root@zookeeper1 ssl]# openssl  req  -newkey rsa:4096  -nodes  -sha256  -keyout ca.key  -x509  -days 2.235  -out  ca.crt
Generating a 4096 bit RSA private key
...................................................................................................................++
............................................................................................................................................++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN		# 國家
State or Province Name (full name) []:Guangxi	# 地區(州或省名)
Locality Name (eg, city) [Default City]:Liuzhou 	# 城市
Organization Name (eg, company) [Default Company Ltd]:lztd	# 公司名稱
Organizational Unit Name (eg, section) []:xxjsxy	# 單位名稱
Common Name (eg, your name or your server's hostname) []:	# 服務器主機名,域名
Email Address []:		# 郵箱地址

[root@zookeeper1 ssl]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout www.yidaoyun.com.key  -out www.yidaoyun.com.csr
Generating a 4096 bit RSA private key
.........................................................++
......++
writing new private key to 'www.yidaoyun.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN		# 國家
State or Province Name (full name) []:LGuangxi	# 地區(州或省名)
Locality Name (eg, city) [Default City]:Liuzhou 	# 城市
Organization Name (eg, company) [Default Company Ltd]:lztd	# 公司名稱
Organizational Unit Name (eg, section) []:xxjsxy	# 單位名稱
Common Name (eg, your name or your server's hostname) []:www.yidaoyun.com	# 服務器主機名,域名
Email Address []:		# 郵箱地址

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@zookeeper1 ssl]# openssl x509  -req  -days 2.235  -in  www.yidaoyun.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out www.yidaoyun.com.crt
Signature ok
subject=/C=CN/ST=Guangxi/L=Liuzhou/O=lztd/OU=xxjsxy/CN=www.yidaoyun.com
Getting CA Private Key
[root@zookeeper1 ssl]# cp -rvf www.yidaoyun.com.crt /etc/pki/ca-trust/source/anchors/
‘www.yidaoyun.com.crt’ -> ‘/etc/pki/ca-trust/source/anchors/www.yidaoyun.com.crt’
[root@zookeeper1 ssl]# update-ca-trust enable
[root@zookeeper1 ssl]# update-ca-trust extract
# 註釋:上傳docker-compose-Linux-x86_64.64並重命名docker-compose:
[root@zookeeper1 ~]# mv docker-compose-Linux-x86_64.64  /usr/local/bin/
[root@zookeeper1 ~]# mv /usr/local/bin/docker-compose-Linux-x86_64.64 /usr/local/bin/docker-compose
[root@zookeeper1 ~]# chmod +x /usr/local/bin/docker-compose
[root@zookeeper1 ~]# docker-compose --version
docker-compose version 1.26.0-rc4, build d279b7a8
[root@zookeeper1 opt]# tar  -zvxf  harbor-offline-installer-v1.5.3.tgz  -C  /opt/
[root@zookeeper1 opt]# ll
total 1097260
drwxr-xr-x. 8 root root       4096 May 14 08:03 centos
drwx--x--x  4 root root         26 May 19 23:16 containerd
-rw-r--r--. 1 root root 1123583789 May 15 04:26 Docker.tar.gz
drwxr-xr-x  4 root root       4096 May 20 03:55 harbor
[root@zookeeper1 opt]# cd harbor/
[root@zookeeper1 harbor]# ll
total 895708
drwxr-xr-x 3 root root        22 May 20 03:55 common
-rw-r--r-- 1 root root      1185 Sep 12  2018 docker-compose.clair.yml
-rw-r--r-- 1 root root      1725 Sep 12  2018 docker-compose.notary.yml
-rw-r--r-- 1 root root      3596 Sep 12  2018 docker-compose.yml
drwxr-xr-x 3 root root       150 Sep 12  2018 ha
-rw-r--r-- 1 root root      6956 Sep 12  2018 harbor.cfg
-rw-r--r-- 1 root root 915878468 Sep 12  2018 harbor.v1.5.3.tar.gz
-rwxr-xr-x 1 root root      5773 Sep 12  2018 install.sh
-rw-r--r-- 1 root root     10764 Sep 12  2018 LICENSE
-rw-r--r-- 1 root root       482 Sep 12  2018 NOTICE
-rw-r--r-- 1 root root   1247461 Sep 12  2018 open_source_license
-rwxr-xr-x 1 root root     27840 Sep 12  2018 prepare
[root@zookeeper1 harbor]# vim harbor.cfg
# 註釋:修改配置文件內容:
hostname = 192.168.1.111
ui_url_protocol = https
ssl_cert = /data/ssl/www.yidaoyun.com.crt
ssl_cert_key = /data/ssl/www.yidaoyun.com.key
harbor_admin_password = 000000
[root@zookeeper1 harbor]# ./prepare 
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[root@zookeeper1 harbor]# ./install.sh --with-notary --with-clair
[Step 0]: checking installation environment ...
Note: docker version: 18.09.6
Note: docker-compose version: 1.26.0

[Step 1]: loading Harbor images ...
dba693fc2701: Loading layer  133.4MB/133.4MB
5773887c4c41: Loading layer  30.09MB/30.09MB
6fc2abbcae42: Loading layer  15.37MB/15.37MB
d85f176a11ec: Loading layer  15.37MB/15.37MB
Loaded image: vmware/harbor-adminserver:v1.5.3
462b14c85230: Loading layer  410.1MB/410.1MB
c2e0c8cb2903: Loading layer  9.216kB/9.216kB
11bdb24cded2: Loading layer  9.216kB/9.216kB
5d8f974b49ef: Loading layer   7.68kB/7.68kB
ee04f13f4147: Loading layer  1.536kB/1.536kB
799db4dfe41a: Loading layer  11.78kB/11.78kB
f7d813585bdd: Loading layer   2.56kB/2.56kB
6300bbdbd7ab: Loading layer  3.072kB/3.072kB
Loaded image: vmware/harbor-db:v1.5.3
1d7516778a05: Loading layer  30.09MB/30.09MB
f7ec8d1b47d0: Loading layer  20.91MB/20.91MB
22b0ad749c21: Loading layer  20.91MB/20.91MB
Loaded image: vmware/harbor-jobservice:v1.5.3
2d449d67c05a: Loading layer  89.58MB/89.58MB
0bfd4e706575: Loading layer  3.072kB/3.072kB
6100e173c230: Loading layer   59.9kB/59.9kB
86fe093d1358: Loading layer  61.95kB/61.95kB
Loaded image: vmware/redis-photon:v1.5.3
Loaded image: photon:1.0
3bf3086a6569: Loading layer  30.09MB/30.09MB
641d0f77d675: Loading layer  10.95MB/10.95MB
89efbaabea87: Loading layer   17.3MB/17.3MB
1276e51f4dc2: Loading layer  15.87kB/15.87kB
49e187d04e78: Loading layer  3.072kB/3.072kB
e62fbfea411d: Loading layer  28.24MB/28.24MB
Loaded image: vmware/notary-signer-photon:v0.5.1-v1.5.3
Loaded image: vmware/mariadb-photon:v1.5.3
201f6ade61d8: Loading layer  102.5MB/102.5MB
81221fbb5879: Loading layer  6.656kB/6.656kB
2268e3c9e521: Loading layer  2.048kB/2.048kB
9fca06f4b193: Loading layer   7.68kB/7.68kB
Loaded image: vmware/postgresql-photon:v1.5.3
11d6e8a232c9: Loading layer  30.09MB/30.09MB
42650b04d53d: Loading layer  24.41MB/24.41MB
a1cd8af19e29: Loading layer  7.168kB/7.168kB
4b1cda90ba19: Loading layer  10.56MB/10.56MB
1351f0f3006a: Loading layer   24.4MB/24.4MB
Loaded image: vmware/harbor-ui:v1.5.3
e335f4c3af7d: Loading layer  79.93MB/79.93MB
2aea487bc2c4: Loading layer  3.584kB/3.584kB
d2efec3de68b: Loading layer  3.072kB/3.072kB
d0d71a5ce1dd: Loading layer  4.096kB/4.096kB
19930367abf0: Loading layer  3.584kB/3.584kB
03e5b7640db5: Loading layer  9.728kB/9.728kB
Loaded image: vmware/harbor-log:v1.5.3
5aebe8cc938c: Loading layer  11.97MB/11.97MB
Loaded image: vmware/nginx-photon:v1.5.3
ede6a57cbd7e: Loading layer  30.09MB/30.09MB
4d6dd4fc1d87: Loading layer   2.56kB/2.56kB
c86a69f49f60: Loading layer   2.56kB/2.56kB
0cf6e04c5927: Loading layer  2.048kB/2.048kB
6fbff4fe9739: Loading layer   22.8MB/22.8MB
6f527a618092: Loading layer   22.8MB/22.8MB
Loaded image: vmware/registry-photon:v2.6.2-v1.5.3
e29a8834501b: Loading layer  12.16MB/12.16MB
aaf67f1da2c7: Loading layer   17.3MB/17.3MB
8d5718232133: Loading layer  15.87kB/15.87kB
fc89aca1dd12: Loading layer  3.072kB/3.072kB
076eb5a76f6d: Loading layer  29.46MB/29.46MB
Loaded image: vmware/notary-server-photon:v0.5.1-v1.5.3
454c81edbd3b: Loading layer  135.2MB/135.2MB
e99db1275091: Loading layer  395.4MB/395.4MB
051e4ee23882: Loading layer  9.216kB/9.216kB
6cca4437b6f6: Loading layer  9.216kB/9.216kB
1d48fc08c8bc: Loading layer   7.68kB/7.68kB
0419724fd942: Loading layer  1.536kB/1.536kB
543c0c1ee18d: Loading layer  655.2MB/655.2MB
4190aa7e89b8: Loading layer  103.9kB/103.9kB
Loaded image: vmware/harbor-migrator:v1.5.0
45878c64fc3c: Loading layer  165.3MB/165.3MB
fc3d407ce98f: Loading layer  10.93MB/10.93MB
d7a0785bb902: Loading layer  2.048kB/2.048kB
a17e0f23bc84: Loading layer  48.13kB/48.13kB
57c7181f2336: Loading layer  10.97MB/10.97MB
Loaded image: vmware/clair-photon:v2.0.5-v1.5.3

[Step 2]: preparing environment ...
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/config.yml
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/cert/www.yidaoyun.com.crt
Clearing the configuration file: ./common/config/nginx/cert/www.yidaoyun.com.key
Clearing the configuration file: ./common/config/nginx/nginx.conf
Clearing the configuration file: ./common/config/log/logrotate.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
Copying sql file for notary DB
Generated certificate, key file: ./cert_tmp/notary-signer-ca.key, cert file: ./cert_tmp/notary-signer-ca.crt
Generated certificate, key file: ./cert_tmp/notary-signer.key, cert file: ./cert_tmp/notary-signer.crt
Copying certs for notary signer
Copying notary signer configuration file
Generated configuration file: ./common/config/notary/server-config.json
Copying nginx configuration file for notary
Generated configuration file: ./common/config/nginx/conf.d/notary.server.conf
Generated and saved secret to file: /data/defaultalias
Generated configuration file: ./common/config/notary/signer_env
Generated configuration file: ./common/config/clair/postgres_env
Generated configuration file: ./common/config/clair/config.yaml
Generated configuration file: ./common/config/clair/clair_env
The configuration files are ready, please use docker-compose to start the service.

[Step 3]: checking existing instance of Harbor ...

[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating network "harbor_harbor-clair" with the default driver
Creating network "harbor_harbor-notary" with the default driver
Creating network "harbor_notary-mdb" with the default driver
Creating network "harbor_notary-sig" with the default driver
Creating harbor-log ... done
Creating redis              ... done
Creating clair-db           ... done
Creating notary-db          ... done
Creating harbor-db          ... done
Creating registry           ... done
Creating harbor-adminserver ... done
Creating notary-signer      ... done
Creating clair              ... done
Creating harbor-ui          ... done
Creating notary-server      ... done
Creating nginx              ... done
Creating harbor-jobservice  ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at https://192.168.1.111. 
For more details, please visit https://github.com/vmware/harbor .

 

15.Shell腳本補全(40分)

下面有一段腳本,作用是自動配置nginx服務,由於工程師的失誤,將腳本中的某些代碼刪除了,但註釋還在,請根據註釋,填寫代碼。最後將填寫的代碼按照順序以文本形式提交至答題框。 nginx(){ cd #刪除默認項目路徑下的文件 rm -rf /usr/share/nginx/html/* #將提供的dist靜態文件複製到nginx項目目錄 cp -rvf /root/dist/* /usr/share/nginx/html #修改nginx配置文件如下 cat > /etc/nginx/conf.d/default.conf << EOF server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } location /user { (此處需要填寫) } location /shopping { proxy_pass http://127.0.0.1:8081; } location /cashier { proxy_pass http://127.0.0.1:8083; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } EOF #啓動nginx服務 systemctl start nginx #設置nginx開機自啓 (此處需填寫) #檢查nginx服務是否成功啓動 if [ $? -eq 0 ] then sleep 3 echo -e "\033[36m==========nginx啓動成功==========\033[0m" else echo -e "\033[31mnginx啓動失敗,請檢查\033[0m" exit 1 fi sleep 2 }

proxy_pass http://127.0.0.1:8082;
systemctl enable nginx

©版權聲明

著作權歸作者所有:如需轉載,請註明出處,謝謝。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章