安装mongo
# 启动mongo
cd /root/software/mongodb/bin
./mongod --dbpath ~/data/
# 后台启动mongo
vi /root/software/mongodb/conf/mongodb.cnf
dbpath=/root/data/
logpath=/var/log/mongo.log
logappend=true
fork=true
port=27017
mongod -f /root/software/mongodb/conf/mongodb.cnf &
安装nginx
yum方式安装
# 采用 yum 安装 nginx
yum install -y epel-release
yum -y update
yum install -y nginx
# 禁止自动更新
vi /etc/yum.conf
exclude=nginx
# 配置nginx,前后端分离
vi /etc/nginx/nginx.conf
# 调整启动用户
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
include /etc/nginx/default.d/*.conf;
# 配置静态映射目录
root /root/software/frontend/dist;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 解决前端 text/plain 异常问题
location ~\.js {
add_header Content-Type application/x-javascript;
}
location ~\.css {
add_header Content-Type text/css;
}
location / {
# 解决重定向 404 问题
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
# 配置接口映射
location /admin/ {
# 重写url , /admin/xx... => /xx...
# rewrite /admin/(.+)$ /$1 break;
proxy_pass http://127.0.0.1:3001;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
}
# 启动,查看,重启 nginx
systemctl start nginx
systemctl status nginx
systemctl stop nginx
离线方式安装
# 下载离线安装包
wget https://nginx.org/download/nginx-1.16.1.tar.gz
mkdir -p compile
tar -zxvf nginx-1.16.1.tar.gz -C compile/
cd compile/nginx-1.16.1
# 编译安装nginx
./configure --prefix=/usr/local/nginx-1.16.1
make && make install
编辑配置文件: vi /usr/local/nginx/conf/nginx.conf
# 调整启动用户
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /usr/local/nginx/conf/mime.types;
server {
listen 8888;
listen [::]:8888;
server_name _;
# 配置静态映射目录
root /root/software/AIOT-admin-frontend;
location ~\.js {
add_header Content-Type application/x-javascript;
}
location ~\.css {
add_header Content-Type text/css;
}
location / {
index index.html index.htm;
}
# 配置接口映射
location /admin/ {
# 重写url , /admin/xx... => /xx...
# rewrite /admin/(.+)$ /$1 break;
proxy_pass http://127.0.0.1:8080;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
}
安装redis
# 安装 redis
docker pull redis
docker run -p 6379:6379 --name redis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/docker/redis_6379 -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker exec -it redis /bin/bash
启动前后端
# 设置 yarn 仓库源
yarn config set registry https://registry.npm.taobao.org
yarn config set sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
yarn config set phantomjs_cdnurl "http://cnpmjs.org/downloads"
yarn config set electron_mirror "https://npm.taobao.org/mirrors/electron/"
yarn config set sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
yarn config set profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
yarn config set chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
# 查看当前 yarn 仓库源
yarn config get registry
# 安装依赖包
yarn install
# 打包
npm run build
# 将打包好的代码复制到静态文件映射目录
mkdir -p /root/software/frontend/dist
cp dist/* /root/software/frontend/dist/*
开启端口
# 查看防火墙状态
systemctl status firewalld.service
# 开启防火墙
systemctl start firewalld.service
# 设置端口
firewall-cmd --permanent --zone=public --add-port=8080/tcp
# 重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
# 查看是否生效
firewall-cmd --zone=public --query-port=8080/tcp
# 关闭防火墙
systemctl stop firewalld.service