lushdog@outlook.com 5 months ago
parent
commit
c7bccb0fcd
7 changed files with 67 additions and 0 deletions
  1. 1 0
      .env.sample
  2. 15 0
      Dockerfile
  3. 9 0
      README.md
  4. 15 0
      docker-compose.yml
  5. 25 0
      entrypoint.sh
  6. BIN
      nexus_client
  7. 2 0
      nexus_client.txt

+ 1 - 0
.env.sample

@@ -0,0 +1 @@
+CLIENT_COUNT=5

+ 15 - 0
Dockerfile

@@ -0,0 +1,15 @@
+FROM debian:bullseye-slim
+
+RUN apt update && apt install -y ca-certificates && rm -rf /var/lib/apt/lists/*
+
+# 设置工作目录
+WORKDIR /app
+
+COPY nexus_client /app/nexus_client
+
+COPY entrypoint.sh entrypoint.sh
+
+RUN chmod +x entrypoint.sh
+
+# 设置默认命令
+ENTRYPOINT ["./entrypoint.sh"]

+ 9 - 0
README.md

@@ -1,2 +1,11 @@
 # nexus-client
 
+## 修改nexus_client.txt 内容, 填入nexus_server的ip和端口
+
+## 设置环境变量
+
+ `cp .env.sample .env` 填入需要开的nexus_client数量
+
+ ## 构建运行
+
+  `docker compose up -d`

+ 15 - 0
docker-compose.yml

@@ -0,0 +1,15 @@
+services:
+  nexus-client:
+    build: .
+    container_name: nexus-client
+    environment:
+      - CLIENT_COUNT=3
+    volumes:
+      - ./logs:/app/logs
+      - ./nexus_client.txt:/app/nexus_client.txt
+    restart: unless-stopped
+    logging:
+      driver: "json-file"
+      options:
+        max-size: "10m"
+        max-file: "3" 

+ 25 - 0
entrypoint.sh

@@ -0,0 +1,25 @@
+#!/bin/bash
+
+CLIENT_COUNT=${CLIENT_COUNT:-"1"}
+
+# 创建日志目录
+mkdir -p /app/logs
+
+# 清空日志文件
+> /app/logs/client.log
+
+# 启动实时日志监控(前台运行)
+tail -f /app/logs/client.log &
+TAIL_PID=$!
+
+for ((COUNT=1; COUNT<=CLIENT_COUNT; COUNT++)); do
+    echo "start $COUNT client"
+    ./nexus_client 2>&1 | while IFS= read -r line; do
+        echo "$(date '+%Y-%m-%d %H:%M:%S') [Client-$COUNT] $line"
+    done >> /app/logs/client.log &
+    sleep 2
+done
+
+wait
+
+echo "=== 所有客户端已完成,tail进程继续运行 ==="

BIN
nexus_client


+ 2 - 0
nexus_client.txt

@@ -0,0 +1,2 @@
+host: 127.0.0.1
+port: 8182