django-vue-admin 運(yùn)行記錄
https://django-vue-admin.com/document/hjbs.html
https://django-vue-admin.com/document/hjbs.html
https://bbs.django-vue-admin.com/article/9.html
https://gitee.com/liqianglog/django-vue-admin/tree/demo_project
1. 安裝 ubuntu-20.04.6 桌面版
ubuntu-20.04.6-desktop-amd64.iso
桌面版本
桌面版的目的是 有瀏覽器可以看 django vue 的localhost網(wǎng)頁(yè)。
用server版,需要用別的機(jī)器看,別的機(jī)器在權(quán)限上可能有問(wèn)題。
sudo apt install vim -y
sudo apt install lrzsz
rz
sz
命令
2. 設(shè)置 ssh
sudo apt-get update
sudo apt-get install openssh-server -y
sudo systemctl status ssh
sudo vim /etc/ssh/sshd_config 不用修改
sudo service ssh restart
ssh username@your_server_ip_address -p port_number
systemctl restart sshd
// 開(kāi)啟防火墻ssh的服務(wù)端口
ufw allow ssh
// 查看ssh服務(wù)狀態(tài)
systemctl status ssh
// 關(guān)閉ssh服務(wù)
systemctl stop ssh
// 開(kāi)啟ssh服務(wù)
systemctl start ssh
// 重啟ssh服務(wù)
systemctl restart ssh
// 設(shè)置開(kāi)啟自啟
sudo systemctl enable ssh
// 關(guān)閉開(kāi)機(jī)自啟
sudo systemctl disable ssh
3. 桌面版設(shè)置固定ip地址
sudo apt install net-tools
ens33
cd /etc/netplan/
sudo vi /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
ethernets:
ens33:
dhcp4: no
addresses: [192.168.99.143/24]
optional: true
gateway4: 192.168.99.1
nameservers:
addresses: [114.114.114.114]
version: 2
renderer: NetworkManager
~
sudo netplan apply
4. server版本設(shè)置固定ip地址
cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: no
addresses: [192.168.99.57/24]
optional: true
gateway4: 192.168.99.1
nameservers:
addresses: [114.114.114.114]
version: 2
sudo netplan apply
5. 查看python版本
python3 -V
Python 3.8.10
sudo apt install python3-pip -y
6. 安裝 mysql 8.0
sudo apt-get update
sudo apt install mysql-server -y
systemctl status mysql
netstat -an |grep 3306
mysqladmin --version
mysqladmin Ver 8.0.33-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
sudo apt-get install mysql-client
sudo systemctl start mysql.service
sudo systemctl restart mysql.service
sudo systemctl stop mysql.service
sudo systemctl enable mysql.service
sudo netstat -anp | grep mysql
sudo ufw allow 3306
sudo netstat -anp | grep mysql
netstat -ntulp | grep 3306
6.1 配置文件
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/bak_mysqld.cnf
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
有的地方說(shuō)是 只注釋掉,好像是不行
sudo systemctl restart mysql
6.2 修改
sudo mysql
use mysql
select host,user from user;
update user set host=‘%’ where user=‘root’;
select host,user from user;
alter user ‘root’@‘%’ identified with mysql_native_password by ‘123456’;
exit
mysql -u root -p123456
exit
創(chuàng)建數(shù)據(jù)庫(kù)
django-vue-admin
utf8mb4
utf8mb4_general_ci
6.2 登錄
mysql -h ip(本機(jī)) -uroot –p
mysql -hlocalhost -uroot –p
mysql -h 192.168.99.57 -uroot –p
mysql -h 127.0.0.1 -uroot –p
mysql -h127.0.0.1 -uroot –p
mysql -uroot -p
mysql -u root –p
6.3 遠(yuǎn)程訪問(wèn)
Ubuntu22.04.2安裝&卸載MySQL8.0.33詳細(xì)步驟
https://blog.csdn.net/m0_56349886/article/details/130751157
7. 安裝 redis
sudo apt update
sudo apt install redis -y
https://redis.io/
https://redis.io/docs/getting-started/
sudo systemctl status redis
sudo systemctl restart redis
配置文件 應(yīng)該是不用修改
sudo cp /etc/redis/redis.conf /etc/redis/bak_redis.conf
sudo vi /etc/redis/redis.conf
redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379[1]>
8. 安裝 nodejs
cd ~
sudo apt install curl -y
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
## Run `sudo apt-get install -y nodejs` to install Node.js 14.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
sudo apt-get install -y nodejs
node --version
v14.21.3
npm --version
6.14.18
sudo apt install build-essential (可以不執(zhí)行)
正式工作
https://django-vue-admin.com/document/hjbs.html
sudo apt-get install libmysqlclient-dev -y
cd ~
mkdir work
cd work
下載正式 版
django-vue-admin-v2.1.4.tar.gz
tar xvf django-vue-admin-v2.1.4.tar.gz
cd django-vue-admin-v2.1.4/
cd backend/
cd conf/
cp env.example.py env.py
vi env.py
import os
from application.settings import BASE_DIR
# ================================================= #
# *************** mysql數(shù)據(jù)庫(kù) 配置 *************** #
# ================================================= #
# 數(shù)據(jù)庫(kù) ENGINE ,默認(rèn)演示使用 sqlite3 數(shù)據(jù)庫(kù),正式環(huán)境建議使用 mysql 數(shù)據(jù)庫(kù)
# sqlite3 設(shè)置
# DATABASE_ENGINE = "django.db.backends.sqlite3"
# DATABASE_NAME = os.path.join(BASE_DIR, "db.sqlite3")
# 使用mysql時(shí),改為此配置
DATABASE_ENGINE = "django.db.backends.mysql"
DATABASE_NAME = 'django-vue-admin' # mysql 時(shí)使用
# 數(shù)據(jù)庫(kù)地址 改為自己數(shù)據(jù)庫(kù)地址
DATABASE_HOST = "127.0.0.1"
# # 數(shù)據(jù)庫(kù)端口
DATABASE_PORT = 3306
# # 數(shù)據(jù)庫(kù)用戶(hù)名
DATABASE_USER = "root"
# # 數(shù)據(jù)庫(kù)密碼
DATABASE_PASSWORD = "123456"
# 表前綴
TABLE_PREFIX = "dvadmin_"
# ================================================= #
# ******** redis配置,無(wú)redis 可不進(jìn)行配置 ******** #
# ================================================= #
# REDIS_PASSWORD = ''
# REDIS_HOST = '127.0.0.1'
# REDIS_URL = f'redis://:{REDIS_PASSWORD or ""}@{REDIS_HOST}:6380'
# ================================================= #
# ****************** 功能 啟停 ******************* #
# ================================================= #
DEBUG = True
# 啟動(dòng)登錄詳細(xì)概略獲取(通過(guò)調(diào)用api獲取ip詳細(xì)地址。如果是內(nèi)網(wǎng),關(guān)閉即可)
ENABLE_LOGIN_ANALYSIS_LOG = True
# 登錄接口 /api/token/ 是否需要驗(yàn)證碼認(rèn)證,用于測(cè)試,正式環(huán)境建議取消
LOGIN_NO_CAPTCHA_AUTH = True
# 是否啟動(dòng)API日志記錄
API_LOG_ENABLE = locals().get("API_LOG_ENABLE", True)
# API 日志記錄的請(qǐng)求方式
API_LOG_METHODS = locals().get("API_LOG_METHODS", ["POST", "UPDATE", "DELETE", "PUT"])
# API_LOG_METHODS = 'ALL' # ['POST', 'DELETE']
# ================================================= #
# ****************** 其他 配置 ******************* #
# ================================================= #
ENVIRONMENT = "local" # 環(huán)境,test 測(cè)試環(huán)境;prod線上環(huán)境;local本地環(huán)境
ALLOWED_HOSTS = ["*"]
# 系統(tǒng)配置存放位置:redis/memory(默認(rèn))
DISPATCH_DB_TYPE = 'redis'
cd …
pwd
/home/jack/work/django-vue-admin-v2.1.4/backend
echo ‘export PATH=/home/jack/.local/bin:$PATH’ >> ~/.bashrc
source ~/.bashrc
echo $PATH
pip3 install -r requirements.txt
ERROR: launchpadlib 1.10.13 requires testresources, which is not installed.
WARNING: The script chardetect is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script normalizer is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script sqlformat is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script django-admin is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pypinyin is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script automat-visualize is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts cftp, ckeygen, conch, mailmail, pyhtmlizer, tkconch, trial, twist and twistd are installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts wamp, xbrnetwork and xbrnetwork-ui are installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script daphne is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script uvicorn is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script gunicorn is installed in '/home/jack/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
echo ‘export PATH=/home/jack/.local/bin:$PATH’ >> ~/.bashrc
source ~/.bashrc
echo $PATH
pip3 uninstall -r requirements.txt -y
pip3 install -r requirements.txt
python3 -m pip install launchpadlib
安裝依賴(lài)環(huán)境:
pip3 install -r requirements.txt
執(zhí)行遷移命令:
python3 manage.py makemigrations
python3 manage.py migrate
初始化數(shù)據(jù):
python3 manage.py init
初始化省市縣數(shù)據(jù):
python3 manage.py init_area
啟動(dòng)項(xiàng)目:
python3 manage.py runserver 0.0.0.0:8000
web
cd /home/jack/work/django-vue-admin-v2.1.4/web
前端運(yùn)行
進(jìn)入前端項(xiàng)目目錄 cd web
安裝依賴(lài) npm install --registry=https://registry.npm.taobao.org
啟動(dòng)服務(wù) npm run dev
#訪問(wèn)項(xiàng)目
訪問(wèn)地址:http://localhost:8080 (opens new window)(默認(rèn)為此地址,如有修改請(qǐng)按照配置文件)
賬號(hào):superadmin 密碼:admin123456
[vue-echarts] Switched to Vue 2 environment.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN cosmiconfig-typescript-loader@4.3.0 requires a peer of cosmiconfig@>=7 but none is installed. You must install peer dependencies yourself.
npm WARN acorn-jsx@5.3.2 requires a peer of acorn@^6.0.0 || ^7.0.0 || ^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN django-vue-admin@2.1.4 No license field.
added 2252 packages from 1183 contributors in 122.451s
146 packages are looking for funding
run `npm fund` for details
http://localhost:8080 火狐瀏覽器 可以
http://192.168.99.143:8080/ 谷歌瀏覽器 不可以
如果想讓他可以,需要部署一下
安裝 nginx服務(wù)器
保證以 sudo 用戶(hù)身份登錄,并且你不能運(yùn)行 Apache 或者 其他處理進(jìn)程在80端口和443端口。
sudo apt install nginx
sudo systemctl status nginx
查看安裝版本
nginx -v
查看狀態(tài)
sudo systemctl status nginx
啟動(dòng)
sudo systemctl start nginx
停止
sudo systemctl stop nginx
重啟
sudo systemctl restart nginx
sudo systemctl enable nginx
sudo systemctl start nginx
如何在Ubuntu20.04上配置Nginx以及使用Nginx部署一個(gè)網(wǎng)站
https://developer.aliyun.com/article/895750
①打包Vue項(xiàng)目——npm run build
②將靜態(tài)資源文件上傳至服務(wù)器
③配置Nginx文件開(kāi)啟一個(gè)網(wǎng)點(diǎn)
使用vim打開(kāi)該配置文件——vim /etc/nginx/nginx.conf
修改完成之后進(jìn)行保存退出。
④重啟Nginx服務(wù)——service nginx restart
普通部署流程
進(jìn)入如下目錄:
/home/jack/work/django-vue-admin-v2.1.4/web/
修改環(huán)境配置 .env.preview 文件中,VUE_APP_API 地址為后端服務(wù)器地址
VUE_APP_API=192.168.99.143
/home/jack/work/django-vue-admin-v2.1.4/web
構(gòu)建生產(chǎn)環(huán)境 npm run build,等待生成 dist 文件夾
生成的 dist 文件放到服務(wù)器 /opt/django-vue-admin/web/dist 目錄下
使用 nginx 進(jìn)行靜態(tài)文件代理
Nginx配置
sudo cp /etc/nginx/nginx.conf /etc/nginx/bak_nginx.conf
sudo vi /etc/nginx/nginx.conf
修改為如下內(nèi)容,并重啟sudo systemctl restart nginx
# 此nginx配置默認(rèn)項(xiàng)目放在服務(wù)器的 /opt 目錄下,前端默認(rèn)端口為 8080,后端為8000,如需修改請(qǐng)自行對(duì)照修改
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80 default_server;
server_name _;
return 404;
}
# 前端配置
server {
listen 8080;
client_max_body_size 100M;
server_name dvadmin-web;
charset utf-8;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
root /opt/django-vue-admin/web/dist;
index index.html index.php index.htm;
}
# 后端服務(wù)
location /api {
root html/www;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
rewrite ^/api/(.*)$ /$1 break; #重寫(xiě)
proxy_pass http://127.0.0.1:8000;
}
# Django media
location /media {
root /opt/django-vue-admin/backend; # your Django project's media files - amend as required
}
# Django static
location /static {
root /opt/django-vue-admin/backend; # your Django project's static files - amend as required
}
#禁止訪問(wèn)的文件或目錄
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
}
}
后端啟動(dòng)
進(jìn)入如下目錄:
/home/jack/work/django-vue-admin-v2.1.4/backend
使用daphne啟動(dòng):daphne -b 0.0.0.0 -p 8000 application.asgi:application
后臺(tái)運(yùn)行: nohup daphne -b 0.0.0.0 -p 8000 application.asgi:application > run.log 2>&1 &
不用sudo
訪問(wèn)項(xiàng)目
訪問(wèn)地址:http://公網(wǎng)或本服務(wù)器ip:8080 (服務(wù)器需注意供應(yīng)商端防火墻是否開(kāi)啟對(duì)應(yīng)端口)
賬號(hào):superadmin 密碼:admin123456
http://192.168.99.143:8080/
谷歌瀏覽器
運(yùn)行項(xiàng)目并查看接口
打開(kāi)swgger可以看到我們配置的接口已經(jīng)生效了文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-513401.html
http://192.168.99.143:8000/文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-513401.html
到了這里,關(guān)于django-vue-admin ubuntu 20.04 環(huán)境準(zhǔn)備 記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!