- 修改配置
- 安装nginx
- 安装mysql
- 安装虚拟环境
- 安装uwsgi
- 安装vnc
- Django上线部署流程
1、修改配置
DEBUG=True
ALLOWED_HOSTS = ['*']
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest.settings.prod')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest.settings.prod')
2、安装nginx
nginx download url:http://nginx.org/en/download.html
1. 去网页下载相应版本安装
> wget http://nginx.org/download/nginx-1.20.2.tar.gz
> tar -zxvf nginx-1.20.2.tar.gz
> cd nginx-1.20.2/
> ./configure --prefix=/usr/local/nginx
> make && sudo make install
> sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
> cd ..
> rm -rf nginx-1.20.2*
> sudo nginx
2. 常用指令
启动:nginx
停止:nginx -s stop
重启:nginx -s reload
3. 配置文件
安装路径下的:conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 8000;
server_name localhost;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8808;
uwsgi_param UWSGI_SCRIPT test.wsgi;
uwsgi_param UWSGI_CHDIR /home/wukn/test;
}
location /static {
alias /home/wukn/test/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3、安装mysql
ubuntu 20.04
1. 安装server
sudo apt-get update
sudo apt-get install mysql-server
2. 设置密码及安全配置
sudo mysql_secure_installation
配置项,如下所示
New password: (输入密码)
Re-enter new password: (重复输入)
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (选择N,不删除匿名用户)
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (选择N,允许root远程连接)
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (选择N,不删除test数据库)
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (选择Y,修改权限立即生效)
3. 检测服务
systemctl status mysql.service
4. 配置允许远程访问
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
sudo /etc/init.d/mysql restart
5. 设置权限与密码
sudo mysql
mysql>use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;
mysql> UPDATE user SET host = '%' WHERE user = 'root';
mysql> CREATE DATABASE auto;
mysql> CREATE USER 'www' @'%' IDENTIFIED WITH mysql_native_password BY 'www123?';
mysql> GRANT ALL PRIVILEGES ON autoneo.* TO 'www'@'%' WITH GRANT OPTION;
mysql>flush privileges;
mysql>quit;
4、安装虚拟环境
1. 安装包
pip3 install virtualenv
pip3 install virtualenvwrapper
2. 创建软链接
sudo ln -s ~/.local/bin/virtualenv /usr/bin/virtualenv
sudo cp ~/.local/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh
3. 配置文件
在~/.bash_profile最下面添加下面两行代码
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
4. 更新配置
source ~/.bash_profile
5. 常用指令
创建虚拟环境:mkvirtualenv name
-p python2.7
查看已有的虚拟环境:workon
切换虚拟环境:workon name
退出虚拟环境:deactivate
删除虚拟环境:rmvirtualenv name
5、安装uwsgi
pip3 install uwsgi
创建配置文件:xxx.xml
<uwsgi>
<socket>127.0.0.1:8808</socket>
<chdir>/home/wukn/test</chdir>
<module>test.wsgi</module>
<processes>4</processes>
<daemonize>uwsgi.log</daemonize>
</uwsgi>
启动uwsgi:uwsgi -x xxx.xml
杀死进程:sudo pkill -f uwsgi
查看进程:ps -ef | grep uwsgi
6、安装vnc
1. 安装
sudo apt remove vnc4server
sudo apt update
sudo apt install xserver-xorg-core
sudo apt install tigervnc-standalone-server tigervnc-xorg-extension tigervnc-viewer -y
2. 设置密码
vncpasswd
3. 创建启动文件
vi ~/.vnc/xstartup
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &
4. 加权
sudo chmod 777 ~/.vnc/xstartup
5. 启动
vncserver :1 -localhost no -geometry 1680x1050 -alwaysshared
6. 其他命令
pgrep Xtigervnc
ss -tulpn | egrep -i 'vnc|590'
vncserver -kill :1
7、Django上线部署流程
1. 下载代码
git clone xxx
2. 安装虚拟环境
见
3. 安装mysql
见
4. 安装python包
pip install -r requirement.txt
5. 试运行,检测错误,修复错误
见
6. 安装uwsgi(虚拟环境和host都装)
见
7. 安装nginx
见
8. 启动uwsgi或nginx
|