CentOS8本地安裝Redash中文版,並且配置為生產環境


Centos8內置的Python為3.6.8版本,以下是在內置Python3.6.8基礎上的安裝步驟。由於安裝多版本Python會導致系統底層庫需要下載源碼重新編譯,比較麻煩,不建議在多版本Python環境下安裝Redash中文版。

本地安裝Redash中文版

1、初始化

改國內源:
cd /etc/yum.repos.d/
sudo rm -f CentOS-Base.repo CentOS-AppStream.repo CentOS-PowerTools.repo CentOS-centosplus.repo CentOS-Extras.repo
sudo curl -o CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
sudo yum makecache

更新系統包:
sudo yum update

安裝常用包:
sudo yum -y install gcc gcc-c++ kernel-devel make zlib zlib-devel libffi-devel openssl-devel git

當前用戶添加到root組:
sudo usermod -aG root 當前centos用戶名

2、安裝PostgreSql9.6

安裝PostgreSql9.6初始化並配置為系統啟動時自動啟動:
sudo dnf install @postgresql:9.6
sudo dnf install postgresql-contrib
sudo yum install postgresql-devel
sudo postgresql-setup initdb
sudo systemctl enable --now postgresql

登錄Postgresql:
sudo -u postgres psql

更改postges密碼:
alter user postgres with password '密碼';

創建角色:
create role 當前centos用戶名;

賦予登錄權限:
alter role 當前centos用戶名 login;

退出postgresql終端:
\q

3、安裝Redis

sudo yum install redis
sudo systemctl start redis
sudo systemctl enable redis.service 

4、安裝Nodejs

sudo yum install nodejs
sudo npm config set registry https://registry.npm.taobao.org
sudo npm install n -g
sudo /usr/local/bin/n stable

5、安裝Redash中文版

1、下載代碼:
   git clone https://github.com/dazdata/redash.git
   cd redash
2、前端安裝依賴包:npm install
3、前端打包:npm run build
4、配置pip國內源:sudo cp pip.conf /etc/pip.conf
5、安裝Python虛擬環境:sudo pip3 install virtualenv
6、創建Python虛擬環境:virtualenv venv
7、激活Python虛擬環境:source venv/bin/activate
8、安裝Pip包:
  pip install -r requirements.txt -r requirements_dev.txt -r requirements_bundles.txt
9、初始化數據庫表結構:./manage.py database create_tables
10、退出虛擬環境,安裝完成:deactivate

6、啟動

分別打開三個終端,都執行cd redash進入目錄后分別執行下列三個命令之一:
source venv/bin/activate
./manage.py runserver --debugger --reload
和
source venv/bin/activate
./manage.py rq worker
和
source venv/bin/activate
./manage.py rq scheduler

打開瀏覽器,輸入地址:http://localhost:5000

配置為生產環境

在此基礎上升級為Nginx+Supervisor+uWSGI的生產環境部署

一、安裝和測試uWSGI

1、安裝:
sudo yum -y install python36-devel
sudo pip3 install uwsgi

2、配置:
進入項目目錄:cd ~/redash
創建配置文件:sudo nano uwsgi.ini
[uwsgi]
http=:5000
chdir=/home/當前centos用戶名/redash/
wsgi-file=redash/wsgi.py
callable=app
master=true
virtualenv=/home/當前centos用戶名/redash/venv/                       
pythonpath=/home/當前centos用戶名/redash/
processes=1
threads=2
保存退出,先配置成http方式,便於從瀏覽器訪問,后續配合nginx將改為socket方式。
注意這只是基本配置,高級配置請參考uWSGI官網中文文檔
https://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/WSGIquickstart.html

3、啟動:
uwsgi uwsgi.ini
進入瀏覽器輸入http://localhost:5000即可訪問,
注意其它worker和scheduler還是以終端方式進虛擬環境啟動。
運行無問題,證明已用uwsgi啟動了redash,先Ctrl+C停止uwsgi服務繼續進行后續配置。

二、安裝和測試Supervisor

1、安裝SuperVisor:
sudo pip3 install supervisor 

2、配置:
進入項目目錄:cd ~/redash
先用命令生成默認配置文件:echo_supervisord_conf > supervisord.conf 
打開配置文件:sudo nano supervisord.conf 修改其中86/87行,去掉行頭注釋符;
[program:redash] 
command = uwsgi uwsgi.ini
在文件結尾插入下列內容,用於啟動redash的worker和scheduler
[program:worker]
directory=/home/當前centos用戶名/redash/
command=venv/bin/python3 ./manage.py rq worker

[program:scheduler]
directory=/home/當前centos用戶名/redash/
command=venv/bin/python3 ./manage.py rq scheduler
保存退出,注意這只是基本配置,高級配置請參考http://supervisord.org/

3、啟動
supervisord -c supervisord.conf
進入瀏覽器輸入http://localhost:5000即可訪問,注意這時worker和scheduler也已用supervisor進行管理,
不需要另外啟動。可用supervisorctl status查看三個進程,運行無問題,
證明已用supervisor啟動了含uwsgi的redash全部進程。
先運行supervisorctl stop all停止進程(最好重啟系統),繼續后續配置。

三、安裝Nginx並全部啟動

1、安裝Nginx:
sudo yum install nginx

2、修改配置:sudo nano /etc/nginx/nginx.conf 將location /加入如下內容
location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:5000;
}
保存退出

3、改uwsgi協議:
進入項目目錄:cd ~/redash
修改配置文件:sudo nano uwsgi.ini的第2行並新增第3行
socket=127.0.0.1:5000
chmod-socket=666
保存退出

4、啟動:
supervisord -c supervisord.conf
systemctl start nginx
進入瀏覽器輸入http://127.0.0.1:80能夠正常訪問即為安裝成功。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM