报错
failed to initialize database, got error Binary was compiled with 'CGO_ENABL
编译或者调试的时候:
[root@...]# go env -w CGO_ENABLED=1
运行的时候有报错
[root@....]# ./yunwei-cdn-platform-v20240702
./yunwei-cdn-platform-v20240702: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./yunwei-cdn-platform-v20240702)
方法一、本地直接安装glibc
未使用这个方式(比较麻烦),因为当前系统是centos7.9,yum默认安装版本是低于2.28的,需要编译安装,担心兼容性问题
[root@yw-gw yunwei-cdn-platform]# yum install glibc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
方法二、使用容器化
[root@...]# cat Dockerfile
FROM alpine:3.11
WORKDIR /opt
RUN echo 'http://mirrors.aliyun.com/alpine/v3.9/main' > /etc/apk/repositories && echo -e 'http://mirrors.aliyun.com/alpine/v3.9/community' >> /etc/apk/repositories
RUN apk update \
&& apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
RUN apk --no-cache add ca-certificates wget && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add glibc-2.28-r0.apk
# docker build -t alpine:3.17-glibc .
构建镜像
[root@...]# docker build -t alpine:3.17-glibc .
运行
docker run -d -v ./:/opt/ -p 9000:9000 --restart=always -e BROWSER_TZ=Asia/Shanghai --name xxx-platform alpine:3.17-glibc ./xxx-platform-v20240702