歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Docker部署Rancher Server

http://www.pangxie.space/docker/212
環境:
rancher server:192.168.12.181
rancher agent01:192.168.12.182
rancher agent02:192.168.12.183
版本:
rancher/server:v0.50.2
rancher/agent:v0.8.2
rancher/agent-instance:v0.6.0
1.三台主機均安裝docker。
2.rancher server安裝:
12345[root@rancher_server ~]#docker run -d --restart=always -p 8080:8080 rancher/server [root@rancher_server ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES12d5aa863cd9 rancher/server "/usr/bin/s6-svscan /" 6 minutes ago Up 3 minutes 3306/tcp, 0.0.0.0:8080->8080/tcp jovial_pasteur3.配置浏覽器打開192.168.12.181:8080主界面:

3.1添加agent01:192.168.12.182Add host-> Custom12.182 主機運行如下:
1
2
3
4
5
docker
run
-d
--privileged
-v
/var/run/docker.sock:/var/run/docker.sock
rancher/agent:v0.8.2http://192.168.12.181:8080/v1/scripts/1D401C0E3BE559BE5D7F:1450839600000:mYLyHoPTQQqvIc0QVnjMgoLR9E
[root@rancher_agent01
~]#
docker ps
CONTAINER
ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
2f4c2bab573a
rancher/agent:v0.8.2
"/run.sh
run"
51
seconds
ago
Up
50
seconds
rancher-agent
3.2浏覽器查看已添加host

3.3創建容器

容器創建完成:



3.4管理容器:可以啟停容器,可以直接進入shell。



4.使用
4.1容器間的互通。
按照上述辦法,再新增一個host 192.168.12.183,並新建容器test02



容器間,使用10.42網段地址互通。
5典型案例
5.1案例1:
目標:新建2個wordpress容器實現負載均衡,並且數據保存在mysql數據庫。
所需容器:wordpress容器*2+mysql容器*1+load balance容器*1
5.1.1新建mysql容器:



自定義MYSQL_ROOT_PASSWORD=wordpress



5.1.2新建wordpress*2,link mysql數據庫。



5.1.3新建load balancer



5.1.4檢查
service狀態檢查:



找到load balance容器所在agent地址,浏覽器打開192.168.12.182:8080



5.2案例2:
使用yml文件創建service。
5.2.1使用docker compose.yml文件創建wordpress
1234567891011121314151617181920mywordpress01:tty: trueimage: wordpresslinks:database01: mysqlstdin_open: truewordpresslb01:ports:- 8090:80tty: trueimage: rancher/load-balancer-servicelinks:mywordpress01: mywordpress01stdin_open: truedatabase01:environment:MYSQL_ROOT_PASSWORD: pass1tty: trueimage: mysqlstdin_open: true將上述yml文件內容復制進入:

創建好後,wordpress容器可以根據實際情況進行增加。

浏覽器打開 192.168.12.182:8090,出現wordpress配置界面。

5.2.2使用rancher compose.yml文件創建wordpress(鑒於該方法比較復雜,只作為學習)a.下載rancher-compose文件至rancher server(12.181)下載位置:Application-stack-右上角download CLI,下載linux版至12.181
1
2
tar
zxvf rancher-compose-linux-amd64-v0.6.2.tar.gz
cp rancher-compose-v0.6.2/rancher-compose
/usr/bin/
b.新建一個文件夾yml
在該文件夾中,新建2個yml文件
12345678910111213141516171819202122232425262728293031323334353637383940414243[root@rancher_server yml]# more docker-compose.ymlmywordpress02:tty: trueimage: wordpresslinks:database02: mysqlstdin_open: truewordpresslb02:ports:- 8070:80tty: trueimage: rancher/load-balancer-servicelinks:mywordpress02: mywordpress02stdin_open: truedatabase02:environment:MYSQL_ROOT_PASSWORD: pass1tty: trueimage: mysqlstdin_open: true [root@rancher_server yml]# more rancher-compose.ymlmywordpress02:scale: 2wordpresslb02:scale: 1load_balancer_config:lb_cookie_stickiness_policy: nulldescription: nullname: wordpresslb02 configapp_cookie_stickiness_policy: nullhealth_check:port: nullinterval: 2000unhealthy_threshold: 3request_line: ''healthy_threshold: 2response_timeout: 2000database02:scale: 1[root@rancher_server yml]#c.在12.181設置環境變量
1
2
3
[root@rancher_server
yml]#
export RANCHER_URL=http://192.168.12.181:8080/
[root@rancher_server
yml]#
export RANCHER_ACCESS_KEY=59F7850E651C9B901291
[root@rancher_server
yml]#
export RANCHER_SECRET_KEY=2JxRErbgUVy9Ze8trQiEs7ZRBitC824k1xnphudh
ACCESS_KEY來源於 右上角-API&keys-Add APi key中的username
SECRET_KEY來源於 右上角-API&keys-Add APi key中的password
d.在12.181使用命令行創建wordpress
1[root@rancher_server yml]# rancher-compose -p mywordpress02 up創建完成後,界面查看

6.升級將當前server版本v0.50.2升級至v0.56.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@rancher_server
~]#
docker ps
CONTAINER
ID IMAGE
COMMAND CREATED
STATUS PORTS NAMES
12d5aa863cd9 rancher/server "/usr/bin/s6-svscan
/"
6
weeks
ago
Up
6
weeks 3306/tcp,
0.0.0.0:8080->8080/tcp
jovial_pasteur
[root@rancher_server
~]#
docker stop 12d5aa863cd9
12d5aa863cd9
[root@rancher_server
~]#
docker create --volumes-from jovial_pasteur --name rancher-data rancher/server:v0.50.2
Unable
to
find
image
'rancher/server:v0.50.2'
locally
v0.50.2:
Pulling
from
rancher/server
Digest:
sha256:602b2e73d1394550b319718704f48c2178ea6f4ccb7bf6f75e8f1203c463952a
Status:
Downloaded
newer
image
for
rancher/server:v0.50.2
360b6f73f99c656d0a638b8f07fbde2c81ab7d21c72c1d1006f7c7e45986794d
[root@rancher_server
~]#
docker images
REPOSITORY TAG
IMAGE
ID CREATED
VIRTUAL
SIZE
rancher/server latest 4b0be812e553 7
weeks
ago
844.4
MB
rancher/server v0.50.2
4b0be812e553 7
weeks
ago
844.4
MB
ubuntu 14.04.3
d55e68e6cc9c 8
weeks
ago
187.9
MB
rancher/agent
v0.8.2 bd417032148c 5
months
ago 365
MB
ubuntu 14.04.2
63e3c10217b8 6
months
ago 188.3
MB
[root@rancher_server
~]#
docker pull rancher/server:latest
[root@rancher_server
~]#
docker images
REPOSITORY TAG
IMAGE
ID CREATED
VIRTUAL
SIZE
rancher/server latest ae3d59f95cac 8
days
ago 848.7
MB
rancher/server v0.50.2
4b0be812e553 7
weeks
ago
844.4
MB
ubuntu 14.04.3
d55e68e6cc9c 8
weeks
ago
187.9
MB
rancher/agent
v0.8.2 bd417032148c 5
months
ago 365
MB
ubuntu 14.04.2
63e3c10217b8 6
months
ago 188.3
MB
[root@rancher_server
~]#
docker run -d --volumes-from rancher-data --restart=always -p 8080:8080 rancher/server:latest
abbe5ee325c7246932eec2ae38e35e4cfeb7c1e094a37a4621b7753ee96c293a
[root@rancher_server
~]#
docker ps
CONTAINER
ID IMAGE
COMMAND CREATED
STATUS PORTS NAMES
abbe5ee325c7 rancher/server:latest
"/usr/bin/s6-svscan
/"
4
seconds
ago
Up
3
seconds 3306/tcp,
0.0.0.0:8080->8080/tcp
jolly_boyd
[root@rancher_server
~]#
打開浏覽器,可以看到已經升級至新版本。
http://192.168.12.181:8080
原有host仍然存在,並且可用:

本文結束。
Copyright © Linux教程網 All Rights Reserved