简介

蓝鲸智云PaaS平台是一个开放式的开发平台,让开发者可以方便快捷地创建、开发、部署和管理SaaS应用。

github仓库: https://github.com/Tencent/bk-Paas

结构

源码包含

Paas 包含4大服务,均基于python2.7+django1.8开发

  • login 蓝鲸统一登录服务,支持用户及角色管理,支持对接企业内部登录体系
  • paas 蓝鲸开发者中心&web工作台,提供自助化、自动化服务,支持快速、低成本、免运维地构建SaaS应用
  • esb 蓝鲸API网关,提供自助化、自动化服务,支持快速、低成本、免运维地构建SaaS应用
  • appengine 蓝鲸应用引擎,提供统一的SaaS应用开发框架, 提升开发效率

Paasagent 蓝鲸应用引擎,go语言开发

安装

要安装paas服务,需要需要准备相应的环境

  • mysql 5.6+
  • redis
  • Nginx 开发环境和生产环境都建议
  • supervisor
  • python 2.7.15+

安装mysql

我这里是centos8.1的系统,直接包含有mysql-8.0

1dnf -y install mysql-server
2
3# 运行mysql
4systemctl enable --now mysql

创建一个数据库和普通账户用于paas应用

1create database open_paas character set utf8;
2create user openpaas identified by 'your_password';
3grant all on open_paas.* to openpaas@'%';

安装redis

1dnf -y install redis
2systemctl enable --now redis

安装nginx

1dnf -y install nginx
2systemctl enable --now nginx

安装python2.7.16

1dnf -y install python2 python2-devel openssl-devel zlib-devel

下载bk-Paas

1dnf -y install git
2mkdir /data && cd /data
3git clone https://github.com/Tencent/bk-PaaS.git
4
5cd bk-Paas/paas-ce/paas

配置paas相关服务

备注:如果用的MySQL8.0pymysql需要升级到最新版本0.9.3 uwsgi建议升级到最新版本

另外login服务还需要下面两个包:xlrd==1.2.0 xlwt==1.1.2

appengine应用引擎

 1cd appengine
 2pip install -r requirements.txt
 3
 4# 修改配置文件,修改用户名和密码
 5vim controller/settings.py
 6DATABASES = {
 7    'default': {
 8        'ENGINE': 'django.db.backends.mysql',
 9        'NAME': 'open_paas',
10        'USER': 'root',
11        'PASSWORD': '',
12        'HOST': '127.0.0.1',
13        'PORT': '3306',
14    }
15}
16
17# 运行appengine
18export BK_ENV="production"
19python manage.py runserver 127.0.0.1:8000

paasweb工作台

 1cd paas
 2cp conf/settings_production.py{.sample,}
 3
 4# 修改配置文件,数据库相关配置
 5DATABASES = {
 6    'default': {
 7        'ENGINE': 'django.db.backends.mysql',
 8        'NAME': 'open_paas',
 9        'USER': 'root',
10        'PASSWORD': '',
11        'HOST': '127.0.0.1',
12        'PORT': '3306',
13    }
14}
15
16# 运行
17export BK_ENV="production"
18python manage.py runserver 127.0.0.1:8001

esb企业总线

 1cd esb
 2cp configs/default{_template,}.py
 3# 修改数据库相关配置
 4vim configs/default.py
 5DATABASES = {
 6    'default': {
 7        'ENGINE': 'django.db.backends.mysql',
 8        'NAME': 'open_paas',
 9        'USER': 'root',
10        'PASSWORD': '',
11        'HOST': '127.0.0.1',
12        'PORT': '3306',
13    }
14}
15
16# 运行
17export BK_ENV="production"
18python manage.py runserver 127.0.0.1:8002

login统一登录服务

 1cd login
 2cp conf/settings_production.py{.sample,}
 3
 4# 修改数据库配置
 5vim conf/settings_production.py
 6DATABASES = {
 7    'default': {
 8        'ENGINE': 'django.db.backends.mysql',   # �~X认�~T�mysql
 9        'NAME': 'open_paas',
10        'USER': 'root',
11        'PASSWORD': '',
12        'HOST': '127.0.0.1',
13        'PORT': '3306',
14    }
15}
16
17# 运行
18export BK_ENV="production"
19python manage.py runserver 127.0.0.1:8003

nginx反向代理

  1vim /etc/nginx/conf.d/paas.conf
  2# upstream - web
  3upstream OPEN_PAAS {
  4    server 127.0.0.1:8001 max_fails=1  fail_timeout=30s;
  5}
  6upstream OPEN_PAAS_APPENGINE {
  7    server 127.0.0.1:8000 max_fails=1  fail_timeout=30s;
  8}
  9upstream OPEN_PAAS_ESB {
 10    server 127.0.0.1:8002 max_fails=1  fail_timeout=30s;
 11}
 12upstream OPEN_PAAS_LOGIN {
 13    server 127.0.0.1:8003 max_fails=1  fail_timeout=30s;
 14}
 15
 16# upstream - paasagent
 17upstream PAAS_AGENT_TEST {
 18    server 192.168.1.1:8085 max_fails=1  fail_timeout=30s;
 19}
 20upstream PAAS_AGENT_PROD {
 21    server 192.168.1.2:8085 max_fails=1  fail_timeout=30s;
 22}
 23# proxy_next_upstream  http_502 http_504 error timeout invalid_header;
 24
 25server {
 26    listen       80;
 27    server_name  www.bking.com;
 28
 29    access_log /var/log/nginx/openpaas_osce_access.log;
 30    error_log /var/log/nginx/openpaas_osce_error.log;
 31
 32    client_max_body_size    512m;
 33
 34    # ============================ paas ============================
 35    # PAAS_SERVICE HOST/PORT
 36    location / {
 37        proxy_pass http://OPEN_PAAS;
 38        proxy_pass_header Server;
 39        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 40        proxy_set_header X-Real-IP $remote_addr;
 41        proxy_set_header X-Scheme $scheme;
 42        proxy_set_header Host $http_host;
 43        proxy_redirect off;
 44        proxy_read_timeout 600;
 45    }
 46
 47    # PAAS_SERVICE HOST/PORT, for doc
 48    location ~ ^/doc/(.*) {
 49        proxy_pass http://OPEN_PAAS/static/doc/$1$is_args$args;
 50        proxy_pass_header Server;
 51        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 52        proxy_set_header X-Real-IP $remote_addr;
 53        proxy_set_header X-Scheme $scheme;
 54        proxy_set_header Host $http_host;
 55        proxy_redirect off;
 56        proxy_read_timeout 600;
 57
 58    }
 59
 60
 61    # ============================ appengine ============================
 62    # ENGINE_SERVICE HOST/PORT
 63    location ~ ^/v1 {
 64        proxy_pass http://OPEN_PAAS_APPENGINE;
 65        proxy_pass_header Server;
 66        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 67        proxy_set_header X-Real-IP $remote_addr;
 68        proxy_set_header Host $http_host;
 69        proxy_set_header X-Scheme $scheme;
 70        proxy_read_timeout 600;
 71    }
 72
 73    # ============================ esb ============================
 74    # ESB_SERVICE HOST/PORT
 75    location ~ ^/api/(.*) {
 76        proxy_pass http://OPEN_PAAS_ESB/$1$is_args$args;
 77        proxy_pass_header Server;
 78        proxy_set_header X-Request-Uri $request_uri;
 79        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 80        proxy_set_header X-Real-IP $remote_addr;
 81        proxy_set_header X-Scheme $scheme;
 82        proxy_set_header Host $http_host;
 83        proxy_redirect off;
 84        proxy_read_timeout 600;
 85    }
 86
 87
 88    # ============================ login ============================
 89    # LOGIN_SERVICE HOST/PORT
 90    location ~ ^/login/(.*) {
 91        proxy_pass http://OPEN_PAAS_LOGIN/$1$is_args$args;
 92        proxy_pass_header Server;
 93        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 94        proxy_set_header X-Real-IP $remote_addr;
 95        proxy_set_header X-Scheme $scheme;
 96        proxy_set_header Host $http_host;
 97        proxy_redirect off;
 98        proxy_read_timeout 600;
 99    }
100
101
102    # ============================ paas_agent ============================
103    # for apps test
104    location ~ ^/t/ {
105        proxy_pass http://PAAS_AGENT_TEST;
106        proxy_pass_header Server;
107        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
108        proxy_set_header X-Real-IP $remote_addr;
109        proxy_set_header X-Scheme $scheme;
110        proxy_set_header Host $http_host;
111        proxy_redirect off;
112        proxy_read_timeout 600;
113    }
114
115    # for apps prod
116    location ~ ^/o/ {
117        proxy_pass http://PAAS_AGENT_PROD;
118        proxy_pass_header Server;
119        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
120        proxy_set_header X-Real-IP $remote_addr;
121        proxy_set_header X-Scheme $scheme;
122        proxy_set_header Host $http_host;
123        proxy_redirect off;
124        proxy_read_timeout 600;
125    }
126
127}

配置完重新加载nginx服务

1nginx -t
2nginx -s reload

登录蓝鲸paas平台

由于是在本地测试环境下部署的,需要手动配置hosts文件 172.16.10.10为部署paas平台的服务器IP

1172.16.10.10 www.bking.com

访问http://www.bking.com

默认登录用户名和密码均为admin

login

dashboard

dev_center

使用supervisor部署python应用

安装supervisor

1pip install supervisor

配置supervisor

 1vim /etc/supervisord.conf
 2[unix_http_server]
 3file=/data/bk-Paas/paas-ce/paas/logs/run/supervisor.sock   ; (the path to the socket file)
 4
 5[supervisord]
 6logfile=/data/bk-Paas/paas-ce/paas/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
 7logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
 8logfile_backups=10           ; (num of main logfile rotation backups;default 10)
 9loglevel=info                ; (log level;default info; others: debug,warn,trace)
10pidfile=/data/bk-Paas/paas-ce/paas/logs/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
11nodaemon=false               ; (start in foreground if true;default false)
12minfds=1024                  ; (min. avail startup file descriptors;default 1024)
13minprocs=200                 ; (min. avail process descriptors;default 200)
14
15[rpcinterface:supervisor]
16supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
17
18[supervisorctl]
19serverurl=unix:///data/bk-Paas/paas-ce/paas/logs/run/supervisor.sock ; use a unix:// URL  for a unix socket
20
21[program:appengine]
22command=/usr/bin/gunicorn wsgi --bind 0.0.0.0:8000 -k gevent -w 4 -n appengine --access-logfile - --error-logfile -
23directory=/data/paas/appengine
24environment=PYTHONPATH=/data/paas/appengine,BK_ENV="production",PAAS_LOGGING_DIR="/data/paas/logs/"
25startsecs=0
26stopwaitsecs=0
27autostart=true
28autorestart=true
29redirect_stderr=true
30stdout_logfile=/data/bk-Paas/paas-ce/paas/logs/appengine_gunicorn.log
31
32
33[program:paas]
34command=/usr/bin/gunicorn wsgi --bind 0.0.0.0:8001 -k gevent -w 4 -n paas --access-logfile - --error-logfile -
35directory=/data/bk-Paas/paas-ce/paas/paas
36environment=DJANGO_SETTINGS_MODULE=settings,PYTHONPATH=/data/paas/paas,BK_ENV="production",PAAS_LOGGING_DIR="/data/bk-Paas/paas-ce/paas/logs/"
37startsecs=0
38stopwaitsecs=0
39autostart=true
40autorestart=true
41redirect_stderr=true
42stdout_logfile=/data/bk-Paas/paas-ce/paas/logs/paas_gunicorn.log
43
44
45[program:esb]
46command=/usr/bin/gunicorn wsgi --bind 0.0.0.0:8002 -k gevent -w 4 -n esb --access-logfile - --error-logfile -
47directory=/data/bk-Paas/paas-ce/paas/esb
48environment=PYTHONPATH=/data/bk-Paas/paas-ce/paas/esb,BK_ENV="production",PAAS_LOGGING_DIR="/data/bk-Paas/paas-ce/paas/logs/"
49startsecs=0
50stopwaitsecs=0
51autostart=true
52autorestart=true
53redirect_stderr=true
54stdout_logfile=/data/bk-Paas/paas-ce/paas/logs/esb_gunicorn.log
55
56
57[program:login]
58command=/usr/bin/gunicorn wsgi --bind 0.0.0.0:8003 -k gevent -w 4 -n login --access-logfile - --error-logfile -
59directory=/data/bk-Paas/paas-ce/paas/login
60environment=DJANGO_SETTINGS_MODULE=settings,PYTHONPATH=/data/paas/login,BK_ENV="production",PAAS_LOGGING_DIR="/data/bk-Paas/paas-ce/paas/logs/"
61startsecs=0
62stopwaitsecs=0
63autostart=true
64autorestart=true
65redirect_stderr=true
66stdout_logfile=/data/bk-Paas/paas-ce/paas/logs/login_gunicorn.log

创建日志文件目录

1mkdir -p /data/bk-Paas/paas-ce/paas/logs/run

运行

1supervisord

查看运行结果

1supervisorctl
2appengine                        RUNNING   pid 3770, uptime 0:00:00
3esb                              RUNNING   pid 3769, uptime 0:00:00
4login                            RUNNING   pid 3137, uptime 0:00:17
5paas                             RUNNING   pid 3136, uptime 0:00:17

好了,paas平台已经搭建好了,后面介绍蓝鲸运维平台的cmdb模块