# react-admin-template **Repository Path**: faychou/react-admin-template ## Basic Information - **Project Name**: react-admin-template - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-04-18 - **Last Updated**: 2022-04-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 项目运行 ### 1、book-admin ```bash npm start ``` ### 2、book-server ```bash npm start ``` # 部署 ### 1、部署方式 - 阿里云 - 腾讯云 - 华为云 - 。。。 #### 1.1 连接阿里云 **方式 1:** 阿里云云-实例-远程连接-Workbench 远程连接 **方式 2:** 阿里云云-实例-远程连接-VNC 远程连接 **方式 3:** 本地电脑-终端-(确保有 sshkey)-输入以下命令连接: ```bash ssh 用户名@服务器IP # 回车键后输入密码(输入密码的过程看不到) ``` #### 1.2 yum 是 centos 的软件包管理器。 #### 1.3 设置 yum 镜像源为国内镜像 第一步、备份原镜像 ```bash mv /etc/yum.repos.d/centOS-Base.repo /etc/yum.repos.d/centOS-Base.repo.backup ``` 第二步、下载国内镜像(阿里云镜像) ```bash # 手动下载后再通过 ftp工具上传到服务器 # 或者通过 wget 下载 wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo # 可能是另一个名字 wget -O /etc/yum.repos.d/CentOS-Linux-BaseOS.repo https://mirrors.aliyun.com/repo/Centos-8.repo ``` 第三步、yum源更新 ```bash yum clear all # 清除之前的缓存 yum makecache # 建立新缓存 ``` #### 1.4 NodeJS 第一步、下载源码 ```bash cd /usr/local/src wget https://nodejs.org/dist/v16.13.2/node-v16.13.2.tar.gz ``` 第二步、解压 ```bash tar zxvf node-v16.13.2.tar.gz ``` 第三步、编译 ```bash cd node-v16.13.2 # 安装依赖的编译软件包 sudo yum install gcc gcc-c++ ./configure make sudo make install ``` 第四步、验证是否安装成功 ```bash node -v ``` ##### 1.4.1 进程守护 node 的守护进程,一直监听程序的运行,当出现bug导致程序停止时,能重新启动程序,并且输出日志到指定的目录中。 * nodemon * forever * pm2 ```bash # 安装 npm install -g pm2 # 启动项目 pm2 start app.js # 查看所有的进程 pm2 list # 停止所有的 pm2 stop all # 停止指定的 pm2 stop [pid] ``` 因为 nodejs 使用 express 框架,是通过 `npm start` 启动的,所以通过 pm2 的配置来处理: ```json // processes.json { "apps": [ { "name": "api-fay", // 名称 "cwd": "./", // 根目录 "script": "./bin/www", // 启动文件 "log_date_format": "YYYY-MM-DD HH:mm Z", // 日期格式 "error_file": "./logs/node-app.stderr.log", // 错误输出日志 "out_file": "./logs/node-app.stdout.log", // 日志 "pid_file": "pids/node-geo-api.pid", "instances": 6, "min_uptime": "200s", "max_restarts": 10, "max_memory_restart": "1M", "cron_restart": "1 0 * * *", //"watch": false, "watch":[ // 需要监控的目录 "bin", "util", "configs", "public", "routes", "views" ], "merge_logs": true, "exec_interpreter": "node", "exec_mode": "fork", "autorestart": false, "vizion": false } ] } ``` 然后修改 `package.json`: ```json "scripts": { "pm2": "pm2 start processes.json" } ``` 运行: ```bash npm run pm2 ``` #### 1.5 Nginx 是一个轻量级、高性能的web服务器、反向代理服务器、IMAP/POP3/SMTP服务器。 特点-反向代理、负载均衡。 **CentOS8安装** CentOS8 中默认包含 nginx 软件包,只需要通过 yum 安装即可。 ```bash # 安装 yum install nginx # 验证 systemctl status nginx # 启动并且运行服务 sudo systemctl enable nginx sudo systemctl start nginx # 测试 nginx -t # 重启 systemctl restart nginx ``` **centos7安装** 需要从源码开始安装: ```bash # 安装依赖 yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel pcre pcre-devel # 安装 cd 某个目录 wget https://nginx.org/download/nginx-1.21.5.tar.gz # 解压 tar -zxvf nginx-1.21.5.tar.gz # 编译 cd nginx-1.21.5 ./configure make make install ``` **配置文件说明** yum 安装之后,配置文件在 `/etc/nginx/nginx.conf` ```nginx ### 每个指令必须有分号结束。### # 表明 Nginx 服务是由哪个用户哪个群组来负责维护进程的,默认是 nobody # user nobody; # 工作的子进程数量(通常等于CPU数量或者2倍于CPU),默认1 worker_processes 2; # 全局错误日志、存放路径、级别 # 级别:debug/info/notice/warn/error/crit;从左到右记录的信息从最详细到最少 # error_log logs/error.log; error_log logs/error.log info; # 指定 nginx 进程运行文件存放地址,默认配置文件是注释了 # 如果上面 worker_processes 的数量大于 1 那 Nginx 就会启动多个进程 # 而发信号的时候需要知道要向哪个进程发信息,不同进程有不同的 pid,所以需要记录当前启动的 nginx 的进程 id pid logs/nginx.pid; # 简化调试 此指令不得用于生产环境 # master_process off; # 简化调试 此指令可以用到生产环境 # daemon off; # 最大文件描述符 worker_rlimit_nofile 51200; # 配置影响 nginx 服务器或与用户的网络连接 events { # 设置网路连接序列化,防止惊群现象发生,默认为 on # accept_mutex on; # 设置一个进程是否同时接受多个网络连接,默认为 off # multi_accept on; # 事件驱动模型,使用网络 IO 模型 linux 建议 epoll,FreeBSD 建议采用 kqueue,window 下不指定 # epoll 是多路复用 IO(I/O Multiplexing) 中的一种方式 # use epoll; # 每一个 worker 进程能并发处理的最大连接数 worker_connections 2048; # 并发总数是 worker_processes 和 worker_connections 的乘积 # 即 max_clients = worker_processes * worker_connections # 在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4 为什么 # 为什么上面反向代理要除以4,应该说是一个经验值 # 根据以上条件,正常情况下的Nginx Server可以应付的最大连接数为:4 * 8000 = 32000 # worker_connections 值的设置跟物理内存大小有关 # 因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数 # 而系统可以打开的最大文件数和内存大小成正比,一般1GB内存的机器上可以打开的文件数大约是10万左右 # 我们来看看360M内存的VPS可以打开的文件句柄数是多少: # $ cat /proc/sys/fs/file-max # 输出 34336 # 32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内 # 所以,worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置 # 使得并发总数小于操作系统可以打开的最大文件数目 # 其实质也就是根据主机的物理CPU和内存进行配置 # 当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。 # ulimit -SHn 65535 } # 设定 http 服务器 http { # 关闭错误页面的 nginx 版本数字,提高安全性 server_tokens off; # 设定 mime 类型,类型由 mime.type 文件定义 include mime.types; # 加载以下文件到当前的配置里,如将 server 部分分离出去,配置反向代理 # include proxy.conf; # include gzip.conf; # 文件类型,默认为 text/plain default_type application/octet-stream; # 关闭 access_log 可以让读取磁盘 IO 操作更快 # 当然如果你在学习的过程中可以打开方便查看 Nginx 的访问日志 # access_log logs/access.log main; # 定义日志记录格式,如果 access_log 设置为 off 可以注释掉这段 log_format main '[$remote_addr] - [$remote_user] [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; rewrite_log on; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; # 设定请求缓冲 client_header_buffer_size 128k; large_client_header_buffers 4 128k; # 允许客户端请求的最大单文件字节数 client_max_body_size 10m; # 缓冲区代理缓冲用户端请求的最大字节数, client_body_buffer_size 128k; client_body_in_single_buffer on; # 允许 sendfile 方式传输文件,对于普通应用,必须设为 on,如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off sendfile on; # 每个进程每次调用传输数量不能大于设定的值,默认为 0,即不设上限 # sendfile_max_chunk 100k; # 在一个数据包里发送所有头文件,而不是一个接一个的发送 # tcp_nopush on; # 不要缓存 # tcp_nodelay on; # 连接超时时间,默认为 75s keepalive_timeout 120; # 开启 gzip 压缩 # gzip on; # gzip_disable "MSIE [1-6]."; # 负载均衡配置,可以配置多个 upstream crossover_main { # ip_hash; # 设置负载均衡策略为 ip_hash,会根据请求来源 ip 做 hash,同一个 C 类地址网段 hash 值相同 server 127.0.0.1:8080; # 反向代理到后台应用服务器节点上 } # 配置虚拟主机的相关参数,一个 http 中可以有多个 server server { # 单连接请求上限次数 # keepalive_requests 120; # 监听端口 listen 80; # 服务器地址,默认为 localhost # server_name www.faychou.com faychou.com; server_name localhost; # 代码放置的根目录 root /usr/www/; # 编码 charset utf-8; #koi8-r; # 设定本虚拟主机的访问日志 # access_log logs/host.access.log main; # 如果访问时没有加 www,则跳转至 www.faychou.com if ($host !~* www.faychou.com) { rewrite ^(.*)$ http://www.faychou.com/$1 permanent; } # 配置默认请求的路由,以及各种页面的处理情况 location / { # 自动索引 autoindex on; # 显示文件大概大小 # autoindex_exact_size off; # 显示的文件时间为文件的服务器时间,off 则为 GMT 时间 # autoindex_localtime on; # 10m之后下载速度为 10k # limit_rate_after 10m; # limit_rate 10k; # 该'/'请求映射到本地文件系统 /data/www 目录 #root /data/www; # 默认页及先后顺序 index index.html index.htm; } location /proxy { # 配置所有请求都会分发到这个负载均衡器上 proxy_pass http://upstream_test; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $remote_addr; } # 静态文件 location ~* ^/static/.*\.(jpg|jpeg|gif|png|html|htm|js|css|swf)$ { root /data/static/; access_log off; # 过期30天,静态文件不怎么更新,过期可以设大一点, # 如果频繁更新,则可以设置得小一点。 expires 30d; } # 404 页面跳转到 404.html,相对于上面的 root 目录 # error_page 404 /404.html; # 403 页面跳转到 403.html,相对于上面的 root 目录 # error_page 403 /403.html; # 50x 页面跳转到 50x.html # error_page 500 502 503 504 /50x.html; # redirect server error pages to the static page /50x.html location = /50x.html { root html; } # 设定查看 nginx 状态地址 location /nginx_status { stub_status on; access_log on; allow 127.0.0.1; #设置为可访问该状态信息的ip deny all; } # PHP 脚本请求全部转发到 FastCGI 处理. 使用 FastCGI 默认配置. location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #禁止访问 .htxxx 文件 location ~ /.ht { deny all; } } # HTTPS server # server { # listen 443; # server_name localhost; # 为一个server{......}开启ssl支持 # ssl on; # 指定PEM格式的证书文件 # ssl_certificate cert.pem; # 指定PEM格式的私钥文件 # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } # } } ``` **https配置** 第一步、在域名服务商处申请SSL证书(有免费的); 第二步、下载证书并上传到云服务器; 第三步、云服务器设置安全组策略--新增443端口; 第四步、修改 nginx 配置: ```nginx server { listen 80; server_name api.skywyb.top; rewrite ^(.*)$ https://$host$1 permanent; # 重写到 https 下 # location / { # # index index.html index.htm; # # try_files $uri $uri/ /index.html; # proxy_pass http://localhost:3030; # } } server { listen 443 ssl; server_name api.skywyb.top; # 自己证书绑定的域名 ssl_certificate "/etc/nginx/ssl/api.skywyb.top.pem"; # ssl 证书在服务器绝对地址 ssl_certificate_key "/etc/nginx/ssl/api.skywyb.top.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers PROFILE=SYSTEM; ssl_prefer_server_ciphers on; include /etc/nginx/default.d/*.conf; location / { proxy_pass http://localhost:3030; # index index.html index.htm; } } ``` 第五步、重新启动 nginx ```bash systemctl restart nginx ``` #### 1.8 mysql 第一步、下载源 ```bash wget https://repo.mysql.com//mysql80-community-release-el8-2.noarch.rpm ``` 第二步、安装数据源 ```bash yum install mysql80-community-release-el8-2.noarch.rpm ``` 第三步、检查数据源 ```bash yum repolist enabled | grep "mysql.*-community.*" ``` 第四步、禁止CentOS8自带的mysql模块 ```bash' yum module disable mysql ``` 第五步、安装数据库 ```bash yum install mysql-community-server ``` 第六步、启动mysql ```bash service mysqld start # 检查状态 service mysqld status ``` 第七步、显示密码 ```bash grep 'temporary password' /var/log/mysqld.log # root@localhost: /foUws57%0O& ``` 第八步、修改密码: ```bash # 登录,使用上一步查看的密码 mysql -u root -p # 修改密码 - 默认大小写字母、数字、特殊符号组成 alter user 'root'@'localhost' identified by 'Abc%123456'; #查看密码策略 SHOW VARIABLES LIKE 'validate_password%'; # 验证强度等级 set global validate_password_policy=LOW; # 设置密码长度 set global validate_password_length=6; # 接下来可以设置简单的密码 ``` 第九步、开放某个账号远程登陆 ```bash # 创建一个账号用于远程登陆 create user 'admin'@'%' identified by 'Admin123%'; # 授权 grant all privileges on *.* to 'admin'@'%' with grant option; ``` 第十步、针对 sqlyog 的问题 由于 mysql8 的加密方式变了,sqlyog 不支持这种加密,就会报 2058 错误: ```bash ALTER USER'root'@'localhost' IDENTIFIED BY 'Abc123456%' PASSWORD EXPIRE NEVER; # 重新修改远程账号登陆密码 ALTER USER'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'Admin123456%'; # 刷新权限 flush privileges; ``` 然后就可以连接成功。