• Django(python)项目部署环境搭建命令(附自动执行环境搭建脚本内容)


    Django项目部署环境搭建命令整理。
    过程过于繁琐,可直接跳转至本文shell脚本部分

    安装python(如果用到sqlite,建议先升级sqlite)

    yum -y groupinstall "Development tools"
    yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
    mkdir /usr/local/python3
    tar -xvJf Python-3.6.2.tar.xz    #通过官方网站下载
    cd Python-3.6.2
    ./configure --prefix=/usr/local/python3
    make && make install 
    
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
    
    #修改pip源
    mkdir .pip
    vi .pip/pip.conf    #写入以下内容
    --------
    [global]
    index-url=http://mirrors.aliyun.com/pypi/simple/
    
    [install]
    trusted-host=mirrors.aliyun.com
    --------
    
    #升级pip
    pip3 install --upgrade pip
    pip3 install virtualenv
    
    #解决virtualenv全局访问的问题:
    vi /etc/profile +   #写入以下内容
    
        PATH=$PATH:/usr/local/python3/bin
    # echo PATH=$PATH:/usr/local/python3/bin >> /etc/profile
    
    source /etc/profile
    
    升级setuptools:
    
    python -m pip install --upgrade setuptools
    /usr/local/python3/lib/python3.6/site-packages/virtualenv
    ------------------
    python3的卸载示例
    # 删除以下文件
    rm -rf /usr/local/lib/python3.6
    rm -rf /usr/local/bin/2to3-3.6 to
    rm -rf /usr/local/bin/pyvenv-3.6
    rm -rf /usr/local/bin/pydoc3.6
    rm -rf /usr/local/bin/idle3.6
    

    安装nginx

    yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel
    wget -c https://nginx.org/download/nginx-1.16.1.tar.gz
    tar -zxvf nginx-1.16.1.tar.gz
    cd nginx-1.10.1
    ./configure
    make && make install
    
    ln -s /usr/local/nginx/sbin/nginx /usr/bin/
    

    升级centos7 sqlite3

    #下载地址:https://www.sqlite.org/2021/sqlite-autoconf-3350100.tar.gz
    /usr/bin/sqlite3 --version   #查看当前sqlite版本
    3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
    wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz[根据具体版本进行修改]
    tar -zxvf sqlite-autoconf-3280000.tar.gz
    
    yum groupinstall "Development Tools"
    yum install tcl
    
    
    cd sqlite/
    ./configure
    make
    cp -v .libs/libsqlite3.so.0.8.6 /usr/local/lib64/
        # Dont miss the dot in .libs above
    echo "/usr/local/lib64" > /etc/ld.so.conf.d/sqlite-x68_64.conf
    ldconfig
    

    腾讯云服务器卸载自带python3.6

    rpm -qa | grep python3 | xargs rpm -e --allmatches --nodeps
    whereis python3.6
    python3: /usr/lib/python3.6
    find / -name python3
    

    附:shell脚本内容

    由于我自己已提前保存了相关软件包,所以shell脚本里面不再执行下载命令
    提前将sqlite、python、nginx的安装包放置于/root/app路径下方可执行以下内容

    vi init_app.sh   #写入以下内容
    pwd:/root/app                        #根据自己的情况修改
    
    #!/bin/bash
    local_dir=$(pwd)
    yum -y groupinstall "Development tools"
    yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
    mkdir /usr/local/python3
    cd ${local_dir}
    tar -xvJf Python-3.6.2.tar.xz    #通过官方网站下载
    cd Python-3.6.2
    ./configure --prefix=/usr/local/python3
    make && make install 
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
    #安装nginx
    yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel
    cd ${local_dir}
    tar -zxvf nginx-1.16.1.tar.gz
    cd nginx-1.16.1
    ./configure
    make && make install
    
    ln -s /usr/local/nginx/sbin/nginx /usr/bin/
    #升级sqlite
    cd ${local_dir}
    tar -zxvf sqlite-autoconf-3280000.tar.gz
    
    yum groupinstall "Development Tools"
    yum install tcl
    cd ${local_dir}
    cd sqlite/
    ./configure
    make
    cp -v .libs/libsqlite3.so.0.8.6 /usr/local/lib64/
        # Dont miss the dot in .libs above
    echo "/usr/local/lib64" > /etc/ld.so.conf.d/sqlite-x68_64.conf
    ldconfig
    

    执行:

    bash ./init_app.sh
    
  • 相关阅读:
    出现Invalid input of type: 'CacheKey'. Convert to a byte, string or number first
    如果错误发生在某个封装号的模块中,那请查看数据库里面的数据是不是哪里出现问题
    发现匿名用户问题
    关于序列化器中class Meta中属性说明
    序列化和反序列化
    前端出现has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
    出现bad ruqest,查找原因思路
    注册验证出现错误Define UserView.model, UserView.queryset, or override UserView.get_queryset()
    跨域问题
    celery异步使用和启动方法
  • 原文地址:https://www.cnblogs.com/lisicn/p/14211781.html
Copyright © 2020-2023  润新知