Docker部署Rancher Server-centos7
http://www.pangxie.space/docker/212环境:rancher server:192.168.12.181rancher agent01:192.168.12.182rancher agent02:192.168.12.183版本:rancher/server:v0.50.2rancher/agent:
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安装:
1
2
3
4
5
|
[
root
@
rancher_server
~
]
#docker run -d --restart=always -p 8080:8080 rancher/server
[
root
@
rancher_server
~
]
# docker ps
CONTAINER
ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
12d5aa863cd9
rancher
/
server
"/usr/bin/s6-svscan /"
6
minutes
ago
Up
3
minutes
3306
/
tcp
,
0.0.0.0
:
8080
->
8080
/
tcp
jovial_pasteur
|
3.配置
浏览器打开192.168.12.181:8080
主界面:
3.1添加agent01:192.168.12.182
Add host-> Custom
12.182 主机运行如下:
1
2
3
4
5
|
docker
run
-
d
--
privileged
-
v
/
var
/
run
/
docker
.
sock
:
/
var
/
run
/
docker
.
sock
rancher
/
agent
:
v0
.
8.2
http
:
//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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
mywordpress01
:
tty
:
true
image
:
wordpress
links
:
database01
:
mysql
stdin_open
:
true
wordpresslb01
:
ports
:
-
8090
:
80
tty
:
true
image
:
rancher
/
load
-
balancer
-
service
links
:
mywordpress01
:
mywordpress01
stdin_open
:
true
database01
:
environment
:
MYSQL_ROOT_PASSWORD
:
pass1
tty
:
true
image
:
mysql
stdin_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文件
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
34
35
36
37
38
39
40
41
42
43
|
[
root
@
rancher_server
yml
]
# more docker-compose.yml
mywordpress02
:
tty
:
true
image
:
wordpress
links
:
database02
:
mysql
stdin_open
:
true
wordpresslb02
:
ports
:
-
8070
:
80
tty
:
true
image
:
rancher
/
load
-
balancer
-
service
links
:
mywordpress02
:
mywordpress02
stdin_open
:
true
database02
:
environment
:
MYSQL_ROOT_PASSWORD
:
pass1
tty
:
true
image
:
mysql
stdin_open
:
true
[
root
@
rancher_server
yml
]
# more rancher-compose.yml
mywordpress02
:
scale
:
2
wordpresslb02
:
scale
:
1
load_balancer_config
:
lb_cookie_stickiness_policy
:
null
description
:
null
name
:
wordpresslb02
config
app_cookie_stickiness_policy
:
null
health_check
:
port
:
null
interval
:
2000
unhealthy_threshold
:
3
request_line
:
''
healthy_threshold
:
2
response_timeout
:
2000
database02
:
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仍然存在,并且可用:
本文结束。
更多推荐
- 5914
- 1
- 0
- 0
扫一扫分享内容
- 分享
顶部
所有评论(0)