当前位置:   article > 正文

centos7 Docker可视化管理工具shipyard中文版安装与使用_centos7下docker安装shipyard

centos7下docker安装shipyard

补充:如果shipyard没有显示本地容器和镜像

1、防火墙打开2375端口

  1. firewall-cmd --zone=public --permanent --add-port=2375/tcp
  2. firewall-cmd --reload

2、重启shipyard的容器

  1. docker restart shipyard-controller shipyard-rethinkdb shipyard-swarm-agent shipyard-swarm-manager shipyard-proxy shipyard-certs shipyard-discovery shipyard-rethinkdb
  2. #或者直接重启docker
  3. systemctl restart docker

一、安装与卸载

1、创建自动安装脚本

在服务器下运行

vim backup.sh

然后把下面内容添加到backup.sh 中,保存并退出,

  1. #!/bin/bash
  2. if [ "$1" != "" ] && [ "$1" = "-h" ]; then
  3. echo "Shipyard Deploy uses the following environment variables:"
  4. echo " ACTION: this is the action to use (deploy, upgrade, node, remove)"
  5. echo " DISCOVERY: discovery system used by Swarm (only if using 'node' action)"
  6. echo " IMAGE: this overrides the default Shipyard image"
  7. echo " PREFIX: prefix for container names"
  8. echo " SHIPYARD_ARGS: these are passed to the Shipyard controller container as controller args"
  9. echo " TLS_CERT_PATH: path to certs to enable TLS for Shipyard"
  10. echo " PORT: specify the listen port for the controller (default: 8080)"
  11. echo " IP: specify the address at which the controller or node will be available (default: eth0 ip)"
  12. echo " PROXY_PORT: port to run docker proxy (default: 2375)"
  13. exit 1
  14. fi
  15. if [ -z "`which docker`" ]; then
  16. echo "You must have the Docker CLI installed on your \$PATH"
  17. echo " See http://docs.docker.com for details"
  18. exit 1
  19. fi
  20. ACTION=${ACTION:-deploy}
  21. IMAGE=${IMAGE:-dockerclub/shipyard:latest}
  22. PREFIX=${PREFIX:-shipyard}
  23. SHIPYARD_ARGS=${SHIPYARD_ARGS:-""}
  24. TLS_CERT_PATH=${TLS_CERT_PATH:-}
  25. CERT_PATH="/etc/shipyard"
  26. PROXY_PORT=${PROXY_PORT:-2375}
  27. SWARM_PORT=3375
  28. SHIPYARD_PROTOCOL=http
  29. SHIPYARD_PORT=${PORT:-8080}
  30. SHIPYARD_IP=${IP}
  31. DISCOVERY_BACKEND=etcd
  32. DISCOVERY_PORT=4001
  33. DISCOVERY_PEER_PORT=7001
  34. ENABLE_TLS=0
  35. CERT_FINGERPRINT=""
  36. LOCAL_CA_CERT=""
  37. LOCAL_SSL_CERT=""
  38. LOCAL_SSL_KEY=""
  39. LOCAL_SSL_CLIENT_CERT=""
  40. LOCAL_SSL_CLIENT_KEY=""
  41. SSL_CA_CERT=""
  42. SSL_CERT=""
  43. SSL_KEY=""
  44. SSL_CLIENT_CERT=""
  45. SSL_CLIENT_KEY=""
  46. show_cert_help() {
  47. echo "To use TLS in Shipyard, you must have existing certificates."
  48. echo "The certs must be named ca.pem, server.pem, server-key.pem, cert.pem and key.pem"
  49. echo "If you need to generate certificates, see https://github.com/ehazlett/certm for examples."
  50. }
  51. check_certs() {
  52. if [ -z "$TLS_CERT_PATH" ]; then
  53. return
  54. fi
  55. if [ ! -e $TLS_CERT_PATH ]; then
  56. echo "Error: unable to find certificates in $TLS_CERT_PATH"
  57. show_cert_help
  58. exit 1
  59. fi
  60. if [ "$PROXY_PORT" = "2375" ]; then
  61. PROXY_PORT=2376
  62. fi
  63. SWARM_PORT=3376
  64. SHIPYARD_PROTOCOL=https
  65. LOCAL_SSL_CA_CERT="$TLS_CERT_PATH/ca.pem"
  66. LOCAL_SSL_CERT="$TLS_CERT_PATH/server.pem"
  67. LOCAL_SSL_KEY="$TLS_CERT_PATH/server-key.pem"
  68. LOCAL_SSL_CLIENT_CERT="$TLS_CERT_PATH/cert.pem"
  69. LOCAL_SSL_CLIENT_KEY="$TLS_CERT_PATH/key.pem"
  70. SSL_CA_CERT="$CERT_PATH/ca.pem"
  71. SSL_CERT="$CERT_PATH/server.pem"
  72. SSL_KEY="$CERT_PATH/server-key.pem"
  73. SSL_CLIENT_CERT="$CERT_PATH/cert.pem"
  74. SSL_CLIENT_KEY="$CERT_PATH/key.pem"
  75. CERT_FINGERPRINT=$(openssl x509 -noout -in $LOCAL_SSL_CERT -fingerprint -sha256 | awk -F= '{print $2;}')
  76. if [ ! -e $LOCAL_SSL_CA_CERT ] || [ ! -e $LOCAL_SSL_CERT ] || [ ! -e $LOCAL_SSL_KEY ] || [ ! -e $LOCAL_SSL_CLIENT_CERT ] || [ ! -e $LOCAL_SSL_CLIENT_KEY ]; then
  77. echo "Error: unable to find certificates"
  78. show_cert_help
  79. exit 1
  80. fi
  81. ENABLE_TLS=1
  82. }
  83. # container functions
  84. start_certs() {
  85. ID=$(docker run \
  86. -ti \
  87. -d \
  88. --restart=always \
  89. --name $PREFIX-certs \
  90. -v $CERT_PATH \
  91. alpine \
  92. sh)
  93. if [ $ENABLE_TLS = 1 ]; then
  94. docker cp $LOCAL_SSL_CA_CERT $PREFIX-certs:$SSL_CA_CERT
  95. docker cp $LOCAL_SSL_CERT $PREFIX-certs:$SSL_CERT
  96. docker cp $LOCAL_SSL_KEY $PREFIX-certs:$SSL_KEY
  97. docker cp $LOCAL_SSL_CLIENT_CERT $PREFIX-certs:$SSL_CLIENT_CERT
  98. docker cp $LOCAL_SSL_CLIENT_KEY $PREFIX-certs:$SSL_CLIENT_KEY
  99. fi
  100. }
  101. remove_certs() {
  102. docker rm -fv $PREFIX-certs > /dev/null 2>&1
  103. }
  104. get_ip() {
  105. if [ -z "$SHIPYARD_IP" ]; then
  106. SHIPYARD_IP=`docker run --rm --net=host alpine ip route get 8.8.8.8 | awk '{ print $7; }'`
  107. fi
  108. }
  109. start_discovery() {
  110. get_ip
  111. ID=$(docker run \
  112. -ti \
  113. -d \
  114. -p 4001:4001 \
  115. -p 7001:7001 \
  116. --restart=always \
  117. --name $PREFIX-discovery \
  118. microbox/etcd:latest -addr $SHIPYARD_IP:$DISCOVERY_PORT -peer-addr $SHIPYARD_IP:$DISCOVERY_PEER_PORT)
  119. }
  120. remove_discovery() {
  121. docker rm -fv $PREFIX-discovery > /dev/null 2>&1
  122. }
  123. start_rethinkdb() {
  124. ID=$(docker run \
  125. -ti \
  126. -d \
  127. --restart=always \
  128. --name $PREFIX-rethinkdb \
  129. rethinkdb)
  130. }
  131. remove_rethinkdb() {
  132. docker rm -fv $PREFIX-rethinkdb > /dev/null 2>&1
  133. }
  134. start_proxy() {
  135. TLS_OPTS=""
  136. if [ $ENABLE_TLS = 1 ]; then
  137. TLS_OPTS="-e SSL_CA=$SSL_CA_CERT -e SSL_CERT=$SSL_CERT -e SSL_KEY=$SSL_KEY -e SSL_SKIP_VERIFY=1"
  138. fi
  139. # Note: we add SSL_SKIP_VERIFY=1 to skip verification of the client
  140. # certificate in the proxy image. this will pass it to swarm that
  141. # does verify. this helps with performance and avoids certificate issues
  142. # when running through the proxy. ultimately if the cert is invalid
  143. # swarm will fail to return.
  144. ID=$(docker run \
  145. -ti \
  146. -d \
  147. -p $PROXY_PORT:$PROXY_PORT \
  148. --hostname=$HOSTNAME \
  149. --restart=always \
  150. --name $PREFIX-proxy \
  151. -v /var/run/docker.sock:/var/run/docker.sock \
  152. -e PORT=$PROXY_PORT \
  153. --volumes-from=$PREFIX-certs $TLS_OPTS\
  154. shipyard/docker-proxy:latest)
  155. }
  156. remove_proxy() {
  157. docker rm -fv $PREFIX-proxy > /dev/null 2>&1
  158. }
  159. start_swarm_manager() {
  160. get_ip
  161. TLS_OPTS=""
  162. if [ $ENABLE_TLS = 1 ]; then
  163. TLS_OPTS="--tlsverify --tlscacert=$SSL_CA_CERT --tlscert=$SSL_CERT --tlskey=$SSL_KEY"
  164. fi
  165. EXTRA_RUN_OPTS=""
  166. if [ -z "$DISCOVERY" ]; then
  167. DISCOVERY="$DISCOVERY_BACKEND://discovery:$DISCOVERY_PORT"
  168. EXTRA_RUN_OPTS="--link $PREFIX-discovery:discovery"
  169. fi
  170. ID=$(docker run \
  171. -ti \
  172. -d \
  173. --restart=always \
  174. --name $PREFIX-swarm-manager \
  175. --volumes-from=$PREFIX-certs $EXTRA_RUN_OPTS \
  176. swarm:latest \
  177. m --replication --addr $SHIPYARD_IP:$SWARM_PORT --host tcp://0.0.0.0:$SWARM_PORT $TLS_OPTS $DISCOVERY)
  178. }
  179. remove_swarm_manager() {
  180. docker rm -fv $PREFIX-swarm-manager > /dev/null 2>&1
  181. }
  182. start_swarm_agent() {
  183. get_ip
  184. if [ -z "$DISCOVERY" ]; then
  185. DISCOVERY="$DISCOVERY_BACKEND://discovery:$DISCOVERY_PORT"
  186. EXTRA_RUN_OPTS="--link $PREFIX-discovery:discovery"
  187. fi
  188. ID=$(docker run \
  189. -ti \
  190. -d \
  191. --restart=always \
  192. --name $PREFIX-swarm-agent $EXTRA_RUN_OPTS \
  193. swarm:latest \
  194. j --addr $SHIPYARD_IP:$PROXY_PORT $DISCOVERY)
  195. }
  196. remove_swarm_agent() {
  197. docker rm -fv $PREFIX-swarm-agent > /dev/null 2>&1
  198. }
  199. start_controller() {
  200. #-v $CERT_PATH:/etc/docker:ro \
  201. TLS_OPTS=""
  202. if [ $ENABLE_TLS = 1 ]; then
  203. TLS_OPTS="--tls-ca-cert $SSL_CA_CERT --tls-cert=$SSL_CERT --tls-key=$SSL_KEY --shipyard-tls-ca-cert=$SSL_CA_CERT --shipyard-tls-cert=$SSL_CERT --shipyard-tls-key=$SSL_KEY"
  204. fi
  205. ID=$(docker run \
  206. -ti \
  207. -d \
  208. --restart=always \
  209. --name $PREFIX-controller \
  210. --link $PREFIX-rethinkdb:rethinkdb \
  211. --link $PREFIX-swarm-manager:swarm \
  212. -p $SHIPYARD_PORT:$SHIPYARD_PORT \
  213. --volumes-from=$PREFIX-certs \
  214. $IMAGE \
  215. --debug \
  216. server \
  217. --listen :$SHIPYARD_PORT \
  218. -d tcp://swarm:$SWARM_PORT $TLS_OPTS $SHIPYARD_ARGS)
  219. }
  220. wait_for_available() {
  221. set +e
  222. IP=$1
  223. PORT=$2
  224. echo Waiting for Shipyard on $IP:$PORT
  225. docker pull ehazlett/curl > /dev/null 2>&1
  226. TLS_OPTS=""
  227. if [ $ENABLE_TLS = 1 ]; then
  228. TLS_OPTS="-k"
  229. fi
  230. until $(docker run --rm ehazlett/curl --output /dev/null --connect-timeout 1 --silent --head --fail $TLS_OPTS $SHIPYARD_PROTOCOL://$IP:$PORT/ > /dev/null 2>&1); do
  231. printf '.'
  232. sleep 1
  233. done
  234. printf '\n'
  235. }
  236. remove_controller() {
  237. docker rm -fv $PREFIX-controller > /dev/null 2>&1
  238. }
  239. if [ "$ACTION" = "deploy" ]; then
  240. set -e
  241. check_certs
  242. get_ip
  243. echo "Deploying Shipyard"
  244. echo " -> Starting Database"
  245. start_rethinkdb
  246. echo " -> Starting Discovery"
  247. start_discovery
  248. echo " -> Starting Cert Volume"
  249. start_certs
  250. echo " -> Starting Proxy"
  251. start_proxy
  252. echo " -> Starting Swarm Manager"
  253. start_swarm_manager
  254. echo " -> Starting Swarm Agent"
  255. start_swarm_agent
  256. echo " -> Starting Controller"
  257. start_controller
  258. wait_for_available $SHIPYARD_IP $SHIPYARD_PORT
  259. echo "Shipyard available at $SHIPYARD_PROTOCOL://$SHIPYARD_IP:$SHIPYARD_PORT"
  260. if [ $ENABLE_TLS = 1 ] && [ ! -z "$CERT_FINGERPRINT" ]; then
  261. echo "SSL SHA-256 Fingerprint: $CERT_FINGERPRINT"
  262. fi
  263. echo "Username: admin Password: shipyard"
  264. elif [ "$ACTION" = "node" ]; then
  265. set -e
  266. if [ -z "$DISCOVERY" ]; then
  267. echo "You must set the DISCOVERY environment variable"
  268. echo "with the discovery system used with Swarm"
  269. exit 1
  270. fi
  271. check_certs
  272. echo "Adding Node"
  273. echo " -> Starting Cert Volume"
  274. start_certs
  275. echo " -> Starting Proxy"
  276. start_proxy
  277. echo " -> Starting Swarm Manager"
  278. start_swarm_manager $DISCOVERY
  279. echo " -> Starting Swarm Agent"
  280. start_swarm_agent
  281. echo "Node added to Swarm: $SHIPYARD_IP"
  282. elif [ "$ACTION" = "upgrade" ]; then
  283. set -e
  284. check_certs
  285. get_ip
  286. echo "Upgrading Shipyard"
  287. echo " -> Pulling $IMAGE"
  288. docker pull $IMAGE
  289. echo " -> Upgrading Controller"
  290. remove_controller
  291. start_controller
  292. wait_for_available $SHIPYARD_IP $SHIPYARD_PORT
  293. echo "Shipyard controller updated"
  294. elif [ "$ACTION" = "remove" ]; then
  295. # ignore errors
  296. set +e
  297. echo "Removing Shipyard"
  298. echo " -> Removing Database"
  299. remove_rethinkdb
  300. echo " -> Removing Discovery"
  301. remove_discovery
  302. echo " -> Removing Cert Volume"
  303. remove_certs
  304. echo " -> Removing Proxy"
  305. remove_proxy
  306. echo " -> Removing Swarm Agent"
  307. remove_swarm_agent
  308. echo " -> Removing Swarm Manager"
  309. remove_swarm_manager
  310. echo " -> Removing Controller"
  311. remove_controller
  312. echo "Done"
  313. else
  314. echo "Unknown action $ACTION"
  315. exit 1
  316. fi

注意:如果想使用其他端口,可以修改 SHIPYARD_PORT=${PORT:-8080} 中的8080为其他端口

2、安装

首先设置backup.sh权限

chmod 755 backup.sh 

 然后执行安装

./backup.sh 

返回如下内容代表安装成功:

  1. Shipyard available at http://172.31.36.172:8080
  2. Username: admin Password: shipyard

最后就可以使用服务器ip地址直接访问了,初始账号密码Username: admin Password: shipyard;

如果直接使用http://ip:8080访问防火墙需要打开8080端口

  1. firewall-cmd --zone=public --permanent --add-port=8080/tcp
  2. firewall-cmd --reload

 


详细操作过程:

  1. [root@ip-172-31-36-172 soft]# vim deploy.sh
  2. [root@ip-172-31-36-172 soft]# ./deploy.sh
  3. -bash: ./deploy.sh: Permission denied
  4. [root@ip-172-31-36-172 soft]# chmod 755 deploy.sh
  5. [root@ip-172-31-36-172 soft]# ./deploy.sh
  6. Deploying Shipyard
  7. -> Starting Database
  8. -> Starting Discovery
  9. -> Starting Cert Volume
  10. -> Starting Proxy
  11. -> Starting Swarm Manager
  12. -> Starting Swarm Agent
  13. -> Starting Controller
  14. Waiting for Shipyard on 172.31.36.172:8080
  15. Shipyard available at http://172.31.36.172:8080
  16. Username: admin Password: shipyard
  17. [root@ip-172-31-36-172 gitblit-1.8.0]# firewall-cmd --zone=public --permanent --add-port=8080/tcp
  18. success
  19. [root@ip-172-31-36-172 gitblit-1.8.0]# firewall-cmd --reload
  20. success

3、使用nginx设置域名访问,修改nginx配置文件/etc/nginx/conf.d/default.conf

  1. server {
  2. listen 80;
  3. #listen 443 ssl;
  4. server_name shipyard.*****.com;
  5. #ssl_certificate /etc/nginx/conf.d/mycert.crt;
  6. #ssl_certificate_key /etc/nginx/conf.d/mycert.key;
  7. location / {
  8. proxy_pass http://172.31.36.172:8080;
  9. }
  10. }

 然后重启nginx -s reload就可以使用域名访问了。

4、卸载

执行如下命令,就可以再次步骤一重新安装shipyard

docker rm -f shipyard-controller shipyard-rethinkdb shipyard-swarm-agent shipyard-swarm-manager shipyard-proxy shipyard-certs  shipyard-discovery shipyard-rethinkdb

二、使用

1、增加节点

./deploy.sh | ACTION=node DISCOVERY=etcd://节点IP:4001 bash -s

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/119970
推荐阅读
相关标签
  

闽ICP备14008679号