点击测试连接 连接成功后上传项目文件 ok
(若出现ModuleNotFoundError: No module named '_ssl' 模块问题,参考https://mp.csdn.net/postedit/89819120)
1、安装python3.6
1.1 先去python官网下载python3安装包
执行命令:
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
1.2 安装zlib-devel包(后面安装pip需要用到,这里先下载,后面就不用重复编译)
yum install zlib-devel
1.3 解压命令:
tar -xvf Python-3.6.5.tgz
1.4 将解压文件移动到 usr/local目录下
mv Python-3.6.5 /usr/local
1.5 在local目录下创建python3目录
mkdir /usr/local/python3
1.6 转到解压文件夹下
cd /usr/local/Python-3.6.5
配置安装目录
./configure --prefix=/usr/local/python3
1.7 编译源码及安装
make && make install
1.8 配置软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
1.9 转到根目录
cd /
输入 python3 看到提示如下信息,表示安装成功
2、安装pip
2.1安装依赖环境(包比较多,所以命令长)
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
2.2 安装setuptools
# 下载安装包
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz
# 解压
tar -zxvf setuptools-19.6.tar.gz
# 切换目录
cd setuptools-19.6
# 安装(分两步执行哦)
python3 setup.py build
python3 setup.py install
2.3 设置软链接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
如软链接设置错误,删除软链接命令
rm -rf /usr/bin/pip3(后面/usr/bin/pip为软链接名称,切记不能加结尾/ 如:/usr/bin/pip3/则表示删除软连接及真实文件)
2.4 回到根目录
cd /
输入: pip3 -V 查看pip版本
查看到如下信息,恭喜安装成功!
# 补充
若 pip3 安装第三方包时出现:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte
解决办法:
yum install python36-setuptools
easy_install-3.6 pip
之后就可以使用pip3了,如:
pip3 install numpy
1、安装mariadb
yum install mariadb-server
2、启动、查看状态、重启
systemctl start mariadb
systemctl status mariadb
systemctl restart mariadb
3、设置开机自启动
systemctl enable mariadb.service
4、初始化数据库配置
mysql_secure_installation
首先是设置密码,会提示先输入密码:
设置密码
Enter current password for root (enter for none):<–直接回车
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,Y回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录, N回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,Y回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,Y回车
初始化MariaDB完成,接下来测试本地登录。
配置文件位置:vim /etc/my.cnf.d/mysql-clients.cnf
1、设置bind-ip,使得外部IP可以访问
vim /etc/my.cnf
在[mysqld]下面加一行:
bind-address = 0.0.0.0
2、进去mysql,开启远程访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
3、将阿里云服务器开放mysql的3306端口
重启服务器!!!!
4、用本地navicate连接远程服务器的mysql
5、将原来的数据库导入到新建的远程服务器连接中(数据库要命名相同)
yum install epel-release
sudo yum install nginx
systemctl start nginx
查看nginx的状态(是否启动):systemctl status nginx
设置nginx开机自启动: systemctl enable nginx
1、
yum install python-setuptools python-devel
pip install virtualenv
pip install virtualenvwrapper
2、编辑 .bashrc文件
vi .bashrc
在其后加上:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
3、重载.bashrc文件
source .bashrc/
4、创建虚拟环境(由于我的项目是python3.6)
创建虚拟环境指定python版本: mkvirtualenv --python=/usr/local/python3/bin/python3.6 mxonline
5、
我们可以通过在本地dos命令里进入到项目的虚拟环境中
pip freeze > requirements.txt 将本地的虚拟环境安装包相信信息导出来
然后在服务器的项目虚拟环境中创建一个requirements.txt,将本地requirements.txt中的安装包信息复制粘贴在服务器的项目虚拟环境中的requirements.txt里
然后再服务器上运行:
pip install -r requirements.txt 安装相应的依赖包
出现如下问题时,安装mysqlclient
pip install mysqlclient
如果安装mysqlclient就使用:
yum install python-devel mariadb-devel -y
再继续安装mysqlclient
pip install mysqlclient
在虚拟环境中输入:
pip install uwsgi
测试uwsgi是否能正常启动
uwsgi --http :8000 --module MxOnline.wsgi
1、首先在项目总目录之下创建一个目录
mkdir conf
2、再进入conf
3、新建 vi mx_nginx.conf,内容如下:
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 服务器公网ip 域名 ; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ZYL/projects/mxonline/media; # 指向django的media目录
}
location /static {
alias /home/ZYL/projects/mxonline/static; # 指向django的static目录
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
4、将该配置文件加入到nginx的启动配置文件中
ln -s /home/ZYL/projects/mxonline/conf/mx_nginx.cnf /etc/nginx/conf.d/
5、再拉去所有的static file到同一个目录
在项目总目录下执行:
python manage.py collectstatic
6、运行nginx
/usr/sbin/nginx
如果遇到 0:80 failed (98: Address already in use) 这个问题
则输入:
killall -9 nginx
/usr/sbin/nginx(重启nginx)
ps aux|grep nginx(查看nginx状态)
在项目总目录下的conf文件下新建uwsgi.ini,内容如下:
uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/ZYL/projects/mxonline
# Django's wsgi file
module = MxOnline.wsgi
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = /root/.virtualenvs/mxonline
启动uwsgi
uwsgi -i /home/ZYL/projects/mxonline/conf/uwsgi.ini
在浏览器中输入 http://服务器公网ip 或 www.你的域名