Django 是一个开放源代码的 Web 应用框架,由 Python 写成。采用了 MVC 的软件设计模式,使得开发复杂的、数据库驱动的网站变得简单 Django 注重组件的重用性和”可插拔性”,敏捷开发和 DRY 法则(Do not Repeat Yourself)
核心组件
物件导向的映射器,用作数据模型(以 Python 类的形式定义)和 关联性数据库间的媒介
基于正则表达式的 URL 分发器
视图系统,用于处理请求
模板系统
PyDruid
A Python connector for Druid Exposes a simple API to create, execute, and analyze Druid queries
Pandas
Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive
$ uname -a Linux 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/version Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013
# For Fedora and RHEL-derivatives # [Doc]: Other System https://superset.apache.org/installation.html#os-dependencies $ sudo yum upgrade python-setuptools -y $ sudo yum install gcc libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel -y
## Offline 环境下安装 superset # https://pypi.python.org/pypi/superset 下载 superset-0.15.0.tar.gz $ tar zxvf superset-0.15.0.tar.gz $ cd superset-0.15.0 $ python setup.py install
# Create an admin user $ fabmanager create-admin --app superset
Username [admin]: # login name User first name [admin]: # first name User last name [user]: # lastname Email [admin@fab.org]: # email, must unique Password: Repeat for confirmation: Error: the two entered values do not match Password: #superset Repeat for confirmation: #superset // ... Recognized Database Authentications. 2016-12-14 17:53:40,945:INFO:flask_appbuilder.security.sqla.manager:Added user superset db upgrade Admin User superset db upgrade created.
# Initialize the database $ superset db upgrade
// ... INFO [alembic.runtime.migration] Context impl SQLiteImpl. INFO [alembic.runtime.migration] Will assume transactional DDL.
# Load some data to play with $ superset load_examples
Loading examples into <SQLA engine=u'sqlite:////root/.superset/superset.db'> Creating default CSS templates Loading energy related dataset Creating table [wb_health_population] reference 2016-12-14 17:58:09,568:INFO:root:Creating database reference 2016-12-14 17:58:09,575:INFO:root:sqlite:////root/.superset/superset.db Loading [World Bank's Health Nutrition and Population Stats]' Creating table [wb_health_population] reference 2016-12-14 17:58:30,840:INFO:root:Creating database reference 2016-12-14 17:58:30,846:INFO:root:sqlite:////root/.superset/superset.db
# Create default roles and permissions $ superset init
Loading examples into <SQLA engine=u'sqlite:////root/.superset/superset.db'> Creating default CSS templates Loading energy related dataset Creating table [wb_health_population] reference 2016-12-14 17:58:09,568:INFO:root:Creating database reference 2016-12-14 17:58:09,575:INFO:root:sqlite:////root/.superset/superset.db Loading [World Bank's Health Nutrition and Population Stats] Creating table [wb_health_population] reference 2016-12-14 17:58:30,840:INFO:root:Creating database reference 2016-12-14 17:58:30,846:INFO:root:sqlite:////root/.superset/superset.db Creating slices Creating a World's Health Bank dashboard Loading [Birth names] Done loading table! -------------------------------------------------------------------------------- Creating table [birth_names] reference 2016-12-14 17:58:52,276:INFO:root:Creating database reference 2016-12-14 17:58:52,280:INFO:root:sqlite:////root/.superset/superset.db Creating some slices Creating a dashboard Loading [Random time series data] Done loading table! -------------------------------------------------------------------------------- Creating table [random_time_series] reference 2016-12-14 17:58:53,953:INFO:root:Creating database reference 2016-12-14 17:58:53,957:INFO:root:sqlite:////root/.superset/superset.db Creating a slice Loading [Random long/lat data] Done loading table! -------------------------------------------------------------------------------- Creating table reference 2016-12-14 17:59:09,732:INFO:root:Creating database reference 2016-12-14 17:59:09,736:INFO:root:sqlite:////root/.superset/superset.db Creating a slice Loading [Multiformat time series] Done loading table! -------------------------------------------------------------------------------- Creating table [multiformat_time_series] reference 2016-12-14 17:59:10,421:INFO:root:Creating database reference 2016-12-14 17:59:10,426:INFO:root:sqlite:////root/.superset/superset.db Creating some slices Loading [Misc Charts] dashboard Creating the dashboard
# Start the web server on port 8088 $ superset runserver -p 8088
# To start a development web server, use the -d switch # superset runserver -d
# download openssl-0.9.8h-1-setup.exe from http://gnuwin32.sourceforge.net/packages/openssl.htm
Cannot open include file: ‘stdint.h’: No such file or directory
解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Microsoft Visual C++ 2015 Redistributable Update 3 # download vc_redist.x64.exe from https://www.microsoft.com/zh-CN/download/details.aspx?id=53840 $ vim D:\apps\Python27\Lib\distutils\msvc9compiler.py
def get_build_version(): return 9.0 def find_vcvarsall(version): return r'C:\Users\yuzhouwan\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat'
$ cd superset-0.15.4 $ python setup.py install
# Microsoft 提供的 VCForPython27.msi 默认使用 VC2008,而 stdint.h 是从 VC2012 开始支持的 # 2014 年之后,VCForPython27.msi 便不再维护,决定尝试用 ubuntu or remote debug ...
Python相关
Make sure that you use the correct version of ‘pip’
描述
1
Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\apps\Python27\python.exe'
NAME: superset LAST DEPLOYED: Mon Jul 19 08:45:33 2020 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Superset can be accessed via port 9000 on the following DNS name from within your cluster: superset.default.svc.cluster.local
Initially you can login with username/password: admin/admin. WARNING: Persistence is DISABLED !
Finished processing dependencies for superset==0.15.4
$ pip freeze | grep superset superset==0.15.4
# Create an admin user $ fabmanager create-admin --app superset
Username [admin]: # login name User first name [admin]: # first name User last name [user]: # lastname Email [admin@fab.org]: # email, must unique Password: Repeat for confirmation: Error: the two entered values do not match Password: #superset Repeat for confirmation: #superset // ... Recognized Database Authentications. 2016-12-14 17:53:40,945:INFO:flask_appbuilder.security.sqla.manager:Added user superset db upgrade Admin User superset db upgrade created.
$ superset db upgrade $ superset init $ superset load_examples
# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)" # Do not run this as root! $ wget https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install --no-check-certificate $ mv install install.rb $ vim install.rb
# abort "Don't run this as root!" if Process.uid == 0
$ vim ./lib/python2.7/site-packages/superset/forms.py
'others_category': (BetterBooleanField, { "label": _("Others category"), "default": True, "description": _("Aggregate data outside of topN into a single category") }),
# Druid query timezone # tz.tzutc() : Using utc timezone # tz.tzlocal() : Using local timezone # other tz can be overridden by providing a local_config DRUID_IS_ACTIVE = True DRUID_TZ = tz.tzlocal() # +08:00
# then could just run "superset runserver -a 0.0.0.0 -p 9097"
Unknown column ‘datasources.filter_select_enabled’ in ‘field list’
描述
1
InternalError: (pymysql.err.InternalError) (1054, u"Unknown column 'datasources.filter_select_enabled' in 'field list'") [SQL: u'SELECT datasources.created_on AS datasources_created_on, datasources.changed_on AS datasources_changed_on, datasources.id AS datasources_id, datasources.datasource_name AS datasources_datasource_name, datasources.is_featured AS datasources_is_featured, datasources.is_hidden AS datasources_is_hidden, datasources.filter_select_enabled AS datasources_filter_select_enabled, datasources.description AS datasources_description, datasources.default_endpoint AS datasources_default_endpoint, datasources.user_id AS datasources_user_id, datasources.cluster_name AS datasources_cluster_name, datasources.offset AS datasources_offset, datasources.cache_timeout AS datasources_cache_timeout, datasources.params AS datasources_params, datasources.perm AS datasources_perm, datasources.changed_by_fk AS datasources_changed_by_fk, datasources.created_by_fk AS datasources_created_by_fk \nFROM datasources \nWHERE datasources.datasource_name = %(datasource_name_1)s \n LIMIT %(param_1)s'] [parameters: {u'param_1': 1, u'datasource_name_1': u'bi-dfp-oms-detail'}]
解决
1 2
$ superset db upgrade $ superset refresh_druid
Issues with Druid timezones
描述
Those methods that named tzutc and tzlocal in tz work for me… Oh no.. They are not working when i upgrade superset from v0.13.2 into v0.15.4, even if i try to use DRUID_TZ = tz.gettz(‘Asia/Shanghai’) :-(
# druid02 192.168.1.12 MySQL $ ps -ef | grep mysql | grep -v druid | grep -v grep
mysql 11435 8530 0 14:13 pts/4 00:00:00 /bin/sh /home/mysql/bin/mysqld_safe --defaults-file=/home/mysql/my.cnf mysql 12192 11435 0 14:13 pts/4 00:00:00 /home/mysql/bin/mysqld --defaults-file=/home/mysql/my.cnf --basedir=/home/mysql --datadir=/home/mysql/data --plugin-dir=/home/mysql/lib/mysql/plugin --log-error=/home/mysql/data/druid02.err --open-files-limit=8192 --pid-file=/home/mysql/data/druid02.pid --socket=/home/mysql/data/mysql.sock --port=3306 mysql 12223 8530 0 14:13 pts/4 00:00:00 mysql -uroot -p -S /home/mysql/data/mysql.sock
$ su - mysql $ mysql -uroot -p -S /home/mysql/data/mysql.sock mysql> show databases; mysql> create database superset; mysql> show databases; mysql> use superset;
ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
描述
1 2 3 4 5 6 7 8 9 10 11
(superset) [root@superset01 superset-0.15.4]# ./bin/python ./lib/python2.7/site-packages/superset/cli.py runserver -d -p 9097 /root/superset-0.15.4/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.script is deprecated, use flask_script instead. .format(x=modname), ExtDeprecationWarning /root/superset-0.15.4/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy is deprecated, use flask_sqlalchemy instead. .format(x=modname), ExtDeprecationWarning /root/superset-0.15.4/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sqlalchemy._compat is deprecated, use flask_sqlalchemy._compat instead. .format(x=modname), ExtDeprecationWarning /root/superset-0.15.4/lib/python2.7/site-packages/flask_cache/init.py:152: UserWarning: Flask-Cache: CACHE_TYPE is set to null, caching is effectively disabled. warnings.warn("Flask-Cache: CACHE_TYPE is set to null, " /root/superset-0.15.4/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead. .format(x=modname), ExtDeprecationWarning
# cmake 版本过低(这里是没有安装) # https://cmake.org/ (stable: 3.6.3, lastest: 3.7.1, date: 2016/12/16) # https://cmake.org/cmake/help/v3.6/ $ wget --no-check-certificate https://cmake.org/files/v3.6/cmake-3.6.3.tar.gz # To connect to cmake.org insecurely $ tar zxvf cmake-3.6.3.tar.gz $ cd cmake-3.6.3 $ ./bootstrap $ make $ gmake install
$ cmake -version $ cmake version 3.6.3 $ CMake suite maintained and supported by Kitware (kitware.com/cmake).
# reboot (should)
$ cd ~ $ mkdir virtualenv $ cd virtualenv $ virtualenv env1 $ virtualenv --python=/usr/bin/python env1
# new problem # IOError: [Errno 40] Too many levels of symbolic links: '/root/virtualenv/env1/bin/python' # 不能直接 rm -rf env1,需要用 rmvirtualenv 才行 $ rmvirtualenv env1 $ cd env1 $ source bin/activate # 退出 deactivate (env1) [root@edeppreapp01 env1] # python -V Python 2.7.12
Could not find a version that satisfies the requirement pytz>dev
描述
1 2 3 4 5 6 7 8 9 10 11 12
# 如果一个一个依赖去安装 会很麻烦 Could not find a version that satisfies the requirement pytz>dev (from celery==3.1.23) (from versions: ) Could not find a version that satisfies the requirement billiard<3.4,>=3.3.0.23 (from celery==3.1.23) (from versions: ) No matching distribution found for amqp<2.0,>=1.4.9 (from kombu==3.0.35) No matching distribution found for anyjson>=0.3.3 (from kombu==3.0.35) No matching distribution found for kombu<3.1,>=3.0.34 (from celery==3.1.23) No matching distribution found for celery==3.1.23 (from superset) Could not find suitable distribution for Requirement.parse('werkzeug==0.11.10') pip install thrift-0.9.3.tar.gz No matching distribution found for six (from sasl==0.2.1) No matching distribution found for sasl>=0.2.1 (from thrift-sasl==0.2.1) No local packages or working download links found for thrift-sasl>=0.2.1
$ ./configure --enable-shared CFLAGS=-fPIC //--enable-shared option means to generate dynamic library libpython2.7.so.1.0 make && make install
# Not work $ python --version Python 2.7.12
$ python Python 2.7.12 (default, Dec 19 2016, 10:58:27) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> File "/usr/local/lib/python2.7/ssl.py", line 97, in <module> >>> import _ssl # if we can't import it, let the error propagate >>> ImportError: No module named _ssl >>> quit()
#修改 Setup 文件 $ vim /root/software/Python-2.7.12/Modules/Setup # Socket module helper for socket(2) _socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: #SSL=/usr/local/ssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto
# 重新编译 $ cd /root/software/Python-2.7.12 $ make && make install
$ python Python 2.7.12 (default, Dec 19 2016, 11:08:33) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>>
$ cd /root/virtualenv/superset/bin [root@olap03-sit bin]# python Python 2.7.12 (default, Dec 19 2016, 11:08:33) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license"for more information. >>> import ssl
$ /root/virtualenv/superset/bin/python Python 2.7.12 (default, Dec 16 2016, 16:23:17) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2 Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> File "/usr/local/python27/lib/python2.7/ssl.py", line 97, in <module> >>> import _ssl # if we can't import it, let the error propagate >>> ImportError: No module named _ssl
$ ./python Python 2.7.12 (default, Dec 19 2016, 11:08:33) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> quit() >>> [root@olap03-sit bin]# >>> [root@olap03-sit bin]# >>> [root@olap03-sit bin]# pwd >>> /root/virtualenv/superset/bin >>> [root@olap03-sit bin]# /root/virtualenv/superset/bin/python >>> Python 2.7.12 (default, Dec 19 2016, 11:08:33) >>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 >>> Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> quit() >>> [root@olap03-sit bin]# python >>> Python 2.7.12 (default, Dec 19 2016, 11:08:33) >>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 >>> Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> >>> source bin/activate >>> (superset) [root@olap03-sit superset]# which python >>> /root/virtualenv/superset/bin/python >>> (superset) [root@olap03-sit superset]# python >>> Python 2.7.12 (default, Dec 19 2016, 11:08:33) >>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 >>> Type "help", "copyright", "credits" or "license"for more information. >>> import ssl >>> quit()
# ImportError: No module named gunicorn.app.base import gunicorn.app.base
python: error while loading shared libraries: libpython2.7.so.1.0
描述
1 2 3 4
$ ./configure --prefix=/usr/local/python27 --enable-shared CFLAGS=-fPIC //--enable-shared option means to generate dynamic library libpython2.7.so.1.0 $ make && make install $ python -V python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
An unknown error occurred. (Status: 0) Maybe the request timed out?
描述
部分图标 无法正常显示
解决
1 2 3 4 5
# 打开 debug 模式,查看详细日志,定位问题 $ vim ./lib/python2.7/site-packages/superset/config.py
# DEBUG = False DEBUG = True
ImportError: No module named pymysql
解决
pip install pymysql
uHost druid01 is not allowed to connect to this MySQL server
描述
nohup superset runserver -a 0.0.0.0 -p 8888 2>&1 &
1
2017-01-22 16:36:53,013:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: (pymysql.err.InternalError) (1130, u"Host 'druid01' is not allowed to connect to this MySQL server")
解决
1
GRANT ALL PRIVILEGES ON *.* TO 'root'@'druid01' IDENTIFIED BY 'root' WITH GRANT OPTION;
Permission for Druid
解决
增加新的数据源之后,需要 superset init,来更新 permission 相关的数据表
Update Druid Cluster’s Name
解决
1 2 3 4 5
alter table datasources drop FOREIGN KEY `datasources_ibfk_2`; update clusters set cluster_name='Druid Cluster'where cluster_name='druid cluster'; update datasources set cluster_name ='Druid Cluster'where cluster_name ='druid cluster'; alter table datasources add constraint `datasources_ibfk_2` FOREIGN KEY (`cluster_name`) REFERENCES `clusters` (`cluster_name`); # show create table datasources; # troubleshooting
$ yarn yarn install v1.3.2 info No lockfile found. [1/4] Resolving packages... error An unexpected error occurred: "https://registry.yarnpkg.com/@vx%2fbounds: ETIMEDOUT". info If you think this is a bug, please open a bug report with the information provided in"/home/superset/software/incubator-superset-0.22.1/superset/assets/yarn-error.log". info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
解决
1 2 3 4 5 6
# 由于不知名的外星力量,需要先替换掉原始的 IP 地址 $ vim /etc/hosts 104.16.59.173 registry.yarnpkg.com