Rancher安裝
Rancher是一個(gè)開(kāi)源的容器管理平臺(tái),幫助構(gòu)建企業(yè)私有容器服務(wù),相當(dāng)于KVM里的Openstack。

直接Docker安裝:
$ sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server
訪問(wèn)8080端口即可看到界面。
由于眾所周知的原因,推薦使用DaoCloud進(jìn)行Docker安裝和鏡像加速。
筆者在CentOS 7.2里執(zhí)行上述命令時(shí)遇到一個(gè)錯(cuò)誤,詳情請(qǐng)參考這里。
Rancher認(rèn)證配置


啪啪兩步搞定。
Rancher主機(jī)添加
Rancher提供了很多machine drivers批量添加主機(jī),如下圖:

如果沒(méi)有可用driver, 就只能選擇Custom,看到下圖所示:

在主機(jī)執(zhí)行上圖命令即可,See。

Custom方式批量添加主機(jī)
逐臺(tái)主機(jī)登錄輸入命令也挺頭疼,使用expect編寫一個(gè)腳本減輕部分工作量:
#!/usr/bin/expect
set timeout -1
set ip [lindex $argv 0]
spawn ssh root@$ip
expect {
"*Are you sure you want to continue connecting (yes/no)?*" { send "yes\r" }
"*password*" { send "123456\r" }
}
expect {
"*password*" { send "123456\r" }
}
expect {
"]# " { send "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.2 http://123.207.234.119:8080/v1/scripts/EE431DCFC650693D335A:1483142400000:3FSEGIHT9rsY68RViGJGV8sBiBk\r" }
}
send "exit\r"
expect eof
exit
Host配置
在騰訊云申請(qǐng)了6臺(tái)主機(jī),計(jì)劃1臺(tái)master,5臺(tái)slave。

Add Host后如下圖:

在一臺(tái)準(zhǔn)備做master的主機(jī)add label io.rancher.host.name=master,這個(gè)標(biāo)簽在docker compose里用來(lái)區(qū)分主從機(jī):

Slave鏡像制作
The master-container inside the host can NOT talk to the slave-containers on the other hosts – because containers on each host will be in their own separate network. So they can not communicate.

Port Mapping: While creating a container, we will be mapping the exposed ports of containers to a host port. So, by talking to host on the mapped port, you will be talking to the actual container.
java.rmi.server.hostname Property: As the containers have their own ip addresses, we need to make Jmeter to communicate via host ip by updating java.rmi.server.hostname. For more info on java rmi properties, check here.
So, 我們需要重新制作一個(gè)指定Host IP的slave鏡像,這里用環(huán)境變量取值實(shí)現(xiàn),dockerfile如下:
FROM malfurionpd/jmeter-base
MAINTAINER adeng <343753091@qq.com>
# Ports to be exposed from the container for JMeter Slaves/Server
EXPOSE 1099 50000
# Application to run on starting the container
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
-Dserver.rmi.localport=50000 \
-Dserver_port=1099 \
-Djava.rmi.server.hostname=${HOST_IP}
添加應(yīng)用
Add Stack 就是填寫docker-compose.yml和rancher-compose.yml。

由于slave集群在壓測(cè)過(guò)程中往往由于壓力過(guò)大出現(xiàn)各種rmi異常導(dǎo)致崩潰,我們把主從分別建兩個(gè)Stack。

jmeter-master的docker-compose.yml配置如下:
version: '2'
services:
master:
image: malfurionpd/jmeter-master
stdin_open: true
network_mode: host
tty: true
ports:
- 60000:60000/tcp
labels:
io.rancher.scheduler.affinity:host_label: io.rancher.host.name=master
io.rancher.container.pull_image: always
jmeter-master的rancher-compose.yml配置如下:
version: '2'
services:
master:
scale: 1
start_on_create: true
jmeter-slaves的docker-compose.yml配置如下:
version: '2'
services:
slave01:
image: malfurionpd/jmeter-slave-ip
environment:
HOST_IP: 10.0.7.14
stdin_open: true
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: host.ip=10.0.7.14
slave02:
image: malfurionpd/jmeter-slave-ip
environment:
HOST_IP: 10.0.7.7
stdin_open: true
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: host.ip=10.0.7.7
slave03:
image: malfurionpd/jmeter-slave-ip
environment:
HOST_IP: 10.0.7.5
stdin_open: true
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: host.ip=10.0.7.5
slave04:
image: malfurionpd/jmeter-slave-ip
environment:
HOST_IP: 10.0.7.3
stdin_open: true
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: host.ip=10.0.7.3
slave05:
image: malfurionpd/jmeter-slave-ip
environment:
HOST_IP: 10.0.7.11
stdin_open: true
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:host_label: host.ip=10.0.7.11
jmeter-slaves的rancher-compose.yml配置如下:
version: '2'
services:
slave01:
scale: 1
start_on_create: true
slave02:
scale: 1
start_on_create: true
slave03:
scale: 1
start_on_create: true
slave04:
scale: 1
start_on_create: true
slave05:
scale: 1
start_on_create: true
瞬間集群搭好了:

愉快的玩耍
登錄master,運(yùn)行一個(gè)jmx測(cè)試腳本:
malfurionpd$ ssh root@x.x.x.x
[root@VM_7_2_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16599e89729a malfurionpd/jmeter-master "/bin/bash" 5 minutes ago Up 5 minutes r-jmeter-master-1-0e2ce4cd
2f413226daf1 rancher/net:holder "/.r/r /rancher-entry" 2 days ago Up 2 days r-ipsec-ipsec-3-9061379e
32164227a861 rancher/dns:v0.15.1 "/rancher-entrypoint." 2 days ago Up 2 days r-network-services-metadata-dns-3-362d1496
15b3f4d6730d rancher/net:v0.11.2 "/rancher-entrypoint." 2 days ago Up 2 days r-ipsec-ipsec-cni-driver-3-3430dbdd
a024b39bd9c9 rancher/healthcheck:v0.3.1 "/.r/r /rancher-entry" 2 days ago Up 2 days r-healthcheck-healthcheck-3-e5a0a09c
037ff2e87c84 rancher/metadata:v0.9.1 "/rancher-entrypoint." 2 days ago Up 2 days r-network-services-metadata-3-469fa945
71bf613ede11 rancher/network-manager:v0.7.1 "/rancher-entrypoint." 2 days ago Up 2 days r-network-services-network-manager-3-72af28c8
7275306fe9d1 rancher/agent:v1.2.2 "/run.sh run" 2 days ago Up 2 days rancher-agent
[root@VM_7_2_centos ~]# docker attach 16599e89729a
root@VM_7_2_centos:/# cd /jmeter/apache-jmeter-3.2/bin/
root@VM_7_2_centos:/jmeter/apache-jmeter-3.2/bin# wget https://x.x.x/jmetertest/backend-healthcheck.jmx
--2017-06-15 13:33:13-- https://x.x.x/jmetertest/backend-healthcheck.jmx
Resolving x.x.x (x.x.x)... x.x.x.x
Connecting to x.x.x (x.x.x.x)|x.x.x|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6744 (6.6K) [application/octet-stream]
Saving to: 'backend-healthcheck.jmx'
backend-healthcheck.jmx 100%[========================================================================================>] 6.59K --.-KB/s in 0s
2017-06-15 13:33:13 (1.03 GB/s) - 'backend-healthcheck.jmx' saved [6744/6744]
root@VM_7_2_centos:/jmeter/apache-jmeter-3.2/bin# ./jmeter -n -t backend-healthcheck.jmx -Djava.rmi.server.hostname=10.0.7.2 -Dclient.rmi.localport=60000 -R10.0.7.14,10.0.7.7,10.0.7.5,10.0.7.7,10.0.7.11
Creating summariser <summary>
Created the tree successfully using backend-healthcheck.jmx
Configuring remote engine: 10.0.7.14
Configuring remote engine: 10.0.7.7
Configuring remote engine: 10.0.7.5
Configuring remote engine: 10.0.7.7
Configuring remote engine: 10.0.7.11
Starting remote engines
Starting the test @ Thu Jun 15 13:37:46 UTC 2017 (1497533866012)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary = 4 in 00:00:01 = 4.9/s Avg: 347 Min: 315 Max: 398 Err: 0 (0.00%)
Tidying up remote @ Thu Jun 15 13:37:47 UTC 2017 (1497533867854)
... end of run
關(guān)于測(cè)試報(bào)告的展示,可以看看這里。
Have fun !
參考1