处理逻辑
1. 下载node.js解压并且添加环境变量
2. 修改vue文件路径 改为Nginx代理服务器地址(端口)
3. 安装node依赖 选用国内淘宝源
1 下载文件
wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip
2 解压缩
unzip 07-luffy_project_01.zip
3 配置 node.js
环境[二进制源码包]
1. 下载
wget https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz
2. 解压
xz -d node-v14.18.1-linux-x64.tar.xz
tar -xvf node-v14.18.1-linux-x64.tar
4 添加环境变量并且刷新
1. 修改如下
vim /etc/profile
PATH="/opt/tengine233/sbin:/opt/python396/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/node-v14.18.1-linux-x64/bin"
2. 刷新
source /etc/profile
node -v
v14.18.1
npm -v
6.14.15
5 修改配置文件 /s25luffy/src/restful/api.js
sed -i 's/127.0.0.1:8000/192.168.1.9:9000/g' api.js
6 安装 node
模块的依赖
# 进入指定目录
cd /tmp/s25luffy
ls
build config index.html node_modules package.json package-lock.json README.md src static
npm --registry https://registry.npm.taobao.org install
# 安装后提示
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1136 packages from 654 contributors in 27.306s
7 构建
npm run build
# 输出
Build complete.
Tip: built files are meant to be served over an HTTP server.
Opening index.html over file:// won't work.
8 修改 nginx.conf
增加虚拟主机返回路飞页面
server {
listen 9999;
server_name localhost;
charset utf-8;
location / {
root /tmp/s25luffy/dist;
index index.html;
}
}
部署现状[前端缺后端逻辑代码]
9 准备环境
在 /tmp
目录下,下载解压
wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip
解压
unzip luffy_boy.zip
创建虚拟环境
cd luffy_bloy
python3 -m venv s25_luffy
创建包依赖文件
依赖文件
certifi==2018.11.29
chardet==3.0.4
crypto==1.4.1
Django==2.1.4
django-redis==4.10.0
django-rest-framework==0.1.0
djangorestframework==3.9.0
idna==2.8
Naked==0.1.31
pycrypto==2.6.1
pytz==2018.7
PyYAML==3.13
redis==3.0.1
requests==2.21.0
shellescape==3.4.1
urllib3==1.24.1
uWSGI==2.0.17.1
创建依赖
cd /tmp/luffy_boy
vim requirements.txt
批量安装
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
测试启动
python3 manage.py runserver
修改Nginx配置,设置转发
server {
listen 9000;
server_name localhost;
charset utf-8;
location / {
uwsgi_pass 1:9005;
include uwsgi_params;
}
}
创建并修改 uwsgi.ini
# Django-related settings
# 填写CRM项目第一层绝对路径
chdir = /tmp/luffy_boy
# 填写 CRM 项目第二层相对路径,找到第二层目录下的wsgi.py
# 这里写的不是路径,而是以上一个参数为相对,找到第二层目录下的wsgi.py文件
module = luffy_boy.wsgi
# 虚拟环境Python解释器路径
home = /tmp/luffy_boy/s25_luffy
# process-related settings
# master
master = true
# 推荐性能为 核数 * 2 + 1
processes = 3
#threads = 2
# socket和Nginx结合部署 unix-socket参数,这里先临时暂停使用
# the socket (use the full path to be safe
socket = 0.0.0.0:9005
# 线上部署不会使用http参数,对于后端不安全,使用socket连结是安全的,用Nginx反向代理去访问
# 后端程序是运行在防火墙内部,外网无法直接访问
# 临时使用http参数,便于浏览器直接调试
# http = 0.0.0.0:10001
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
pidfile=uwsgi.pid
daemonize=uwsgi.log
配置 supervisord.conf
[program:Luffyvue]
command=/tmp/luffy_boy/s25_luffy/bin/uwsgi --ini /tmp/luffy_boy/luffy_boy/uwsgi.ini
autostart=true ; 在supervisord启动的时候也自动启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3 ; 启动失败自动重试次数,默认是3
stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
stdout_logfile=/tmp/luffyvue.out ; 需要用户新建该目录
关闭进程重新应用项目
supervisorctl -c /etc/supervisord.conf # 关闭uwsgi stop Blog
ps -ef | grep supervisord # 查看管理工具PID 关闭进程
kill -9 11464
##supervisor 常用命令
一、开启命令
supervisor的服务器端部分启动命令:
sudo unlink /var/run/supervisor.sock
supervisord -c /etc/supervisord.conf
此时默认开启了所有服务
supervisor的客户端部分命令:
supervisorctl status 查看进程运行状态
supervisorctl start 进程名 启动进程
supervisorctl stop 进程名 关闭进程
supervisorctl restart 进程名 重启进程
supervisorctl update 重新载入配置文件
supervisorctl shutdown 关闭supervisord
supervisorctl clear 进程名 清空进程日志
supervisorctl 进入到交互模式下。使用help查看所有命令。
start stop restart + all 表示启动,关闭,重启所有进程。
二、关闭命令
supervisorctl stop all先关闭supervisor服务
之后再关闭supervisord服务
遇到的报错
unix:///tmp/supervisor.sock no such file
解决方案
/usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf #启动路径
(luffyboy_env) [root@vvkt7whznuckhiz2-0723575 luffy_boy]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
Redis的安装
1 下载解压
cd opt
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar -xvf redis-6.2.6.tar.gz
2 安装包依赖
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
yum search systemd-devel
yum -y install systemd-devel.x86_64
编译安装
make USE_SYSTEMD=yes
cd src && make all
测试启动
cd redis-6.2.6/src
./redis-server
make PREFIX=/opt/redis install
cd src && make install
检查文件
ls /opt/redis/
ls /opt/redis/bin/
复制服务配置文件并做如下修改
cd /opt/redis-6.2.6/utils
cp systemd-redis_server.service /etc/systemd/system/redis_6379.service
vim /etc/systemd/system/redis_6379.service
配置文件如下
[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
#Before=your_application.service another_example_application.service
#AssertPathExists=/var/lib/redis
Wants=network-online.target
After=network-online.target
[Service]
#ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
## Alternatively, have redis-server load a configuration file:
ExecStart=/opt/redis/bin/redis-server /etc/redis/redis_6379.conf
ExecStop=/opt/redis/bin/redis-cli -p 6379 shutdown
LimitNOFILE=10032
NoNewPrivileges=yes
#OOMScoreAdjust=-900
#PrivateTmp=yes
Type=notify
TimeoutStartSec=90
TimeoutStopSec=90
UMask=0077
#User=redis
#Group=redis
WorkingDirectory=/var/lib/redis_6379
[Install]
WantedBy=multi-user.target
创建文件夹
cd /var/lib
mkdir redis_6379
cd /etc
mkdir redis
拷贝配置文件
cd /opt/redis-6.2.6
cp redis.conf /etc/redis/redis_6379.conf
编辑配置文件
vim redis_6379.conf
配置文件如下
################################## MODULES #####################################
# Load modules at startup. If the server is not able to load modules
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize no
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# requires "expect stop" in your upstart job config
# supervised auto
supervised systemd
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# on startup, and updating Redis status on a regular
# basis.
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous pings back to your supervisor.
===============================================================================
# Note that on modern Linux systems "/run/redis.pid" is more conforming
# and should be used instead.
pidfile /var/run/redis_6379.pid
logfile "/var/log/redis_6379.log"
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
测试启动
systemctl start redis_6379
systemctl status redis_6379
设置环境变量
vim /etc/profile
PATH="/opt/tengine233/sbin:/opt/python396/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/node-v14.18.1-linux-x64/bin:/opt/redis/bin"
source /etc/profile