# 配置yum 源
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装官方epel源
yum install -y epel-release
# 安装docker-compose
yum install -y docker-compose
yum install -y git
cd /data
git clone -b develop https://gitee.com/lepus-group/lepus.git
下载地址:https://www.lepus.cc/download/lepus-v50/
cd /data/lepus
tar -zxvf lepus-console.5.0.linux-amd64.tar.gz -C ./lepus-console
复制和修改配置文件
cp setting.example.yml setting.yml
log:
path: "/tmp/lepus_api.log"
level: "debug"
debug: true
dataSource:
eventStorageEngine: mysql
host: lepus.mysql #使用容器内hosts
port: 3306
user: lepus
password: lepuspassword
database: lepus_db
influxHost: 127.0.0.1
influxPort: 8086
influxUser: admin
influxPassword:
influxDatabase: lepus_db
token:
storage: "mysql"
key: "S9p2+dsfM1CzLF=="
name: "lepus-pro"
expired: "3d"
decrypt:
signKey: "1234567890abcdef"
dbPassKey: "L1e2p3u4s5Abc321"
version: "3"
services:
mysql:
image: mysql:5.6
expose:
- "3306"
environment:
TZ: "Asia/Shanghai"
MYSQL_DATABASE: lepus_db
MYSQL_USER: lepus
MYSQL_PASSWORD: lepuspassword
MYSQL_ROOT_PASSWORD: mypassword
command: --character-set-server=utf8
volumes:
- lepus-mysql:/var/lib/mysql
restart: always
redis:
image: redis:5
expose:
- "6379"
command: --requirepass "mypassword" --appendonly yes
volumes:
- lepus-redis:/data
restart: always
nsqlookupd:
image: nsqio/nsq
expose:
- 4160
- 4161
command: /nsqlookupd
restart: always
nsqd:
image: nsqio/nsq
expose:
- 4150
- 4151
volumes:
- lepus-nsq:/data
links:
- "nsqlookupd:nsqlookupd"
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=nsqd
depends_on:
- nsqlookupd
restart: always
lepus:
image: lepus
ports:
- 8080:8080 #暴露lepus-console 8080端口至宿主机
build:
context: .
dockerfile: Dockerfile
environment:
TZ: "Asia/Shanghai"
mysql_user: lepus
mysql_password: lepuspassword
mysql_database: lepus_db
links:
- "mysql:lepus.mysql"
- "redis:lepus.redis"
- "nsqd:lepus.nsq"
depends_on:
- mysql
- redis
- nsqd
restart: always
volumes:
lepus-mysql:
lepus-redis:
lepus-nsq:
FROM golang:alpine AS builder
LABEL MAINTAINER sheaven <sheaven@qq.com>
#配置GO编译环境变量
ENV GO111MODULE=on \
GOOS=linux \
GOARCH=amd64 \
GOPROXY="https://goproxy.cn,direct"
RUN set -xe \
&& sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
&& apk update --no-cache \
&& apk add --no-cache gcc musl-dev
WORKDIR /build/lepus
#只复制编译必须文件至容器
COPY src ./src
COPY build.sh ./build.sh
COPY go.mod ./go.mod
COPY go.sum ./go.sum
RUN set -xe \
&& go mod download \
&& chmod 755 ./build.sh && ./build.sh
FROM alpine
LABEL MAINTAINER sheaven <sheaven@qq.com>
WORKDIR /app/lepus
RUN set -xe \
&& sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \
&& apk update --no-cache \
&& apk add --no-cache ca-certificates tzdata supervisor mysql-client \
&& mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 #新增处理apline镜像运行lepus-console报错问题
ENV TZ Asia/Shanghai
COPY docker/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY docker/supervisor/env.conf /etc/supervisor/conf.d/env.conf
COPY --from=builder /build/lepus/bin /app/lepus/bin
COPY etc/alarm.example.ini /app/lepus/etc/alarm.ini
COPY etc/config.example.ini /app/lepus/etc/config.ini
COPY etc/proxy.example.ini /app/lepus/etc/proxy.ini
COPY init_table.sql /app/lepus/init_table.sql
COPY init_data.sql /app/lepus/init_data.sql
COPY entrypoint.sh /app/lepus/entrypoint.sh
COPY lepus-console /app/lepus/console #复制lepus-console文件至容器目录
ENV DEBUG=false
RUN chmod 755 /app/lepus/entrypoint.sh
CMD ["/app/lepus/entrypoint.sh"]
该文件中主要引入了lepus-console,并处理了alpine 无动态连接库的问题。具体如下:
alpine镜像启动的容器内运行二进制文件会出现:/bin/sh: xxx not found问题
这种情况是因为动态链接库位置错误导致的,alpine镜像使用的是musl libc而不是gun libc。因而动态链接库的位置不一致。
而一般二进制文件在linux系统下编译,动态链接库是到/lib64目录下的,在alpine镜像内无/lib64目录。
可以在基础镜像内执行以处理该问题:
mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
[program:lepus_proxy]
directory=/app/lepus/bin/
command=/app/lepus/bin/lepus_proxy --config=/app/lepus/etc/proxy.ini
autostart = true
autorestart = true
stopsignal = TERM
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
[program:lepus_task]
directory=/app/lepus/bin/
command=/app/lepus/bin/lepus_task --config=/app/lepus/etc/config.ini
autostart = true
autorestart = true
stopsignal = TERM
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
[program:lepus_alarm]
directory=/app/lepus/bin/
command=/app/lepus/bin/lepus_alarm --config=/app/lepus/etc/alarm.ini
autostart = true
autorestart = true
stopsignal = TERM
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
#新增lepus_console运行进程
[program:lepus_console]
directory=/app/lepus/console/
command=/app/lepus/console/lepus_console
autostart = true
autorestart = true
stopsignal = TERM
redirect_stderr = true
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
docker-compose up -d
访问 IP:8080 可以登录界面进行登录,默认管理密码为:admin/lepusadmin