先電雲 Paas搭建及運維


PaaS平台搭建

server+client兩個節點部署,1-5步驟在兩個節點均要設置,不能遺漏

1. 關閉selinux 暫時不做

vi /etc/sysconfig/selinux
SELINUX=disabled

[root@server ~]# getenforce
Disabled

2. 關閉防火牆

 setenforce 0
systemctl stop firewalld.service
systemctl disable firewalld.service

3.刪除iptables防火牆規則


# 配置防火牆
# iptables –F //清除所有chains鏈(INPUT/OUTPUT/FORWARD)中所有的rule規則
# iptables –Z //清空所有chains鏈(INPUT/OUTPUT/FORWARD)中包及字節計數器
# iptables –X   //清除用戶自定義的chains鏈(INPUT/OUTPUT/FORWARD)中的rule規則
/usr/sbin/iptables-save
# service iptables save //保存修改的Iptables規則
# 配置selinux
修改配置文件 /etc/selinux/config
SELINUX=permissive //表示系統會收到警告訊息但是不會受到限制,作為selinux的debug模式用處
# 保存修改內容后退出

4. 修改系統內核

# 打開內核轉發功能。
# 編輯配置文件/etc/sysctl.conf,將以下內容添加:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

# 修改完成后使用命令生效。
sysctl –p

上傳鏡像

image-20200708114512558

 

image-20200708114636027

分別刪除源yum

rm -rf /etc/yum.repos.d/*

 

5.添加yum軟件源

[root@registry ~]# cat /etc/yum.repos.d/yum.repo
[centos]
name=centos
baseurl=ftp://10.0.0.137/centos
gpgcheck=0
enabled=1
[docker]
name=iaas
baseurl=ftp://10.0.0.137/docker
gpgcheck=0
enabled=1

# 掛載並拷貝數據至/opt
[root@server mnt]# mount -o loop XianDian-PaaS-v2.2.iso /mnt/
[root@server mnt]# cp -rvf * /opt/

--------------------------------------------------------------------
# 更新yum源為aliyun源
curl -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

image-20200619160328637

yum -y install vsftpd

vi /etc/vsftpd/vsftpd.conf

anon_root=/opt/

systemctl restart vsftpd systemctl enable vsftpd

6. 修改主機名,配置域名解析

# server節點:
[root@server ~]# hostnamectl set-hostname server

# client節點:
[root@client ~]# hostnamectl set-hostname client

[root@server ~]# cat /etc/hosts
10.0.0.137 server
10.0.0.138 client

[root@server ~]# ping client
PING client (10.0.0.138) 56(84) bytes of data.
64 bytes from client (10.0.0.138): icmp_seq=1 ttl=64 time=0.624 ms
64 bytes from client (10.0.0.138): icmp_seq=2 ttl=64 time=1.75 ms
64 bytes from client (10.0.0.138): icmp_seq=3 ttl=64 time=0.640 ms

[root@client ~]# ping server
PING server (10.0.0.137) 56(84) bytes of data.
64 bytes from server (10.0.0.137): icmp_seq=1 ttl=64 time=0.654 ms
64 bytes from server (10.0.0.137): icmp_seq=2 ttl=64 time=0.594 ms
64 bytes from server (10.0.0.137): icmp_seq=3 ttl=64 time=0.718 ms

# 配置DNS服務器地址
root@client ~]# vi /etc/resolv.conf
nameserver 114.114.114.114
nameserver 223.5.5.5

 


# 1. 檢查內核
[root@localhost ~]# uname -a

# 2. 檢查Device Mapper(存儲驅動)
[root@localhost ~]# ls -l /sys/class/misc/device-mapper
ls: cannot access /sys/class/misc/device-mapper: No such file or directory
[root@localhost yum.repos.d]# sudo grep device-mapper /proc/devices

# 3. 以上檢查說明沒有安裝Device Mapper,需要安裝Device Mapper軟件包如下:
[root@localhost yum.repos.d]# sudo yum install -y device-mapper

# 4. 加載Device Mapper模塊
[root@localhost yum.repos.d]# sudo modprobe dm-mod


# 5. 驗證Device Mapper安裝
[root@localhost yum.repos.d]# ls -l /sys/class/misc/device-mapper

lrwxrwxrwx 1 root root 0 Dec 23 09:39 /sys/class/misc/device-mapper -> ../../devices/virtual/misc/device-mapper

# 6. 更新 系統
sudo yum update

部署服務

7. 安裝docker

  • 所有節點安裝docker環境

1. 安裝docker
[root@registry ~]# yum -y install docker-io

2. 啟動docker
[root@localhost yum.repos.d]# systemctl restart docker.service

3. 開機啟動Docker
[root@localhost yum.repos.d]# systemctl enable docker.service

4. 檢查Docker是否正確安裝
[root@localhost yum.repos.d]# docker info

====================================================================
5.配置鏡像加速器並重啟

國內訪問 Docker Hub 有時會遇到困難,此時可以配置鏡像加速器。國內很多雲服務商都提供了加速器服務,例如:阿里雲加速器、DaoCloud 加速器、靈雀雲加速器。如這里使用DaoCloud 加速器
[root@client ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef0cb1d0.m.daocloud.io
Success.
You need to restart docker to take effect: sudo systemctl restart docker

[root@client ~]# sudo systemctl restart docker

部署docker倉庫

8. 上傳倉庫部署使用的鏡像

[root@server ~]# cd /opt/images/rancher1.6.5

[root@server rancher1.6.5]# docker load -i registry_latest.tar 

9. 啟動倉庫容器服務

# 1.啟動基礎倉庫容器
[root@server rancher1.6.5]# docker run -d -p 5000:5000 --restart=always --name registry docker.io/registry:latest
c965e5487b7d836541a5cc87779b9050cd5a708e1614f45116ffdc72adfa174c

# 2.查看正在運行的容器
[root@server rancher1.6.5]# docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
c965e5487b7d        docker.io/registry:latest   "/entrypoint.sh /e..."   26 seconds ago      Up 24 seconds       0.0.0.0:5000->5000/tcp   registry

10. 設置倉庫地址

# PS:兩個節點都做
vi /etc/sysconfig/docker
在最后添加:
ADD_REGISTRY='--add-registry 10.0.0.137:5000'
INSECURE_REGISTRY='--insecure-registry 10.0.0.137:5000'
(注:IP為server節點IP)

# 重啟服務
systemctl daemon-reload
systemctl restart docker
docker info    查看docker的詳細信息
Insecure Registries:
 192.168.200.201:5000
 127.0.0.0/8
Registries: 192.168.200.201:5000 (insecure), docker.io (secure)

# server節點:
[root@server rancher1.6.5]#   
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
docker.io/registry   latest              c9bd19d022f6        3 years ago         33.3 MB

[root@server rancher1.6.5]# docker tag c9bd19d022f6 10.0.0.137:5000/registry:latest
[root@server rancher1.6.5]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
10.0.0.137:5000/registry   latest              c9bd19d022f6        3 years ago         33.27 MB
docker.io/registry         latest              c9bd19d022f6        3 years ago         33.27 MB

[root@server rancher1.6.5]# docker push 10.0.0.137:5000/registry:latest
The push refers to a repository [10.0.0.137:5000/registry]
9b728062fb6d: Pushed 
481c807467a1: Pushed 
a049b9c716b3: Pushed 
d57f828d06ea: Pushed 
011b303988d2: Pushed 
latest: digest: sha256:2fdff97736e7dd785a91ccddb6c2df4ad6664f7032e3d8f28f56d94f699a58f9 size: 1363

# 至此倉庫就建立好了,我們需要將所有鏡像全部推送到倉庫中,提供給其他節點使用。

image-20200708141606693

部署Rancher-Server服務

11. 上傳rancher-server鏡像

rancher_server_v1.6.5.tar

[root@server rancher1.6.5]# docker load -i rancher_server_v1.6.5.tar

[root@server rancher1.6.5]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
<none>                     <none>              f89070da7581        22 months ago       985 MB
10.0.0.137:5000/registry   latest              c9bd19d022f6        3 years ago         33.3 MB
docker.io/registry         latest              c9bd19d022f6        3 years ago         33.3 MB	

[root@server rancher1.6.5]# docker tag f89070da7581 10.0.0.137:5000/rancher/server:v1.6.5
[root@server rancher1.6.5]# docker push 10.0.0.137:5000/rancher/server:v1.6.5

rancher_agent_v1.2.5.tar 

[root@Server rancher1.6.5]# docker load -i rancher_agent_v1.2.5.tar 
[root@server rancher1.6.5]# docker tag  ef5fea38dbe6 10.0.0.137:5000/rancher/agent:v1.2.5
[root@server rancher1.6.5]# docker push  10.0.0.137:5000/rancher/agent:v1.2.5

rancher_net_holder.tar

[root@server rancher1.6.5]# docker load -i rancher_net_holder.tar
[root@server rancher1.6.5]# docker tag  665d9f6e8cc1 10.0.0.137:5000/rancher/net:holder
[root@server rancher1.6.5]# docker push  10.0.0.137:5000/rancher/net:holder

rancher_dns_v0.15.1.tar 

[root@server rancher1.6.5]# docker load -i rancher_dns_v0.15.1.tar 
[root@server rancher1.6.5]# docker tag  af5509fe436b   10.0.0.137:5000/rancher/dns:v0.15.1
[root@server rancher1.6.5]# docker push 10.0.0.137:5000/rancher/dns:v0.15.1

rancher-net_v0.11.3.tar 

[root@server rancher1.6.5]# docker load -i rancher-net_v0.11.3.tar 
[root@server rancher1.6.5]# docker tag   9495baae8faf 10.0.0.137:5000/rancher/net:v0.11.3
[root@server rancher1.6.5]# docker push  10.0.0.137:5000/rancher/net:v0.11.3

rancher_healthcheck_v0.3.1.tar 

[root@server rancher1.6.5]# docker load -i rancher_healthcheck_v0.3.1.tar 
[root@server rancher1.6.5]# docker tag    10710b438de7   10.0.0.137:5000/rancher/healthcheck:v0.3.1
[root@server rancher1.6.5]# docker  push  10.0.0.137:5000/rancher/healthcheck:v0.3.1

 rancher_network-manager_v0.7.4.tar 
 
[root@server rancher1.6.5]# docker load -i rancher_network-manager_v0.7.4.tar 
[root@server rancher1.6.5]# docker tag   787fc137ac53   10.0.0.137:5000/rancher/network-manager:v0.7.4
[root@server rancher1.6.5]# docker push  10.0.0.137:5000/rancher/network-manager:v0.7.4

rancher_metadata_v0.9.2.tar 

[root@server rancher1.6.5]# docker load -i rancher_metadata_v0.9.2.tar 
[root@server rancher1.6.5]# docker tag    d46f30a656e0  10.0.0.137:5000/rancher/metadata:v0.9.2
[root@server rancher1.6.5]# docker push  10.0.0.137:5000/rancher/metadata:v0.9.2


rancher_scheduler_v0.8.2.tar 

[root@server rancher1.6.5]# docker load -i rancher_scheduler_v0.8.2.tar 
[root@server rancher1.6.5]# docker tag    690ef14a99b7   10.0.0.137:5000/rancher/scheduler:v0.8.2
[root@server rancher1.6.5]# docker push 10.0.0.137:5000/rancher/scheduler:v0.8.2

image-20200708161355680

12. 啟動rancher-server服務

[root@server rancher1.6.5]# docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:v1.6.5
55c09a2bdab5b840ae4e274b1861e854748f0353b43153521b01f1f8bd540460

[root@server rancher1.6.5]# docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                              NAMES
55c09a2bdab5        rancher/server:v1.6.5       "/usr/bin/entry /u..."   5 seconds ago       Up 4 seconds        3306/tcp, 0.0.0.0:8080->8080/tcp   relaxed_beaver
c965e5487b7d        docker.io/registry:latest   "/entrypoint.sh /e..."   11 minutes ago      Up 7 minutes        0.0.0.0:5000->5000/tcp             registry

13. 通過網頁訪問

  • Rancher-server的訪問地址是server IP:8080

image-20200611210918312

將/opt/images/rancher1.6.5鏡像全部上傳load--->tag--->push
[root@server rancher1.6.5]# docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
10.0.0.137:5000/rancher/server            v1.6.5              f89070da7581        22 months ago       985 MB
10.0.0.137:5000/rancher/scheduler         v0.8.2              690ef14a99b7        2 years ago         242 MB
10.0.0.137:5000/rancher/agent             v1.2.5              ef5fea38dbe6        2 years ago         237 MB
10.0.0.137:5000/rancher/network-manager   v0.7.4              787fc137ac53        2 years ago         249 MB
10.0.0.137:5000/rancher/metadata          v0.9.2              d46f30a656e0        2 years ago         252 MB
10.0.0.137:5000/rancher/net               v0.11.3             9495baae8faf        2 years ago         267 MB
10.0.0.137:5000/rancher/dns               v0.15.1             af5509fe436b        2 years ago         240 MB
10.0.0.137:5000/rancher/healthcheck       v0.3.1              10710b438de7        2 years ago         384 MB
10.0.0.137:5000/rancher/net               holder              665d9f6e8cc1        2 years ago         267 MB
10.0.0.137:5000/registry                  latest              c9bd19d022f6        3 years ago         33.3 MB
docker.io/registry                        latest              c9bd19d022f6        3 years ago         33.3 MB

14. Rancher 服務設置

進去之后選擇右下方的語言,設置成中文;
系統管理->訪問控制->選擇LOCAL(本地)->登錄用戶名wangjingmao、全名wangjingmao、密碼000000->點擊啟用本地驗證

image-20200609195858041

系統管理->系統設置->點擊我確認已經知道修改高級設置可能導致的問題->找到registry.default,添加10.0.0.137:5000(IP為server內網IP)->保存

image-20200609195946401

image-20200609194901972

 

 

  • 將所有鏡像上傳完之后,點擊Default->環境管理->添加環境->名稱Rancher、環境模板Cattle->創建

  • 點擊Default切換到Rancher

  • 添加主機->設置client節點的IP(10.0.0.138),復制腳本在client節點執行

 

image-20200609194940543

 

 

# client節點執行腳本自動pull鏡像
[root@client ~]# sudo docker run -e CATTLE_AGENT_IP="10.0.0.138"  --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.5 http://10.0.0.137:8080/v1/scripts/1E055DBBE42EF6CE70AA:1546214400000:vEBBODv17mJ31Gq78kQiIEKgVk
Unable to find image 'rancher/agent:v1.2.5' locally
Trying to pull repository 10.0.0.137:5000/rancher/agent ... 
v1.2.5: Pulling from 10.0.0.137:5000/rancher/agent
c83208261473: Pull complete 
6e1a85c1d66a: Pull complete 
f1320ef45e20: Pull complete 
5a6ab6e6fbf6: Pull complete 
6fd240c27767: Pull complete 
e65de2d7811b: Pull complete 
69209ef84f12: Pull complete 
2f794cb0fa7b: Pull complete 
0f461936465b: Pull complete 
Digest: sha256:9a75552b1c3073349aed0ff75c578382b6ac9c9868a8a4029cc4da55e37b8151
Status: Downloaded newer image for 10.0.0.137:5000/rancher/agent:v1.2.5

INFO: Running Agent Registration Process, CATTLE_URL=http://10.0.0.137:8080/v1
INFO: Attempting to connect to: http://10.0.0.137:8080/v1
INFO: http://10.0.0.137:8080/v1 is accessible
INFO: Inspecting host capabilities
INFO: Boot2Docker: false
INFO: Host writable: true
INFO: Token: xxxxxxxx
INFO: Running registration
INFO: Printing Environment
INFO: ENV: CATTLE_ACCESS_KEY=64D9A9AD4C473D98DB84
INFO: ENV: CATTLE_AGENT_IP=10.0.0.138
INFO: ENV: CATTLE_HOME=/var/lib/cattle
INFO: ENV: CATTLE_REGISTRATION_ACCESS_KEY=registrationToken
INFO: ENV: CATTLE_REGISTRATION_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_URL=http://10.0.0.137:8080/v1
INFO: ENV: DETECTED_CATTLE_AGENT_IP=10.0.0.138
INFO: ENV: RANCHER_AGENT_IMAGE=rancher/agent:v1.2.5
INFO: Launched Rancher Agent: b24fefd92a34746f96d71cd5b4652a14dce37e82a241de6e873c689bcc7a1d23

# 切換到應用-基礎設施,等待基礎設施應用自動部署成功,如下圖是基礎設施應用部署成功的效果,

image-20200609195037396

 

 

15. 部署MySQL8.0數據庫服務

cd ..
[root@server images]# docker load -i mysql_8.0.tar

[root@server images]# docker tag 26bd364f80bf 10.0.0.137:5000/mysql:8.0

[root@server images]# docker push 10.0.0.137:5000/mysql:8.0
The push refers to a repository [10.0.0.137:5000/mysql]
a5f2a9df13dd: Pushed 
4b0cb3e76d62: Pushed 
8c75b8d21905: Pushed 
2456590c0f90: Pushed 
22afc4412590: Pushed 
45fb4a2ab5eb: Pushed 
8b2d012e71d9: Pushed 
19aa284e9bf3: Pushed 
889744378e18: Pushed 
ae12d30e1dfc: Pushed 
4bcdffd70da2: Pushed 
8.0: digest: sha256:c6a388006b8f706b031279a0102c3b454d9cbee74390a84f3735769f3070d07b size: 2617

 

應用模板部署

16. 企業級Gogs應用部署

# 1.push gogs鏡像
[root@server images]# docker load -i gogs_gogs_0.11.34.tar
[root@server images]# docker tag 290bc4df94f2 10.0.0.137:5000/gogs/gogs:0.11.34
[root@server images]# docker push 10.0.0.137:5000/gogs/gogs:0.11.34

# 2.push haproxy鏡像
[root@server images]# docker load -i rancher_lb-service-haproxy_v0.7.9.tar
[root@server images]# docker tag 774f6505bd28 10.0.0.137:5000/rancher/lb-service-haproxy:v0.7.9
[root@server images]# docker push 10.0.0.137:5000/rancher/lb-service-haproxy:v0.7.9
 

17. 點擊應用商店->全部->搜索Gogs應用->查看詳情,將配置選項里的8080端口改為9093,Mysql Password密碼為000000,然后點擊啟動

image-20200613165911306

image-20200613165859821

18. 下面Gogs部署設置,點擊最下方的預覽,查看具體的服務配置

image-20200609195430091

image-20200613173539312

19. 然后用client節點的IP加9090端口在瀏覽器中訪問,輸入密碼,點擊立即安裝

image-20200609195534478

 

20. 然后打開一個新的標簽頁訪問http://10.0.0.138:9090即可訪問Gogs主頁

PaaS平台運維

1.容器底層服務(2分)

1.容器底層服務(2分)
# 在容器server節點創建CPU控制的cgroup,名稱為xiandian。假設存在進程號為8888的進程一直占用CPU,嚴重影響系統的正常運行。
# 在創建的cgroup中將此進程調用CPU的配額調整為30%。依次將操作命令及返回結果以文本形式提交到答題框。
mkdir -p /sys/fs/cgroup/cpu/xiandian
echo 30000 > /sys/fs/cgroup/cpu/xiandian/cpu.cfs_quota_us
echo 8888 > /sys/fs/cgroup/cpu/xiandian/tasks
cat /sys/fs/cgroup/cpu/xiandian/cpu.cfs_quota_us
30000
#在server節點使用nginx鏡像創建一個名為xiandian的容器,只能使用0這個內核,鏡像使用nginx:latest,並通過查看Cgroup相關文件查看內核使用情況,將以上操作命令及檢查結果填入答題框。
[root@server images]#
[root@server images]# docker run -dit --name 1daoyun --cpuset-cpus="0" nginx:latest /bin/bash
6f377e734d407649f8c2703eb336a145a88cd78bdedc077ad1714872b6406514 
[root@server images]# cat /sys/fs/cgroup/cpuset/system.slice/docker-6f377e734d407649f8c2703eb336a145a88cd78bdedc077ad1714872b6406514.scope/cpuset.cpus
0

2.容器存儲配置(3分)

2.容器存儲配置(3分)
# (1)在容器server節點運行mysql:8.0鏡像,設置數據庫密碼為xd_root,將server節點的13306端口映射到容器3306端口;
docker run -itdP -e MYSQL_ROOT_PASSWORD=xd_root -p 13306:3306  mysql:8.0
263509211cb33853360407fc76c422236e43506738a70b3c1a4d25b6bfd4c93c
# (2)進入容器創建名為xd_db的數據庫,創建名為xiandian,密碼為xd_pass的用戶,設置此用戶對xd_db數據庫擁有所有權限和允許此用戶遠程訪問;
docker ps -a 的第一個鏡像id
[root@server rancher1.6.5]# docker exec -it ea60458029a8 /bin/bash
root@ea60458029a8:/# mysql -uroot -pxd_root
mysql> create database xd_db;
Query OK, 1 row affected (0.15 sec)

mysql> grant all privileges on xd_db.* to 'xiandian'@'%'  identified by 'xd_pass';
Query OK, 0 rows affected, 1 warning (0.02 sec)

# MySQL 賦予用戶權限命令的簡單格式
 grant 權限 on 數據庫對象 to 用戶

#(3)使用xiandian用戶遠程登錄數據庫並查詢數據庫內的數據庫列表。
[root@Server ~]# docker exec -it ea60458029a8 /bin/bash
root@ea60458029a8:/# mysql -uxiandian -pxd_pass -h172.17.0.4 -e "show databases;"
mysql: [Warning] Using a password on the command line interface can be insecure. #報錯是密碼不安全
+--------------------+
| Database           |
+--------------------+
| information_schema |
| xd_db              |
+--------------------+
crt +p+q 退出

3.容器網絡(2分)

3.容器網絡(2分)
#(1)在容器server節點,使用docker命令創建名為xd_net的網絡,網絡網段為192.168.3.0/24,網關為192.168.3.1;
docker network create --subnet=192.168.3.0/24 --ip-range=192.168.3.0/24 --gateway=192.168.3.1 xd_net
6bd7080ec71615b7144161acd4bf83fe3c98f824cc06cf9e62f3e80ce8db5750

docker network ls  # 查詢網絡列表
NETWORK ID          NAME                DRIVER              SCOPE
c780a6066bcb        bridge              bridge              local               
bcc52d5172e3        host                host                local               
78c459bf4568        none                null                local               
6bd7080ec716        xd_net              bridge              local 
docker network inspect xd_net   # 查詢此網絡的詳細信息
[
    {
        "Name": "xd_net",
        "Id": "6bd7080ec71615b7144161acd4bf83fe3c98f824cc06cf9e62f3e80ce8db5750",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.3.0/24",
                    "IPRange": "192.168.3.0/24",
                    "Gateway": "192.168.3.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
 
#(2)啟動鏡像為centos:latest、名為centos-xd、網絡為xd_net的容器;
# 上傳 centos 的鏡像
load--->tag--->push
[root@Server images]# docker load -i centos_latest.tar
[root@Server images]# docker tag  ff426288ea90  192.168.100.10:5000/centos-xd
[root@Server images]# docker push  192.168.100.10:5000/centos-xd  
[root@Server images]# docker run -ditP --net=xd_net --name centos-xd centos-xd
#(3)使用inspect -f命令查詢容器IP地址。
docker inspect -f '{{.NetworkSettings.Networks.xd_net}}' centos-xd

{<nil> [] [7267f14a3015] 762d4defafef4a5edd86f19752048e140bf293972f782465d9eb974087ec24df a466720c204c31101ff0b696c4eb44249e2f6cca0d73e8f3318f1a1de76d3f47 192.168.3.1 192.168.3.2 24   0 02:42:c0:a8:03:02}

 

4.容器構建(3分)

4.容器構建(3分)

# 在容器server節點,使用supermin5命令(若命令不存在,則自己安裝)構建名為centos-7的centos7系統docker鏡像,鏡像預裝yum、net-tools、initscripts和vi命令。構建完成后提交鏡像至容器倉庫,並查看此鏡像。依次將操作命令及返回結果以文本形式提交到答題框。
[root@Server images]# yum install supermin5 supermin5-devel -y

[root@Server images]# supermin5 -v --prepare bash yum net-tools initscripts vi coreutils -o supermin.d

[root@Server images]# supermin5 -v --build --format chroot supermin.d -o appliance.d

[root@Server images]#echo 7 > appliance.d/etc/yum/vars/releasever

[root@Server images]#tar --numeric-owner -cpf centos-7.tar -C appliance.d .

[root@Server images]#cat centos-7.tar | docker import - 192.168.200.12:5000/centos-7
sha256:cb9effb750bd016112ade73b031646c3411229a998ef16721bc4e7d545687bd4

[root@Server images]#docker push 192.168.200.12:5000/centos-7:latest
The push refers to a repository [192.168.100.10:5000/centos-7]
21af50fef18c: Pushed 
latest: digest: sha256:29a028e0cc15518484f0b80c267b9f714b992fbda95b22a39e25bcffa037a94a size: 528

docker run -i -t --rm 192.168.200.12:5000/centos-7 /bin/bash     
	進入bash-4.2#

# cat /etc/redhat-release
Derived from Red Hat Enterprise Linux 7.1 (Source)

# docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
192.168.200.12:5000/centos-7                      latest              e40242986ac3        3 minutes ago       258.1 MB

 

5.Dockerfile編寫(3分)

5.Dockerfile編寫(3分)
# 以上題構建的centos-7鏡像為基礎,按以下要求構建http服務鏡像http:v1.0:
# 刪除鏡像的yum源,使用當前系統的yum源文件;
# 完成后安裝http服務;
# 暴露80端口。
# 使用cat命令查看Dockerfile文件並構建鏡像。
[root@server ~]# mkdir docker_demo
[root@server ~]# cd docker_demo
[root@server nginx]# cat Dockerfile 
FROM 192.168.200.201:5000/centos-7:latest
MAINTAINER Xiandian
RUN rm -fv /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/
RUN yum install -y httpd
EXPOSE 80

PS: 
FROM 10.0.0.100:5000/centos-7
MAINTAINER myhttp "123@qq.com"
RUN rm -f /etc/yum.repos.d/*
RUN echo '[centos]' > /etc/yum.repos.d/docker.repo
RUN echo 'name=centos' >> /etc/yum.repos.d/docker.repo
RUN echo 'baseurl=ftp://192.168.100.10/centos' >> /etc/yum.repos.d/docker.repo
RUN echo 'gpgcheck=0' >>/etc/yum.repos.d/docker.repo
RUN echo 'enabled=1' >> /etc/yum.repos.d/docker.repo
RUN echo '[docker]' > /etc/yum.repos.d/docker.repo
RUN echo 'name=docker' >> /etc/yum.repos.d/docker.repo
RUN echo 'baseurl=file:///opt/docker/docker' >> /etc/yum.repos.d/docker.repo
RUN echo 'gpgcheck=0' >> /etc/yum.repos.d/docker.repo
RUN echo 'enabled=1' >> /etc/yum.repos.d/docker.repo
RUN yum clean all
EXPOSE 80
#以上題構建的centos-7鏡像為基礎,構建數據庫鏡像centos-mariadb:v1.0,其要求為:
cat Dockerfile  
#FROM 10.0.6.126:5000/centos-7 			鏡像來自Centos-7
#MAINTAINER Xiandian 				   鏡像的作者
#RUN rm -fv /etc/yum.repos.d/*       	刪除鏡像的本地yum源,
#ADD local.repo /etc/yum.repos.d/  		使用容器server節點的yum源文件;
#RUN yum install -y mariadb-server  	安裝mariadb服務
#RUN mysql_install_db --user=mysql 		使用mysql用戶初始化數據庫;
#ENV LC_ALL en_US.UTF-8 			   數據庫支持中文;
#ENV MYSQL_USER xiandian 			   設置MYSQL_USER=xiandian環境變量;
#ENV MYSQL_PASS xiandian 			   設置MYSQL_PASS=xiandian環境變量;
#EXPOSE 3306 						  暴露3306端口;
#CMD mysqld_safe 					  啟動容器時能自動運行mysld_safe命令。

[root@server nginx]# docker build -t 192.168.200.201:5000/httpd:v1.0 .
[root@server nginx]# docker images
REPOSITORY                                                  TAG                 IMAGE ID            CREATED             SIZE
192.168.200.201:5000/httpd                                       v1.0                a41a37cb9467        6 minutes ago       554.2 MB

6.容器api(2分)

6.容器api(2分)
# 在容器server節點使用docker api 命令查詢docker內所有容器

#編寫docker文件 
vi /usr/lib/systemd/system/docker.service
# 在 ExecStart 行最后面加入以下內容
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

[root@server docker_demo]# source /etc/sysconfig/docker
[root@server docker_demo]# vi /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false  -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375'
# 查看docker內所有容器
curl -X GET http://localhost:2375/containers/json?all=1

7.在 server 節點使用 netstat 命令查詢倉庫監聽端口號,查詢完畢后通過 lsof 命令(如命令不存在則手工安裝)查詢使用此端口號的進程

[root@server xiandian]# netstat -ntpl | grep docker	
[root@server xiandian]# yum install lsof -y
[root@server xiandian]# lsof -i:5000

8.在 server 節點通過 netstat 命令(如命令不存在則手工安裝)查詢 docker

鏡像倉庫 PID,使用 top 命令查詢上一步查詢到的 PID 的資源使用情況。

[root@client ~]# netstat -ntpl
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      941/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      821/master          
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      821/master
[root@client ~]# top p 941

9.在 server 節點創建 memory 控制的 cgroup,名稱為:xiandian,創建完成后將當前進程移動到這個 cgroup 中,通過 cat 相關命令查詢 cgroup 中的進程

ID。

[root@server ~]# mkdir /sys/fs/cgroup/memory/xiandian -p
[root@server ~]# echo $$  /// 查詢進程號
[root@server ~]# echo $$ > /sys/fs/cgroup/memory/xiandian/tasks 
[root@server ~]# cat /sys/fs/cgroup/memory/xiandian/tasks 
18737
18822
[root@server ~]# cat  /proc/52345/cgroup

 

10.查詢docker registry 容器后幾條日志

[root@server ~]# ls
[root@server ~]# docker ps
[root@server ~]# docker logs registry | tail -3

11.在 server 節點,查詢rancher/server 容器的進程號,建立命名空間 \var\run\netns並與rancher/server 容器進行連接,通過ip netns 相關命令查詢該容器的ip

[root@server ~]# docker ps -a   ///查詢是否有運行的進程
[root@server ~]# docker inspect -f {{.State.Pid}} rancher  // 查詢進程號ID
52520
[root@server ~]# mkdir -p /var/run/netns
[root@server ~]# ln -s /proc/52520/ns/net /var/run/netns/52520
[root@server ~]#ip netens exec 52520 ip addr list

12.在server節點查詢當前cgroup的掛載情況

[root@server ~]# mount  -t cgroup

13.在server 節點創建目錄,完成號啟動鏡像為nginx:latest的容器,並指定此目錄為容器啟動的數據卷,創建完成后通過inspect命令指定查看數據卷的情況。

[root@server ~]# docker rm -f nginx
[root@server ~]# mkdir -p  /opt/xiandian
[root@server ~]# docker run -dp --name nginx -v /opt/xiandian/:/opt nginx:latest
[root@server ~]# docker inspect -f {{.Mounts}} nginx

 

 

刪除docker 標簽

docker rmi -f [image]

 


免責聲明!

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



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