zoukankan      html  css  js  c++  java
  • 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能够正常访问即为安装成功。
    
  • 相关阅读:
    使用PHP QR Code生成二维码
    thinkphp伪静态(url重写)
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    php各种编码集详解和以及在什么情况下进行使用
    PHP无限极分类生成树方法,无限分级
    PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)
    Js获取当前日期时间及其它操作
    Spring源码解读Spring IOC原理
    java多线程系列六、线程池
    springMVC中ajax的实现
  • 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/13701029.html
Copyright © 2011-2022 走看看