yum换源阿里
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
安装依赖
yum -y install gcc
yum -y install gcc-c++
yum -y groupinstall "Development tools"
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
安装python
创建放安装包的文件夹
mkdir -p /data/software
下载python
cd /data/software
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
解压
tar -zxvf Python-3.6.6.tgz
编译到指定路径
mkdir /usr/local/python3
cd Python-3.6.6
./configure --prefix=/usr/local/python3
安装python3
make
make install
建立软连接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
查看是否安装成功
python3
pip3 -V
pip换源
下载pip
yum -y install epel-release
yum -y install python-pip
pip --version 查看pip版本
更新pip
pip install --upgrade pip
永久
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
临时
pip install xxx -i https://pypi.tuna.tsinghua.edu.cn/simple
安装虚拟环境
新建虚拟环境文件夹和网站文件夹
mkdir -p /data/env
mkdir -p /data/wwwroot
新建虚拟环境
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
pip3安装虚拟环境
cd /data/env
virtualenv --python=/usr/bin/python3 pyweb
启动虚拟环境
cd /data/env/pyweb/bin
source activate
退出虚拟环境
deactivate
安装需要的python包
pip3 install django
pip3 install uwsgi
pip3 install PyJWT
给uwsgi建立软连接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
安装mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
检查是否安装成功
rpm -qa | grep mysql
启动 mysql 服务
systemctl start mysqld.service #启动 mysql
systemctl restart mysqld.service #重启 mysql
systemctl stop mysqld.service #停止 mysql
systemctl enable mysqld.service #设置 mysql 开机启动
设置密码
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("123456")where User='root';
mysql> flush privileges;
设置远程主机登录
GRANT ALL PRIVILEGES ON . TO root@’%’ IDENTIFIED BY ‘your password’ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON . TO ‘your username’@’%’ IDENTIFIED BY ‘your password’;
# 执行以下命令,为root 用户添加远程登录的能力。
mysql> GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY “your password”;
添加MySQL用户
mysql>useradd -g qi qi
Django一定要设置跨域
启动项目
python3 manage.py runserver 0.0.0.0:port # 任何端口
uWsgi
安装
pip3 install uwsgi
查看版本
uwsgi --version
做uwsgi测试
# 编辑文件
vim test.py
# 文件内容
def application(env,start_response):
start_response('200 OK',[('Content-Type','text/html')])
return [b"Hello Hero, YANGGEOL "]
# 测试
uwsgi --http :8083 --wsgi-file test.py # port为服务器开放的端口
常用命令
启动:uwsgi --ini uwsgi.ini
停止:uwsgi --stop uwsgi.pid
重启:uwsgi --reload uwsgi.pid
Django配置uwsgi
# 在项目文件下新建 uwsgi.ini
vim uwsgi.ini
# 文件内容
[uwsgi]
#配置和nginx连接的socket连接
socket=127.0.0.1:8997
#配置项目路径,项目的所在目录
chdir=/data/wwwroot/mysite/
#配置wsgi接口模块文件路径,也就是wsgi.py这个文件所在的目录名
wsgi-file=mysite/wsgi.py
#配置启动的进程数
processes=4
#配置每个进程的线程数
threads=2
#配置启动管理主进程
master=True
#配置存放主进程的进程号文件
pidfile=uwsgi.pid
#配置dump日志记录
daemonize=uwsgi.log
Nginx
常用命令
service nginx start #启动
service nginx stop #停止
service nginx reload #重启
安装nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz
解压
tar -zxvf nginx-1.13.7.tar.gz
安装
cd nginx-1.13.7
./configure
make
make install
备份
cp nginx.conf nginx.conf.bak
在server中添加
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8997; # 和uwsgi里的socket一样
uwsgi_param UWSGI_SCRIPT mysite.wsgi;
uwsgi_param UWSGI_CHDIR /data/wwwroot/mysite;
}