容器系列(四):基础组件构建
文章目录
1. DM7镜像制作
DM7镜像制作,主要分为3个步骤:
- 添加安装包
- dminit执行初始化
- 启动dmserver
1. 添加安装包
DM7镜像制作时,只需要dm7安装包解压缩后的bin
目录文件。
文件 dmdbms.tar.gz 内的目录结果如下:
1 2 3 4 5 |
--dmdbms |-- bin |-- ... |-- data |-- log |
data和log为空目录
Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
FROM base-alpine:latest AS build LABEL maintainer="zxb@dameng.com" ADD ./dmdbms.tar.gz /opt COPY entrypoint.sh switchDmLog.sh /opt/ FROM base-alpine:latest ENV DM7_INSTANCE_NAME instance \ BUFFER 100 \ MAX_BUFFER 100 COPY --from=build /opt /opt RUN apk add --no-cache tini && \ rm -rf /var/cache/apk/* && \ mv /opt/entrypoint.sh /bin/entrypoint.sh && \ mv /opt/switchDmLog.sh /bin/switchDmLog.sh EXPOSE 5236 VOLUME [ "/opt/dmdbms/data" ] CMD ["/bin/entrypoint.sh"] ENTRYPOINT ["/sbin/tini", "--"] |
2. 执行初始化
entrypoint.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/bash INSTANCE_NAME=${DM7_INSTANCE_NAME} DEM_FLAG=${DM7_DEM_FLAG} ADMIN_PWD=${SYSDBA_PWD} INSTANCE_BUFFER=${BUFFER} INSTANCE_MAX_BUFFER=${MAX_BUFFER} export LANG=en_US.UTF-8 if [ ! -d "/opt/dmdbms/data/DAMENG" ]; then cd /opt/dmdbms/bin ./dminit PATH=/opt/dmdbms/data PAGE_SIZE=16 CASE_SENSITIVE='N' UNICODE_FLAG=1 SYSDBA_PWD=${ADMIN_PWD} echo "Init DM7 success!" sed -i.bak "s/MAX_SESSIONS = 100/MAX_SESSIONS = 1000/g; \ s/KEEP = 8/KEEP = 64/g; \ s/SORT_BUF_SIZE = 2/SORT_BUF_SIZE = 50/g; \ s/BUFFER = 100/BUFFER = ${INSTANCE_BUFFER}/g; \ s/MAX_BUFFER = 100/MAX_BUFFER = ${INSTANCE_MAX_BUFFER}/g" \ /opt/dmdbms/data/DAMENG/dm.ini; echo "Finished config dm.ini." fi current_year_month=`date +%Y%m` DM_LOG=dm_DMSERVER_${current_year_month}.log ln -s /opt/dmdbms/log/${DM_LOG} /opt/dmdbms/log/dm_DMSERVER.log echo "Finished soft link DM7 current ${DM_LOG} to dm_DMSERVER.log" echo "5 0 1 * * root /bin/switchDmLog.sh" > /opt/switchDmLogCron /usr/bin/crontab /opt/switchDmLogCron echo "Start Cron Service" /usr/sbin/crond echo "Start DM7 Service" cd /opt/dmdbms/bin exec ./dmserver /opt/dmdbms/data/DAMENG/dm.ini |
上述脚本中,当数据目录不存在时,会执行
dminit
程序完成数据库初始化工作。
switchDmLog.sh
1 2 3 4 5 6 |
#!/bin/bash current_year_month=`date +%Y%m` DM_LOG=dm_DMSERVER_${current_year_month}.log rm -rf /opt/dmdbms/log/dm_DMSERVER.log ln -s /opt/dmdbms/log/${DM_LOG} /opt/dmdbms/log/dm_DMSERVER.log echo "Finished switch DM7 current ${DM_LOG} to dm_DMSERVER.log" |
switchDmLog.sh脚本主要用于完成软链接的切换,其实用途不大,可以删除掉。
3. 启动服务
在 entryponit.sh 最后一行,前台方式启动了 dmserver
1
|
exec ./dmserver /opt/dmdbms/data/DAMENG/dm.ini |
因为 DM7 是数据库系统,所以文件盘建议是通过挂载的方式将宿主机的目录挂载到容器中,避免容器重新创建后数据丢失。
2. MySQL镜像
MySQL 镜像直接采用的官方镜像,该镜像主要需要设置2个环境变量:
1 2 |
MYSQL_ROOT_PASSWORD=xxx MYSQL_ROOT_HOST=% |
docker-compose:
1 2 3 4 5 6 7 8 9 10 11 12 |
version: '2.4' services: mysql: image: mysql:5 command: --default-authentication-plugin=mysql_native_password environment: - MYSQL_ROOT_PASSWORD=xxxxxx - MYSQL_ROOT_HOST=% volumes: - /data/mysql:/var/lib/mysql ports: - 3306:3306 |
3. vsftpd镜像
使用容器搭建 ftp 时,不要采用默认的主动模式,应采用被动模式。
Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 |
FROM base-alpine:latest RUN apk add --no-cache vsftpd \ && adduser -h /home/admin -s /bin/false -D admin COPY vsftpd.conf /etc/vsftpd/ COPY docker-entrypoint.sh / VOLUME /home/admin EXPOSE 20 21 10090-10100 CMD /docker-entrypoint.sh |
vsftpd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
anonymous_enable=YES local_enable=YES write_enable=YES local_umask=002 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_file=/var/log/xferlog xferlog_std_format=NO log_ftp_protocol=YES use_localtime=YES max_clients=5000 max_per_ip=1000 accept_timeout=120 connect_timeout=120 data_connection_timeout=600 pam_service_name=vsftpd dual_log_enable=YES seccomp_sandbox=NO vsftpd_log_file=/var/log/vsftpd.log allow_writeable_chroot=YES passwd_chroot_enable=YES chroot_local_user=YES pasv_enable=YES pasv_max_port=10100 pasv_min_port=10090 |
docker-entrypoint.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/bin/sh if [ -z ${PASSWORD} ]; then PASSWORD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-8};echo;) echo "Generated password for user 'admin': ${PASSWORD}" fi # set ftp user password echo "admin:${PASSWORD}" |/usr/sbin/chpasswd chown admin:admin /home/admin/ -R # set ip echo -e "\npasv_address=${HOST_IP}" >> /etc/vsftpd/vsftpd.conf if [ -z $1 ]; then /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf else $@ fi |
docker-compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
version: '2.4' services: vsftpd: build: ./vsftpd image: vsftpd:latest ports: - "20:20" - "21:21" - "10090-10100:10090-10100" environment: PASSWORD: "xxxxxx" HOST_IP: "192.168.52.10" volumes: - /data/ftp:/home/admin |
文章作者 张雄彪
上次更新 2019-09-29