From 6d33cdab88123389a4a441c9fd191ed27a1c5611 Mon Sep 17 00:00:00 2001 From: Heaven Date: Sat, 13 Jun 2020 19:40:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=89=93=E5=8C=85=E9=95=9C?= =?UTF-8?q?=E5=83=8F,=E5=B0=86=E7=8E=AF=E5=A2=83=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=85=A8=E9=83=A8=E8=BD=AC=E4=B8=BA=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E5=86=85=E6=9D=A5=E6=93=8D=E4=BD=9C=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 15 ++--- README.md | 3 +- .../docker-compose.yml | 0 {doc => docker}/named.cn.conf | 0 {doc => docker}/named.dianxin.conf | 0 {doc => docker}/named.jiaoyu.conf | 0 {doc => docker}/named.liantong.conf | 0 {doc => docker}/named.neiwang.conf | 0 docker/nginx_default.conf | 64 +++++++++++++++++++ {doc => docker}/nginx_ops.conf | 7 +- docker/prestart.sh | 31 +++++++++ {doc => docker}/supervisor_ops.conf | 12 ++++ doc/requirements.txt => requirements.txt | 0 13 files changed, 119 insertions(+), 13 deletions(-) rename docker-compose.yml => docker/docker-compose.yml (100%) rename {doc => docker}/named.cn.conf (100%) rename {doc => docker}/named.dianxin.conf (100%) rename {doc => docker}/named.jiaoyu.conf (100%) rename {doc => docker}/named.liantong.conf (100%) rename {doc => docker}/named.neiwang.conf (100%) create mode 100644 docker/nginx_default.conf rename {doc => docker}/nginx_ops.conf (65%) create mode 100644 docker/prestart.sh rename {doc => docker}/supervisor_ops.conf (65%) rename doc/requirements.txt => requirements.txt (100%) diff --git a/Dockerfile b/Dockerfile index ef77967..5eb14b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,11 @@ -FROM opencodo/python - -COPY doc/requirements.txt /tmp/requirements.txt - -RUN pip3 install -r /tmp/requirements.txt +FROM registry.cn-hangzhou.aliyuncs.com/sourcegarden/python:centos7-3.6 ADD . /var/www/codo-dns/ +RUN pip3 install -r /var/www/codo-dns/requirements.txt -VOLUME /var/log/ - -COPY doc/nginx_ops.conf /etc/nginx/conf.d/default.conf -COPY doc/supervisor_ops.conf /etc/supervisord.conf +COPY docker/nginx_default.conf /etc/nginx/nginx.conf +COPY docker/nginx_ops.conf /etc/nginx/conf.d/codo-admin.conf +COPY docker/supervisor_ops.conf /etc/supervisord.conf +EXPOSE 80 CMD ["/usr/bin/supervisord"] \ No newline at end of file diff --git a/README.md b/README.md index 80c0dec..4d3a995 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ ##### 添加解析 ![menus](./doc/images/add_domain_zone.png) ##### 同步配置文件 + ![menus](./doc/images/python3_domain_sync.png) #### 项目部署 @@ -62,7 +63,7 @@ curl -I -X GET -m 10 -o /dev/null -s -w %{http_code} http://dns.opendevops.cn: [BIND 搭建](./doc/bind.md) #### 多区域支持 -- 把doc下的所有的named 开头的文件放入 bind服务器的 /var/named/chroot/etc/ 目录下 +- 把docker下的所有的named 开头的文件放入 bind服务器的 /var/named/chroot/etc/ 目录下 - 这里是和 settings 下的默认bind配置文件进行关联 #### 自定义区域 diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to docker/docker-compose.yml diff --git a/doc/named.cn.conf b/docker/named.cn.conf similarity index 100% rename from doc/named.cn.conf rename to docker/named.cn.conf diff --git a/doc/named.dianxin.conf b/docker/named.dianxin.conf similarity index 100% rename from doc/named.dianxin.conf rename to docker/named.dianxin.conf diff --git a/doc/named.jiaoyu.conf b/docker/named.jiaoyu.conf similarity index 100% rename from doc/named.jiaoyu.conf rename to docker/named.jiaoyu.conf diff --git a/doc/named.liantong.conf b/docker/named.liantong.conf similarity index 100% rename from doc/named.liantong.conf rename to docker/named.liantong.conf diff --git a/doc/named.neiwang.conf b/docker/named.neiwang.conf similarity index 100% rename from doc/named.neiwang.conf rename to docker/named.neiwang.conf diff --git a/docker/nginx_default.conf b/docker/nginx_default.conf new file mode 100644 index 0000000..e5709d3 --- /dev/null +++ b/docker/nginx_default.conf @@ -0,0 +1,64 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl http2 default_server; +# listen [::]:443 ssl http2 default_server; +# server_name _; +# root /usr/share/nginx/html; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_ciphers HIGH:!aNULL:!MD5; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /etc/nginx/default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + +} \ No newline at end of file diff --git a/doc/nginx_ops.conf b/docker/nginx_ops.conf similarity index 65% rename from doc/nginx_ops.conf rename to docker/nginx_ops.conf index b822152..053dd63 100644 --- a/doc/nginx_ops.conf +++ b/docker/nginx_ops.conf @@ -1,4 +1,4 @@ -upstream codo-dns{ +upstream codo-dns-nginx{ server 127.0.0.1:9100; server 127.0.0.1:9101; } @@ -7,12 +7,13 @@ upstream codo-dns{ server { listen 80; server_name dns.opendevops.cn; + access_log /var/log/nginx/codo-dns-access.log; + error_log /var/log/nginx/codo-dns-error.log; location / { proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; - proxy_pass http://codo-dns; - + proxy_pass http://codo-dns-nginx; } } \ No newline at end of file diff --git a/docker/prestart.sh b/docker/prestart.sh new file mode 100644 index 0000000..c9079dc --- /dev/null +++ b/docker/prestart.sh @@ -0,0 +1,31 @@ +#!/bin/sh +cd /var/www/codo-dns/ + +#域名管理 +CRON_DB_DBNAME='codo_dns' +sed -i "s#cookie_secret = .*#cookie_secret = '${cookie_secret}'#g" settings.py && \ +sed -i "s#DEFAULT_DB_DBHOST = .*#DEFAULT_DB_DBHOST = os.getenv('DEFAULT_DB_DBHOST', '${DEFAULT_DB_DBHOST}')#g" settings.py && \ +sed -i "s#DEFAULT_DB_DBPORT = .*#DEFAULT_DB_DBPORT = os.getenv('DEFAULT_DB_DBPORT', '${DEFAULT_DB_DBPORT}')#g" settings.py && \ +sed -i "s#DEFAULT_DB_DBUSER = .*#DEFAULT_DB_DBUSER = os.getenv('DEFAULT_DB_DBUSER', '${DEFAULT_DB_DBUSER}')#g" settings.py && \ +sed -i "s#DEFAULT_DB_DBPWD = .*#DEFAULT_DB_DBPWD = os.getenv('DEFAULT_DB_DBPWD', '${DEFAULT_DB_DBPWD}')#g" settings.py && \ +sed -i "s#DEFAULT_DB_DBNAME = .*#DEFAULT_DB_DBNAME = os.getenv('DEFAULT_DB_DBNAME', '${CRON_DB_DBNAME}')#g" settings.py && \ +sed -i "s#READONLY_DB_DBHOST = .*#READONLY_DB_DBHOST = os.getenv('READONLY_DB_DBHOST', '${READONLY_DB_DBHOST}')#g" settings.py && \ +sed -i "s#READONLY_DB_DBPORT = .*#READONLY_DB_DBPORT = os.getenv('READONLY_DB_DBPORT', '${READONLY_DB_DBPORT}')#g" settings.py && \ +sed -i "s#READONLY_DB_DBUSER = .*#READONLY_DB_DBUSER = os.getenv('READONLY_DB_DBUSER', '${READONLY_DB_DBUSER}')#g" settings.py && \ +sed -i "s#READONLY_DB_DBPWD = .*#READONLY_DB_DBPWD = os.getenv('READONLY_DB_DBPWD', '${READONLY_DB_DBPWD}')#g" settings.py && \ +sed -i "s#READONLY_DB_DBNAME = .*#READONLY_DB_DBNAME = os.getenv('READONLY_DB_DBNAME', '${CRON_DB_DBNAME}')#g" settings.py + + +try_num=0 + +while [[ $try_num -le 100 ]]; +do + if $(curl -s ${DEFAULT_DB_DBHOST}:${DEFAULT_DB_DBPORT} > /dev/null);then + python3 db_sync.py + exit 0 + else + echo 'wait mysql start to do db_sync.py' + fi + let try_num+=1 + sleep 6 +done \ No newline at end of file diff --git a/doc/supervisor_ops.conf b/docker/supervisor_ops.conf similarity index 65% rename from doc/supervisor_ops.conf rename to docker/supervisor_ops.conf index d1328c5..9d34c74 100644 --- a/doc/supervisor_ops.conf +++ b/docker/supervisor_ops.conf @@ -4,6 +4,18 @@ nodaemon=true [group:dns] programs=dns +[program:dns-prestart] +command=sh docker/prestart.sh +directory=/var/www/codo-dns +user=root +autostart = true +autorestart=false +redirect_stderr=true +stdout_logfile=/var/log/supervisor/codo-dns-prestart.log +loglevel=info +logfile_maxbytes=10MB +logfile_backups=1 + [program:dns] command=python3 startup.py --service=dns --port=91%(process_num)02d process_name=%(program_name)s_%(process_num)02d diff --git a/doc/requirements.txt b/requirements.txt similarity index 100% rename from doc/requirements.txt rename to requirements.txt