Docker镜像仓库
参考官方文档
https://hub.docker.com/r/hyper/docker-registry-web/
1.准备好目录,下载docker-compose
mkdir /opt/harbor
cd /opt/harbor
####下载 harbor
wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz
tar xf harbor-offline-installer-v1.6.1.tgz
# 快速安装compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
cd harbor
vim harbor.cfg
##
hostname=10.0.122.57
harbor_admin_password = Harbor12345
##
#执行安装脚本
./install.sh
#浏览器访问
10.0.122.57
添加项目,推送镜像
#准备好一个镜像
docker tag centos7 10.0.122.57/library/busybox:v1
docker images
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://mb8n4btz.mirror.aliyuncs.com"],
"insecure-registries": ["https://10.0.122.57"]
}
#登录用户
docker login 10.0.122.57
Username:admin
Password:Harbor12345
Login Succeeded
#推送镜像
docker push 10.0.122.57/library/busybox:v1
编排启动镜像,参数含义可查阅官方文档
(让脚本自动拉取镜像)
mkdir /opt/my_wordpress/
cd /opt/my_wordpress/
vim docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
volumes:
- /data/db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- /data/web_data:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
启动脚本
[root@docker01 my_wordpress]docker-compose up
#启动方法:docker-compose up
#后台启动方法:docker-compose up -d
浏览器访问
10.0.122.57:8000
注意: 不要选择中文,很慢
进行 wordpress 的安装即可
haproxy 代理后端 docker容器
[root@docker01 my_wordpress]# vim docker-compose.yml
---
version: '3'
services:
db:
image: mysql:5.7
volumes:
- /data/db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- /data/web_data:/var/www/html
ports:
- "80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
2、同时启动两台 wordpress
[root@docker01 my_wordpress]docker-compose scale db=1 wordpress=2
WARNING: The scale command is deprecated. Use the up command with the --scale
flag instead.
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done
Creating my_wordpress_wordpress_2 ... done
3、安装 haproxy
[root@docker01 ~]# yum install haproxy -y
4、修改haproxy配置文件
关于配置文件的详细说明,参考:https://www.cnblogs.com/MacoLee/p/5853413.html
[root@docker01 ~]cp /etc/haproxy/haproxy.cfg{,.bak}
[root@docker01 ~] vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot
/var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user
group haproxy
daemon
stats socket /var/lib/haproxy/stats level admin #支持命令行控制
haproxy
defaults
mode
http
log global
option
httplog
option
dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option
retries 3
timeout http-request
timeout queue 1m
timeout connect 10s
timeout client
1m
timeout server
1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
redispatch
10s
listen stats
mode http
bind 0.0.0.0:8888
stats enable
stats uri /haproxy-status
stats auth
admin:123456
frontend frontend_www_example_com
bind 10.0.122.57:8000
mode http
option httplog
log global
default_backend backend_www_example_com
backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance roundrobin
server web-node1 10.0.122.57:32768 check inter 2000 rise 6fall 4
server web-node2 10.0.122.57:32769 check inter 2000 rise 6fall 4
5、启动 haproxy
systemctl start haproxy
systemctl enable haproxy
6、编写php测试页
放到/data/web_data下,在浏览器中访问可以查看当前访问节点信息
[root@docker01 web_data]# vim check.php
<html>
<head>
<title>PHP测试</title>
</head>
<body>
<?php echo '<p>Hello World </p>'; ?>
<?php echo "访问的服务器地址是:"."
<fontcolor=red>"._SERVER['SERVER_NAME']."
</font>"."
";
?>
</body>
</html>
7、使用浏览器访问状态页面
http://10.0.122.57:8888/haproxy-status
可以看到后端节点的监控状况,
8、安装 socat 直接操作 socket 控制 haproxy
1、安装软件
yum install socat.x86_64 -y
2、查看帮助
[root@docker01 web_data] echo "help"|socat stdio /var/lib/haproxy/stats
3、下线后端节点
echo "disable server backend_www_example_com/web-node2"|socat stdio
/var/lib/haproxy/stats
4、上线后端节点
echo "enable server backend_www_example_com/web-node3"|socat stdio
/var/lib/haproxy/stats