Skip to content

Commit c88c5fc

Browse files
author
yangmv
committed
edit README
1 parent 32b2234 commit c88c5fc

File tree

9 files changed

+91
-33
lines changed

9 files changed

+91
-33
lines changed

Dockerfile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,33 @@ ENV TZ=Asia/Shanghai
77
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
88

99
# 1. 安装基本依赖
10-
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
10+
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget unzip epel-release nginx xz gcc automake zlib-devel openssl-devel supervisor net-tools groupinstall development libxslt-devel libxml2-devel libcurl-devel git -y
1111

1212
# 2. 准备python
13-
RUN wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
14-
RUN xz -d Python-3.7.1.tar.xz && tar xvf Python-3.7.1.tar && cd Python-3.7.1 && ./configure && make && make install
13+
RUN wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
14+
RUN xz -d Python-3.6.6.tar.xz && tar xvf Python-3.6.6.tar && cd Python-3.6.6 && ./configure && make && make install
1515

1616
# 3. 复制代码
1717
RUN mkdir -p /var/www/
1818
ADD . /var/www/CMDB/
1919

2020
# 4. 安装pip依赖
21-
RUN pip3 install --upgrade pip
22-
RUN pip3 install -r /var/www/CMDB/requirements.txt
21+
RUN pip3 install --user --upgrade pip
22+
RUN pip3 install -r /var/www/SuperCMDB/requirements.txt
2323

2424
# 5. 数据初始化
25-
RUN python3 manage.py makemigrations
26-
RUN python3 manage.py migrate
25+
RUN python3 /var/www/SuperCMDB/manage.py makemigrations
26+
RUN python3 /var/www/SuperCMDB/manage.py migrate
2727

28-
# 5. 准备文件
29-
COPY doc/supervisor_cmdb.conf /etc/supervisord.conf
30-
COPY doc/nginx_cmdb.conf /etc/nginx/conf.d/
28+
# 6. 日志
29+
VOLUME /var/log/
30+
31+
# 7. 准备文件
32+
COPY docs/supervisor_cmdb.conf /etc/supervisord.conf
33+
COPY docs/nginx_cmdb.conf /etc/nginx/conf.d/
3134

3235
EXPOSE 80
33-
CMD ["/usr/bin/supervisord"]
36+
CMD ["/usr/bin/supervisord"]
37+
38+
##### build测试
39+
# docker build -t cmdb .

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ python3 manage.py migrate
3434
```
3535
cat >> /etc/supervisord.conf <<EOF
3636
[program:cmdb]
37-
process_name=cmdb
38-
command=python3 run_server.py
39-
directory=/var/www/CMDB
37+
command=python3 startup.py --port=80%(process_num)02d
38+
process_name=%(program_name)s_%(process_num)02d
39+
numprocs=3
40+
directory=/var/www/SuperCMDB
4041
user=root
42+
autostart=true
4143
autorestart=true
4244
redirect_stderr=true
43-
stdout_logfile=/var/log/cmdb.log
45+
stdout_logfile=/var/log/supervisor/cmdb.log
4446
loglevel=info
4547
logfile_maxbytes=100MB
48+
logfile_backups=3
4649
EOF
4750
4851
supervisorctl update
@@ -52,7 +55,13 @@ supervisorctl reload
5255
#### 五 Nginx配置
5356
```
5457
upstream cmdb{
55-
server 127.0.0.1:8000;
58+
server 127.0.0.1:9000;
59+
server 127.0.0.1:9001;
60+
server 127.0.0.1:9002;
61+
}
62+
63+
location /static {
64+
alias /var/www/CMDB/static;
5665
}
5766
5867
location /api/cmdb/ {
0 Bytes
Binary file not shown.

apps/ws/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def get(self, *args, **kwargs):
164164

165165
ws_urls = [
166166
('/ws/test', WsTest),
167-
('/ws/terminal', WebTerminalHandler)
167+
('/v1/cmdb/ws/terminal', WebTerminalHandler)
168168
]
169169

170170

docker-compose.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
auto_cmdb:
1+
cmdb:
22
restart: unless-stopped
33
image: cmdb_image
44
volumes:
55
- /var/log/supervisor/:/var/log/supervisor/
66
- /sys/fs/cgroup:/sys/fs/cgroup
77
ports:
8-
- "8000:80"
9-
hostname: cmdb-exec01
8+
- "8002:80"
9+
hostname: cmdb-exec01
10+
11+
# docker-compose up -d
12+
# docker-compose down
13+
# 接口测试: http://k8s.yangmv.com:8001/v1/k8s/publish/

docs/nginx_cmdb.conf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
upstream cmdb{
22
server 127.0.0.1:8000;
3+
server 127.0.0.1:8001;
4+
server 127.0.0.1:8002;
35
}
46

57
server
@@ -19,12 +21,9 @@ server
1921
rewrite (.*) /static/favicon.ico;
2022
}
2123

22-
location ^~ /static/ {
23-
alias /var/www/CMDB/static/;
24-
if ($query_string) {
25-
expires max;
26-
}
27-
}
24+
#location /static {
25+
# alias /var/www/CMDB/static;
26+
#}
2827

2928
location /api/cmdb/ {
3029
proxy_set_header Host $http_host;

docs/supervisor_cmdb.conf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
nodaemon=true
33

44
[program:cmdb]
5-
process_name=cmdb
6-
command=python3 run_server.py
7-
directory=/var/www/CMDB
5+
command=python3 startup.py --port=90%(process_num)02d
6+
process_name=%(program_name)s_%(process_num)02d
7+
numprocs=3
8+
directory=/var/www/SuperCMDB
89
user=root
10+
autostart=true
911
autorestart=true
1012
redirect_stderr=true
11-
stdout_logfile=/var/log/cmdb.log
13+
stdout_logfile=/var/log/supervisor/cmdb.log
1214
loglevel=info
1315
logfile_maxbytes=100MB
16+
logfile_backups=3
1417

1518
[program:nginx]
1619
command=/usr/sbin/nginx -g "daemon off;"

libs/Aliyun/oss.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def getObj(self,filename):
6060
if __name__ == '__main__':
6161
oss_config = {
6262
"STORAGE_REGION":"cn-shanghai",
63-
"STORAGE_NAME":"shinezone-opendevops",
63+
"STORAGE_NAME":"xx",
6464
"STORAGE_PATH":"record",
65-
"STORAGE_KEY_ID":"LTAIRiWZ3L2W7NQc",
66-
"STORAGE_KEY_SECRET":"vjUr6a6YcWlUqKO8WEJFLdINCdG42e"
65+
"STORAGE_KEY_ID":"",
66+
"STORAGE_KEY_SECRET":""
6767
}
6868

6969
data = '{"name":"yangmv","age":18}'

startup.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
#encoding:utf-8
3+
'''
4+
@author: yangmv
5+
@file: run_server.py
6+
@time: 18/11/26上午9:44
7+
'''
8+
import tornado.web
9+
import tornado.wsgi
10+
import os
11+
from apps.ws.handler import ws_urls
12+
from ops.settings import DEBUG
13+
from libs.tornado_libs.application import Application as myapplication
14+
from django.core.wsgi import get_wsgi_application
15+
os.environ['DJANGO_SETTINGS_MODULE'] = 'ops.settings'
16+
17+
class Application(myapplication):
18+
def __init__(self,**settings):
19+
wsgi_app = get_wsgi_application()
20+
container = tornado.wsgi.WSGIContainer(wsgi_app)
21+
urls = []
22+
urls.extend(ws_urls)
23+
urls.extend([
24+
("/static/(.*)", tornado.web.StaticFileHandler,dict(path=os.path.join(os.path.dirname(__file__), "static"))),
25+
('.*', tornado.web.FallbackHandler, dict(fallback=container))
26+
])
27+
super(Application,self).__init__(urls,**settings)
28+
29+
def main():
30+
settings = {
31+
'debug' : DEBUG
32+
}
33+
app = Application(**settings)
34+
app.start_server()
35+
36+
if __name__ == '__main__':
37+
main()

0 commit comments

Comments
 (0)