Django (十) 项目部署 1

阿里云部署项目

1, 购买阿里云ECS云服务器(可免费试用1个月)

2, 阿里云实例更换为Ubuntu

3, 安全组配置

4, xshell远程连接

5, 创建虚拟环境:

5.1 linux基本命令
    cd
    ls, ls -a
    pwd
    df -h

    python 
    python3
    apt update
5.2 安装pip(如果存在则不需要安装)
    pip -V
    pip3 -V
    安装pip3: apt install python3-pip
    【安装pip2: apt install python-pip】

5.3 更新pip
    更新pip3: pip3 install --upgrade pip
    更新pip: pip install --upgrade pip

5.4 更新后如出现以下错误(这是pip 10.0.0版本的BUG):
        Traceback (most recent call last): 
        File “/usr/bin/pip3”, line 9, in 
        from pip import main
    解决方法:
        修改 /usr/bin/pip3 文件,
        使用: sudo vim /usr/bin/pip3
        将:            
            from pip import main
            if __name__ == '__main__':
                sys.exit(main())
        改成:
            from pip import __main__
            if __name__ == '__main__':
                sys.exit(__main__._main())
5.5 让pip默认使用python3:
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

5.6 pip命令
 

pip install xxx:安装xxx依赖包

    pip list:查看所有依赖包
    pip freeze:查看新安装的包
    pip uninstall xxx :卸载xxx包
5.7 安装虚拟环境
    更新apt: apt update
    安装虚拟环境:pip install virtualenv virtualenvwrapper

    如果不能使用虚拟环境命令,则需要配置环境变量
    1, 进入root目录: cd root
    2, 使用vim打开.bashrc, 定位到最后:shift+g,并添加以下代码
        export WORKON_HOME=/root/.virtualenvs
        source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

    3, 在root目录创建.virtualenvs目录: mkdir .virtualenvs
    4, 加载修改后的设置,使之生效:source .bashrc
        (如果找不到virtualenvwrapper.sh,
          则将路径改成/usr/local/bin/virtualenvwrapper.sh
    

5.8 创建虚拟环境:  
    mkvirtualenv axfenv
 

6, 安装mysql

apt install mysql-server
【安装过程中切记一定要输入密码】
安装后进入mysql:
[mysql -u 用户名 -p 密码]
mysql -uroot -proot
 

7, 使用Navicat远程连接mysql

7.1 打开Navicat,点击,‘连接’
7.2 在‘常规’中输入连接名,阿里云的主机(填localhost或127.0.0.1),mysql端口, 阿里云mysql用户名和密码
7.3 在‘SSH’选项中填写远程主机ip,端口,远程主机用户名,远程主机密码
7.4 点击‘连接测试’
7.5 如无法连接出现80070007错误,参考以下解决方式:
    解决方案如下:
    1、进入 /etc/ssh/sshd_config 在最下面 加入下面代码
 

KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1Ciphers 3des-cbc,blowfish-cbc,aes128-cbc,aes128-ctr,aes256-ctr

 
    2、执行下面代码
        ssh-keygen -A

    3.重启SSH
        service ssh restart
 
原文地址:https://www.cnblogs.com/gugubeng/p/9723732.html