处理逻辑

  1. 1. 下载node.js解压并且添加环境变量
  2. 2. 修改vue文件路径 改为Nginx代理服务器地址(端口)
  3. 3. 安装node依赖 选用国内淘宝源

1 下载文件

  1. wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip

2 解压缩

  1. unzip 07-luffy_project_01.zip

3 配置 node.js 环境[二进制源码包]

  1. 1. 下载
  2. wget https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz
  3. 2. 解压
  4. xz -d node-v14.18.1-linux-x64.tar.xz
  5. tar -xvf node-v14.18.1-linux-x64.tar

4 添加环境变量并且刷新

  1. 1. 修改如下
  2. vim /etc/profile
  3. 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"
  4. 2. 刷新
  5. source /etc/profile
  6. node -v
  7. v14.18.1
  8. npm -v
  9. 6.14.15

5 修改配置文件 /s25luffy/src/restful/api.js

  1. sed -i 's/127.0.0.1:8000/192.168.1.9:9000/g' api.js

6 安装 node 模块的依赖

  1. # 进入指定目录
  2. cd /tmp/s25luffy
  3. ls
  4. build config index.html node_modules package.json package-lock.json README.md src static
  5. npm --registry https://registry.npm.taobao.org install
  6. # 安装后提示
  7. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
  8. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  9. added 1136 packages from 654 contributors in 27.306s

7 构建

  1. npm run build
  2. # 输出
  3. Build complete.
  4. Tip: built files are meant to be served over an HTTP server.
  5. Opening index.html over file:// won't work.

8 修改 nginx.conf 增加虚拟主机返回路飞页面

  1. server {
  2. listen 9999;
  3. server_name localhost;
  4. charset utf-8;
  5. location / {
  6. root /tmp/s25luffy/dist;
  7. index index.html;
  8. }
  9. }

部署现状[前端缺后端逻辑代码]

delopyment of luffy city - 图1

9 准备环境

/tmp 目录下,下载解压

wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip

解压

unzip luffy_boy.zip

创建虚拟环境

cd luffy_bloy

python3 -m venv s25_luffy

创建包依赖文件

依赖文件

  1. certifi==2018.11.29
  2. chardet==3.0.4
  3. crypto==1.4.1
  4. Django==2.1.4
  5. django-redis==4.10.0
  6. django-rest-framework==0.1.0
  7. djangorestframework==3.9.0
  8. idna==2.8
  9. Naked==0.1.31
  10. pycrypto==2.6.1
  11. pytz==2018.7
  12. PyYAML==3.13
  13. redis==3.0.1
  14. requests==2.21.0
  15. shellescape==3.4.1
  16. urllib3==1.24.1
  17. 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

测试启动

  1. python3 manage.py runserver

修改Nginx配置,设置转发

  1. server {
  2. listen 9000;
  3. server_name localhost;
  4. charset utf-8;
  5. location / {
  6. uwsgi_pass 1:9005;
  7. include uwsgi_params;
  8. }
  9. }

创建并修改 uwsgi.ini

  1. # Django-related settings
  2. # 填写CRM项目第一层绝对路径
  3. chdir = /tmp/luffy_boy
  4. # 填写 CRM 项目第二层相对路径,找到第二层目录下的wsgi.py
  5. # 这里写的不是路径,而是以上一个参数为相对,找到第二层目录下的wsgi.py文件
  6. module = luffy_boy.wsgi
  7. # 虚拟环境Python解释器路径
  8. home = /tmp/luffy_boy/s25_luffy
  9. # process-related settings
  10. # master
  11. master = true
  12. # 推荐性能为 核数 * 2 + 1
  13. processes = 3
  14. #threads = 2
  15. # socket和Nginx结合部署 unix-socket参数,这里先临时暂停使用
  16. # the socket (use the full path to be safe
  17. socket = 0.0.0.0:9005
  18. # 线上部署不会使用http参数,对于后端不安全,使用socket连结是安全的,用Nginx反向代理去访问
  19. # 后端程序是运行在防火墙内部,外网无法直接访问
  20. # 临时使用http参数,便于浏览器直接调试
  21. # http = 0.0.0.0:10001
  22. # ... with appropriate permissions - may be needed
  23. # chmod-socket = 664
  24. # clear environment on exit
  25. vacuum = true
  26. pidfile=uwsgi.pid
  27. daemonize=uwsgi.log

配置 supervisord.conf

  1. [program:Luffyvue]
  2. command=/tmp/luffy_boy/s25_luffy/bin/uwsgi --ini /tmp/luffy_boy/luffy_boy/uwsgi.ini
  3. autostart=true ; supervisord启动的时候也自动启动
  4. startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1
  5. autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
  6. startretries=3 ; 启动失败自动重试次数,默认是3
  7. stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
  8. killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
  9. stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
  10. stdout_logfile=/tmp/luffyvue.out ; 需要用户新建该目录

关闭进程重新应用项目

  1. supervisorctl -c /etc/supervisord.conf # 关闭uwsgi stop Blog
  2. ps -ef | grep supervisord # 查看管理工具PID 关闭进程
  3. kill -9 11464

##supervisor 常用命令

  1. 一、开启命令
  2. supervisor的服务器端部分启动命令:
  3. sudo unlink /var/run/supervisor.sock
  4. supervisord -c /etc/supervisord.conf
  5. 此时默认开启了所有服务
  6. supervisor的客户端部分命令:
  7. supervisorctl status 查看进程运行状态
  8. supervisorctl start 进程名 启动进程
  9. supervisorctl stop 进程名 关闭进程
  10. supervisorctl restart 进程名 重启进程
  11. supervisorctl update 重新载入配置文件
  12. supervisorctl shutdown 关闭supervisord
  13. supervisorctl clear 进程名 清空进程日志
  14. supervisorctl 进入到交互模式下。使用help查看所有命令。
  15. start stop restart + all 表示启动,关闭,重启所有进程。
  16. 二、关闭命令
  17. supervisorctl stop all先关闭supervisor服务
  18. 之后再关闭supervisord服务

遇到的报错

unix:///tmp/supervisor.sock no such file

解决方案

  1. /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf #启动路径
  2. (luffyboy_env) [root@vvkt7whznuckhiz2-0723575 luffy_boy]# systemctl enable supervisord
  3. 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 安装包依赖

  1. yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make
  2. yum -y install centos-release-scl
  3. yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
  4. scl enable devtoolset-9 bash
  5. yum search systemd-devel
  6. 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

检查文件

  1. ls /opt/redis/
  2. ls /opt/redis/bin/

复制服务配置文件并做如下修改

  1. cd /opt/redis-6.2.6/utils
  2. cp systemd-redis_server.service /etc/systemd/system/redis_6379.service
  3. vim /etc/systemd/system/redis_6379.service

配置文件如下

  1. [Unit]
  2. Description=Redis data structure server
  3. Documentation=https://redis.io/documentation
  4. #Before=your_application.service another_example_application.service
  5. #AssertPathExists=/var/lib/redis
  6. Wants=network-online.target
  7. After=network-online.target
  8. [Service]
  9. #ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
  10. ## Alternatively, have redis-server load a configuration file:
  11. ExecStart=/opt/redis/bin/redis-server /etc/redis/redis_6379.conf
  12. ExecStop=/opt/redis/bin/redis-cli -p 6379 shutdown
  13. LimitNOFILE=10032
  14. NoNewPrivileges=yes
  15. #OOMScoreAdjust=-900
  16. #PrivateTmp=yes
  17. Type=notify
  18. TimeoutStartSec=90
  19. TimeoutStopSec=90
  20. UMask=0077
  21. #User=redis
  22. #Group=redis
  23. WorkingDirectory=/var/lib/redis_6379
  24. [Install]
  25. WantedBy=multi-user.target

创建文件夹

  1. cd /var/lib
  2. mkdir redis_6379
  1. cd /etc
  2. mkdir redis

拷贝配置文件

  1. cd /opt/redis-6.2.6
  2. cp redis.conf /etc/redis/redis_6379.conf

编辑配置文件

  1. vim redis_6379.conf

配置文件如下

  1. ################################## MODULES #####################################
  2. # Load modules at startup. If the server is not able to load modules
  3. # By default Redis does not run as a daemon. Use 'yes' if you need it.
  4. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  5. # When Redis is supervised by upstart or systemd, this parameter has no impact.
  6. daemonize no
  7. # If you run Redis from upstart or systemd, Redis can interact with your
  8. # supervision tree. Options:
  9. # supervised no - no supervision interaction
  10. # supervised upstart - signal upstart by putting Redis into SIGSTOP mode
  11. # requires "expect stop" in your upstart job config
  12. # supervised auto
  13. supervised systemd
  14. # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
  15. # on startup, and updating Redis status on a regular
  16. # basis.
  17. # supervised auto - detect upstart or systemd method based on
  18. # UPSTART_JOB or NOTIFY_SOCKET environment variables
  19. # Note: these supervision methods only signal "process is ready."
  20. # They do not enable continuous pings back to your supervisor.
  21. ===============================================================================
  22. # Note that on modern Linux systems "/run/redis.pid" is more conforming
  23. # and should be used instead.
  24. pidfile /var/run/redis_6379.pid
  25. logfile "/var/log/redis_6379.log"
  26. # Specify the server verbosity level.
  27. # This can be one of:
  28. # debug (a lot of information, useful for development/testing)
  29. # verbose (many rarely useful info, but not a mess like the debug level)
  30. # notice (moderately verbose, what you want in production probably)
  31. # warning (only very important / critical messages are logged)
  32. loglevel notice

测试启动

  1. systemctl start redis_6379
  2. systemctl status redis_6379

设置环境变量

  1. vim /etc/profile
  2. 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"
  3. source /etc/profile