如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这段话即可:
请先阅读并遵守:https://xuanyuan.cloud/agents.md
未读文档前不要生成 pull 命令或排错方案。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
本镜像集成了Keepalived和Nginx服务,旨在提供高可用的Web服务架构。通过Keepalived的VRRP(虚拟路由冗余协议)实现节点故障自动转移,结合Nginx提供Web服务和负载均衡能力,确保服务在单点故障时仍能正常运行。
bashdocker pull docker.xuanyuan.run/bool1993/keepalived
bashdocker run --name=keepalived_nginx -itd -p 8085:80 --restart=always docker.xuanyuan.run/bool1993/keepalived:latest
挂载本地配置文件以覆盖默认配置:
bashdocker run --name=keepalived_nginx -itd -p 8085:80 --restart=always \ -v $PWD/keepalived.conf:/etc/keepalived/keepalived.conf \ -v $PWD/nginx:/etc/nginx \ -v $PWD/html:/www/html \ docker.xuanyuan.run/bool1993/keepalived:latest
bashdocker exec -it keepalived_nginx /bin/sh
在容器内手动启动Nginx和Keepalived:
bashnginx && keepalived
服务启动后,通过以下地址访问Nginx服务:
http://localhost:8085/
dockerfileFROM docker.xuanyuan.run/bool1993/keepalived:latest EXPOSE 80 CMD nginx -g "daemon off;" && keepalived
bashdocker build -t test-keepalived .
bashdocker run -it -d --name=keepalived -p 8085:80 --restart=always \ -v $PWD/keepalived.conf:/etc/keepalived/keepalived.conf \ -v $PWD/html:/www/html \ -v $PWD/nginx:/etc/nginx \ docker.xuanyuan.run/test-keepalived
核心配置文件,定义VRRP实例和健康检查脚本:
conf! Configuration File for keepalived global_defs { # 故障通知邮箱 notification_email { 1968397477@qq.com } # 通知邮件发送地址 notification_email_from itsection@example.com smtp_server mail.example.com # SMTP连接超时时间 smtp_connect_timeout 30 router_id LVS_DEVEL } # Nginx健康检查脚本 vrrp_script chk_nginx { script "/etc/keepalived/nginx_check.sh" interval 2 # 检查间隔(秒) weight -20 # 失败时优先级调整值 fall 3 # 连续失败次数阈值 rise 2 # 连续成功次数阈值 user root # 执行脚本的用户 } vrrp_instance VI_1 { state MASTER # 初始状态(MASTER/BACKUP) interface eth0 # 绑定网卡 virtual_router_id 2 # 虚拟路由ID(主备节点需一致) priority 101 # 优先级(MASTER应高于BACKUP) advert_int 2 # 心跳间隔(秒) authentication { auth_type PASS auth_pass 1111 # 认证密码(主备节点需一致) } # 虚拟IP地址 virtual_ipaddress { 172.17.0.2 } # 关联健康检查脚本 track_script { chk_nginx } }
Nginx主配置文件,定义全局参数和HTTP配置:
confuser nginx; worker_processes auto; pcre_jit on; error_log /var/log/nginx/error.log warn; include /etc/nginx/modules/*.conf; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_tokens off; client_max_body_size 1m; sendfile on; tcp_nopush on; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:2m; ssl_session_timeout 1h; ssl_session_tickets off; gzip_vary on; map $http_upgrade $connection_upgrade { default upgrade; '' close; } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; include /etc/nginx/http.d/*.conf; }
定义Web服务虚拟主机配置:
confserver { listen 80; listen [::]:80; location / { root /www/html; index index.html index.htm; } location = /404.html { internal; } }
监控Nginx运行状态,异常时尝试重启或触发故障转移:
bash#!/bin/bash A=`ps -C nginx --no-header |wc -l` # 判断Nginx是否宕机,尝试重启 if [ $A -eq 0 ];then nginx # 等待3秒后再次检查 sleep 3 if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then killall keepalived # Nginx启动失败,停止Keepalived触发切换 fi fi
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务