yum install epel-release -y
yum groupinstall "Development tools" -y
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel zx-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel -y
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz --no-check-certificate
tar xf Python-3.6.5.tar.xz
cd Python-3.6.5
./configure --prefix=/usr/local --with-ensurepip=install --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
pip3.6 install --upgrade pip
pip3.6 install virtualenv
mkdir -p /var/www/html/django
cd /var/www/html/django
virtualenv -p /usr/local/bin/python3.6 .py3env
source .py3env/bin/activate
*** 语法:
开启: source 虚拟环境名称/bin/activate
退出:deactivate
pip install django pymysql mod_wsgi
yum install httpd httpd-devel -y
mod_wsgi-express install-module
结果(根据虚拟目录名称不同,这里结果也略有不同,但大致相同)
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/html/.py3env"
vi /etc/httpd/conf/httpd.conf
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
vi /etc/httpd/conf.d/django.conf
Alias /static /var/www/html/django/django2/common_static #项目名/所有app共享资源文件夹
Require all granted
#项目名
Require all granted
WSGIPythonHome "/var/www/html/django/.py3env" #虚拟环境名
# Listen 80
ServerName 106.14.115.177 #公网ip地址
WSGIDaemonProcess django2 python-path=/var/www/html/django/.py3env/lib/python3.6/site-pachages
WSGIScriptAlias / /var/www/html/django/django2/django2/wsgi.py #项目名
systemctl restart httpd
systemctl enable httpd
注意:此步骤需要在良好的网络下进行,且安装期间不要使用Ctrl+Z退出安装,否则yum将被占用,只有重新连接或者杀死指定进程才能重新安装
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum repolist all | grep mysql
之后会显示可安装的版本列表,默认安装版本为5.7
vi /etc/yum.repos.d/mysql-community.repo
打开repo文件,将其中的5.7版本的enabled=1改为enabled=0以及8.0版本的enabled=0改为enabled=1,结果如下
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 65
mysql-tools-community/x86_64 MySQL Tools Community 69
mysql80-community/x86_64 MySQL 8.0 Community Server 33
# 启动
# systemctl start mysqld
# 开机启动
# systemctl enable mysqld
# systemctl daemon-reload
grep 'temporary password' /var/log/mysqld.log
2018-10-10T12:40:04.498437Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: h0tA=pS_lZ9f
# 最后的h0tA=pS_lZ9f为初始密码
## 登录MySQL
mysql -uroot -p 初始密码
## 修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
# 密码强度默认为中等强度,需要由大写字母、小写字母、特殊符号、数字组成
# 可以先修改密码强度再修改密码
set global validate_password_length=4; (最小值是4,默认为8)
set global validate_password_policy=0
# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
# 之后修改密码便可以使用简单密码
首先使用yum安装上传插件
安装成功后上传Django压缩包(zip格式)并解压
## 上传命令
# rz
## 解压文件
# unzip django2.zip
进入虚拟环境并处于django项目下执行数据迁移操作
# 生成迁移
# python manage.py makemigrations
# 执行迁移
# python manage.py migrate
将各app静态文件集合到公共静态文件中
创建可登录django环境自带后台数据库的超级用户,如不需要可跳过
vi myproject/wsgi.py
注意:myproject为自己项目名称
将主要内容修改为
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
sys.path.append('/var/www/html/django/django2')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# 注意,sys.path.append中的路径根据项目具体路径修改,其目的是连接到Django项目
vi myproject/settings.py
注意:myproject为自己项目名称
将如下内容
ALLOWED_HOSTS = []
改为
# 有域名
ALLOWED_HOSTS = ['*']
# chmod -R 755 /var/www/html
# chown -R apache:apache /var/www/html
# 关闭防火墙
# systemctl stop firewalld
# 开放端口
# 开放
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重新载入
# firewall-cmd --reload