阿里云的python环境配置上线

--------阿里云
#安装常见的库
sudo apt-get update
sudo apt-get install man gcc make lsof ssh openssl tree vim dnsutils iputils-ping
sudo apt-get install net-tools psmisc sysstat curl telnet traceroute wget libbz2-dev
sudo apt-get install libpcre3 libpcre3-dev libreadline-dev libsqlite3-dev libssl-dev
sudo apt-get install llvm zlib1g-dev git mysql-server mysql-client zip p7zip

---------阿里云数据库的安装
1.sudo apt-get install -y mysql-server mysql-client
2.
如果要远程连接mysql数据库,需要以下步骤:
1>.通过mysql -uroot -proot mysql数据库
2>.创建一个新用户来远程连接
GRANT ALL PRIVILEGES ON . TO ‘lss’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
3>.执行命令:flush privileges;
4>.退出mysql,到/etc/mysql/mysql.conf.d下,编辑mysqld.cnf
cd /etc/mysql/mysql.conf.d
vi mysqld.cnf
找到 “bind-address = 127.0.0.1” , 这一行要注释掉,只需在前面加个#
5>.重启mysql服务
sudo service mysql restart | start | stop #重启、启动、停止
或者:sudo /etc/init.d/mysql restart | start | stop
6>.如果开启了防火墙,请添加3306端口
sudo ufw allow 3306

查询数据库的用户(看到如下内容表示创建新用户成功了)
SELECT DISTINCT CONCAT(‘User: ‘’’,user,’’’@’’’,host,’’’;’) AS query FROM mysql.user;
3.
#mysql5.7修改密码
1>.打开配置文件
sudo vim/etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]里配置
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
skip-grant-tables #跳过密码检测
2>.重启服务
sudo service mysql restart
3>.运行mysql -uroot -p进入,直接回车进入,不需要输入密码
4>.选择mysql系统库,修改密码
show databases;
use mysql;
update user set authentication_string=PASSWORD(“123456”) where user=‘root’;
update user set plugin=“mysql_native_password”;
flush privileges;
quit;
5>.再次打开第一步中的配置文件将skip-grant-tables 注释,保存
6>.再次重启mysql服务。
7>.再次打开mysql,正常输入密码.

---------阿里云python3.6.7的安装
1.安装先决条件(build依赖包)
sudo apt install build-essential libssl-dev libevent-dev libjpeg-dev libxml2-dev libxslt-dev
2.下载你所需的版本安装包
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
3。解压Python-3.6.7.tgz
tar -zxvf Python-3.6.7.tgz
4.建立一个空文件夹,用于存放python3程序        
mkdir /usr/local/python3
5。执行配置文件,编译,编译安装            
cd Python-3.7.6 (进入解压完的Python-3.6.7目录下)
./configure --prefix=/usr/local/python3#执行配置文件
sudo make#编译
sudo make install#编译安装

---------阿里云virtualenvwrapper
1.pip install virtualenvwrapper
2.安装完成后,在~/.bashrc写入以下内容
export WORKON_HOME=~/Envs#设置环境变量
source /usr/local/bin/virtualenvwrapper.sh
第一行:virtualenvwrapper存放虚拟环境目录
第二行:virtrualenvwrapper会安装到python的bin目录下,所以该路径是python安装目录下bin/virtualenvwrapper.s
3.source ~/.bashrc    #读入配置文件,立即生效
4.虚拟环境指向的python解释器
若想指定python版本,可通过"–python"指定python解释器(解释器的路径)
mkvirtualenv --python=/usr/local/python3.5.3/bin/python venv
(mkvirtualenv --python=/usr/local/bin/python3.6 python1816 我的)
5.查看python虚拟环境下的版本
python -V
切换 workon 虚拟环境名
退出 deactivate
删除 rmvirtualenv 虚拟环境名

---------阿里云安装nginx+uwsgi
安装nginx
#http://nginx.org/en/linux_packages.html官网上的安装步骤
1.sudo apt install curl gnupg2 ca-certificates lsb-release
2.echo “deb http://nginx.org/packages/ubuntu lsb_release -cs nginx”
| sudo tee /etc/apt/sources.list.d/nginx.list
3.echo “deb http://nginx.org/packages/mainline/ubuntu lsb_release -cs nginx”
| sudo tee /etc/apt/sources.list.d/nginx.list
4.curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
5.sudo apt-key fingerprint ABF5BD827BD9BF62
6.sudo apt update
7.sudo apt install nginx
8.whereis nginx--------->/etc/nginx#查询nginx在哪
9.访问 39.96.92.116:80 如果出现it work 说明Nginx安装成功

#进入虚拟环境 workon python1816
1.安装uwsgi
对于 Python3.x 版本:
第一步:sudo apt-get install python3-dev
第二步:sudo apt-get install python3-pip
第三部:sudo pip install uwsgi
2. 重启nginx
ps aux|grep nginx#查看进程号
kill -quit master(的进程号)#杀死进程
nginx -t nginx.conf#测试nginx
nginx -c nginx.conf#启动nginx
#nginx -s reload#不需要

3.把项目放在 /home下边
在项目下边创建
cd /home/myblog
1>myblog.ini

[uwsgi]
socket = 39.96.92.116:8080
chdir=/home/myblog
module=myblog.wsgi
master = true
processes=2
threads=2
max-requests=2000
chmod-socket=664
vacuum=true
daemonize = /home/myblog/uwsgi.log

2>myblog.conf

user  root;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    #include /etc/nginx/conf.d/*.conf;
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        access_log      /home/myblog/nginx_access.log;
        error_log       /home/myblog/nginx_error.log;
        client_max_body_size 75M;
        location / {
            proxy_pass http://39.96.92.116:8000;
            include     /etc/nginx/uwsgi_params;
            uwsgi_pass  39.96.92.116:8080;
        }
        location ~~/static {
           root  /home/myblog/static/;
        }       
    }
}

4.本地虚拟环境下执行 pip freeze > requirements.txt-------环境下要安装的东西
阿里云虚拟环境下执行 pip install -r requirements.txt
5.create database myblog charset=utf8
6.python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:0

#数据库出错

raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-we9s5i_l/mysqlclient/
原因是没有安装:libmysqlclient-dev
sudo apt-get install libmysqlclient-dev

你可能感兴趣的:(学学)