
一个简单的Go应用程序,用于测试端口是否准备好接受连接,或检查MySQL、PostgreSQL、MongoDB、Redis等服务是否就绪。还可进行HTTP调用并检查响应码和响应文本,支持超时设置,可在等待特定时间后失败。
可下载最新https://github.com/ph4r5h4d/wait4it/releases%EF%BC%8C%E6%88%96%E8%87%AA%E8%A1%8C%E6%9E%84%E5%BB%BA%E3%80%82%E6%9E%84%E5%BB%BA%E5%91%BD%E4%BB%A4%EF%BC%9A%60go build`
支持以下环境变量:
W4IT_TYPE:检查类型(http, tcp, mysql, postgres等)W4IT_TIMEOUT:超时时间(秒)W4IT_HOST:目标主机W4IT_PORT:目标端口W4IT_USERNAME:服务认证用户名W4IT_PASSWORD:服务认证密码W4IT_DBNAME:MySQL/PostgreSQL数据库名W4IT_SSL_MODE:PostgreSQL SSL模式(disable/enable)W4IT_OPERATION_MODE:Redis操作模式(standalone/cluster)W4IT_HTTP_STATUS_CODE:HTTP检查期望状态码W4IT_HTTP_TEXT:HTTP响应中需包含的子字符串W4IT_HTTP_FOLLOW_REDIRECT:HTTP是否跟随重定向(true/false,默认true)支持以下命令行标志:
-type:检查类型(http, tcp, mysql, postgres等)-h:目标主机(默认127.0.0.1)-p:目标端口-t:超时时间(秒,默认30)-u:服务认证用户名-P:服务认证密码-n:MySQL/PostgreSQL数据库名-ssl:PostgreSQL SSL模式(disable/enable)-operation-mode:Redis操作模式(standalone/cluster)-http-status:HTTP检查期望状态码-http-text:HTTP响应中需包含的子字符串-http-follow-redirect:HTTP是否跟随重定向(true/false,默认true)检查TCP端口
bash./wait4it -type=tcp -h=127.0.0.1 -p=8080 -t=60
检查MySQL实例
bash./wait4it -type=mysql -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app
检查PostgreSQL实例
bash./wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable
检查HTTP响应和文本
bash./wait4it -type=http -h=https://farshad.nematdoust.com -t=60 -http-status=200 -http-text="Software Engineer" ./wait4it -type=http -h=https://nematdoust.com -t=60 -http-status=301 -http-follow-redirect=false
检查MongoDB实例
bash./wait4it -type=mongo -p=27017 -t=60 -u=mongoadmin -P=secret -h=127.0.0.1
检查Redis实例
bash# 带密码的Redis ./wait4it -type=redis -p=6379 -t=60 -P=secret -h=127.0.0.1 # 无密码的Redis ./wait4it -type=redis -p=6379 -t=60 -h=127.0.0.1 # Redis集群 ./wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1
检查其他服务
bash# RabbitMQ ./wait4it -type=rabbitmq -p=5267 -t=60 -u=guest -P=guest -h=127.0.0.1 # Memcached ./wait4it -type=memcached -h=127.0.0.1 -p=11211 -t=60 # ElasticSearch ./wait4it -type=elasticsearch -h=http://127.0.0.1 -p=9200 -t=60 # Aerospike ./wait4it -type=aerospike -h=127.0.0.1 -p=3000 -t=60
可在Docker容器中运行,也可作为K8s/OpenShift初始化容器。镜像地址:docker pull ph4r5h4d/wait4it
检查TCP端口
bashdocker run ph4r5h4d/wait4it -type=tcp -h=127.0.0.1 -p=8080 -t=60
检查MySQL实例
bashdocker run ph4r5h4d/wait4it -type=mysql -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app
检查PostgreSQL实例
bashdocker run ph4r5h4d/wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable
检查HTTP响应
bashdocker run ph4r5h4d/wait4it -type=http -h=https://farshad.nematdoust.com -t=60 -http-status=200 -http-text="Software Engineer" docker run ph4r5h4d/wait4it -type=http -h=https://nematdoust.com -t=60 -http-status=301 -http-follow-redirect=false
检查其他服务
bash# MongoDB docker run ph4r5h4d/wait4it -type=mongo -p=32768 -t=60 -u=mongoadmin -P=secret -h=127.0.0.1 # Redis集群 docker run ph4r5h4d/wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1 # ElasticSearch docker run ph4r5h4d/wait4it -type=elasticsearch -h=http://127.0.0.1 -p=9200
环境变量优先级高于命令行参数,若同时设置,以环境变量为准。
http-text时仅检查状态码您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务