固定静态IP
找工厂网管获取“ip“和”网关”,ip必需和调度在同一个网关上
进入看板系统,用用户名和密码登录,一般是ubuntu和abc123!
禁用 cloud-init 网络配置(避免重启后重置)
shellsudo touch /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg编辑 Netplan 配置文件
shellsudo nano /etc/netplan/50-cloud-init.yaml修成如下配置(格式选一种就行):
Linux中编辑文件可以使用“vim”或“nano”
关于用"vim"命令编辑文件的说明:
- 打开以后先按"i",开启编辑模式,然后用方向键将光标移动到需要编辑的地方
- 编辑完成后,按"esc",退出编辑模式,然后再按“:wq”,再按回车,完成文件的编辑
关于用"nano"命令编辑文件的说明:
- 打开可以直接编辑,编辑完成后,关闭需要按“ctrl+X”,再按“Y”,进行保存。
- 如果不想关闭,按“ctrl+O”进行保存,再按“ctrl+X”关闭
- 如果想搜索,则按“ctrl+W”,输入搜索内容按回车
shellnetwork: ethernets: eno1: dhcp4: no dhcp6: no addresses: - 10.0.0.176/24 # 这个改成“内网ip”,“/24”代表子网掩码为255.255.255.0 gateway4: 10.0.0.1 # 这个改成“网关地址” nameservers: addresses: - 100.0.0.254 # 不用改 - 8.8.8.8 # 不用改 enp3s0: dhcp4: no dhcp6: no version: 2或
shellnetwork: ethernets: eno1: dhcp4: no dhcp6: no addresses: - 10.0.0.176/24 # 这个改成“内网ip”,“/24”代表子网掩码为255.255.255.0 routes: - to: default via: 10.0.0.1 # 这个改成“网关地址” nameservers: addresses: - 100.0.0.254 # 不用改 - 8.8.8.8 # 不用改 enp3s0: dhcp4: no dhcp6: no version: 2应用配置并验证
shellsudo chmod 600 /etc/netplan/50-cloud-init.yaml # 消除警告 sudo netplan apply # 应用网络配置 ip addr show eno1 # 检查IP是否固定为设定的地址 ping xx.xx.xx.1 # 测试网关连通性重启验证
shellsudo reboot now # 重启系统 ip addr show eno1 # 重启后登录,再次执行以下命令检查IP是否固定成功
环境配置
安装软件
shell
# 安装mysql
sudo apt install mysql-server -y
# 安装redis
sudo apt install redis-server -y
# 安装nginx
sudo apt install nginx -y
# 安装jdk8
sudo apt install openjdk-8-jdk -y
java -version
# 配置自启
sudo systemctl start mysql
sudo systemctl enable mysql
sudo systemctl status mysql
sudo systemctl start redis-server
sudo systemctl enable redis-server
sudo systemctl status redis-server
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
# 创建必要文件夹
sudo mkdir -p /var/www
sudo mkdir -p /var/www/logs
sudo chown -R ubuntu:ubuntu /var/www/logs配置MySQL
shell
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf修改、添加如下命令:
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
character_set_server=utf8shell
sudo mysqlshell
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'm5Jwk.JR*Uxpbt^9f8jp';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'm5Jwk.JR*Uxpbt^9f8jp';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
exit;shell
systemctl restart mysql配置Redis
shell
sudo nano /etc/redis/redis.conf远程访问:
bind 127.0.0.1 ::1改为bind 0.0.0.0 ::1添加密码:
requirepass UmZHKT39sM
shell
systemctl restart mysql上传前后端文件
准备好前端文件dist/,后端文件data-agv-yanfeng-1.0.jar
windows上打开powershell或Git bash
shell
scp -r ./dist ubuntu@10.0.0.137:/tmpshell
scp -r ./data-agv-yanfeng-1.0.jar ubuntu@10.0.0.137:/tmp来到工控机上
shell
sudo mv /tmp/dist /var/www/distshell
sudo mv /tmp/data-agv-yanfeng-1.0.jar /var/www/data-agv-yanfeng-1.0.jar系统数据初始化
数据库初始化
将表结构导出
将数据表部署到服务器上,运行以下sql脚本和alter语句,重置自增id
sql
SELECT CONCAT('TRUNCATE TABLE `', table_name, '`;') AS reset_sql
FROM information_schema.tables
WHERE table_schema = DATABASE() AND AUTO_INCREMENT IS NOT NULL;sql
TRUNCATE TABLE ...;
....运行如下这段语句插入初始数据
之后用Navicat打开数据库修改一下,结合实际情况修改
工厂编号、工厂名称、工厂近经纬度、调度系统ip等信息
sql
START TRANSACTION;
# 工厂和产线的配置
INSERT INTO `factory` (factory_name, factory_code, coordinate, urls, server_url)
VALUES ('上海临港工厂', '2640(不确定后面问一下)', '121.828236,30.880834', 'http://不知道后面问一下:7566', '');
# 注意:map_id需要询问调度系统的人获取
INSERT INTO `product_line` (factory_code, factory_name, line_code, line_name, work_time, work_output, map_id, `offset`, threshold, websocket_map_url)
VALUES ('2640(不确定后面问一下)', '上海临港工厂', '26400020(不确定后面问一下)', '生产线', 15, 300, 1, 0, 600, 'ws://不知道后面问一下:7567');
INSERT INTO `product_line_ext` (`code`, factory_code, line_code)
VALUES ('26400020(不确定后面问一下)', '2640(不确定后面问一下)', '26400020(不确定后面问一下)');
# 用户和角色的配置
INSERT INTO `user` (username, nickname, user_type, `password`, initial, password_update_time, last_login_time, memo, operator_id)
VALUES ('admin', '管理员账号', 1, '$2a$10$VpX7F/03wRcsdylcAZ.O4.QRJS8D9oJGovYpM3EgrLwxhJfQruYVy', 0, 0, 0, '此账号是管理员', 0);
INSERT INTO `role` (name, description, level, factory_code, operator_id) VALUES ('超级管理员', '所有权限', 'p0', '', 1);
INSERT INTO `role` (name, description, level, factory_code, operator_id) VALUES ('总部', '查看所有工厂数据', 'p1', '', 1);
INSERT INTO `role` (name, description, level, factory_code, operator_id) VALUES ('上海临港工厂', '查看工厂数据', 'p2', '2640(不确定后面问一下)', 1);
INSERT INTO `role` (name, description, level, factory_code, operator_id) VALUES ('上海临港工厂-只读', '查看工厂数据-只读', 'p3', '2640(不确定后面问一下)', 1);
# 配置管理员的user_id和role_id,将除了只读之外的权限给管理员
INSERT INTO `user_role` (user_id, role_id) VALUES (1, 1);
INSERT INTO `user_role` (user_id, role_id) VALUES (1, 2);
INSERT INTO `user_role` (user_id, role_id) VALUES (1, 3);
# 配置管理员的role_id,将对应的资源路径给管理员
INSERT INTO `resource` (path, role_id) VALUES ('2640(不确定后面问一下)', 1);
INSERT INTO `resource` (path, role_id) VALUES ('2640(不确定后面问一下)', 2);
INSERT INTO `resource` (path, role_id) VALUES ('2640(不确定后面问一下)', 3);
COMMIT;配置Nginx反向代理
shell
sudo nano /etc/nginx/sites-enabled/yanfeng新版:
shell
server {
listen 9000;
server_name localhost;
# 静态资源入口
location / {
root /var/www/dist/;
index index.html index.htm;
}
# 错误页
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 通用 API 代理(如 /api/user, /api/login 等)
location ~ ^/api/(?![^/]+/[^/]+/tcs/core|[^/]+/[^/]+/websocket)(.*)$ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8088;
proxy_read_timeout 10s;
}
# tcs/core 接口代理
location ~ ^/api/[^/]+/[^/]+/tcs/core/?(.*)$ {
rewrite ^/api/[^/]+/[^/]+/tcs/core/?(.*)$ /tcs/core/$1 break;
proxy_pass http://127.0.0.1:7566;
proxy_read_timeout 10s;
}
# websocket 接口代理(支持所有工厂/产线)
location ~ ^/api/[^/]+/[^/]+/websocket$ {
proxy_pass http://127.0.0.1:7567;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# 跨域预检
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
return 204;
}
}
}旧版:
shell
server {
listen 9000;
server_name localhost;
location / {
root /var/www/dist/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /api {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://127.0.0.1:8088;
proxy_read_timeout 10s;
}
location /api/【工厂编号】 {
rewrite ^/api/[^/]+/(.*) /$1 break;
proxy_pass http://127.0.0.1:8088;
proxy_read_timeout 10s;
}
location /api/【工厂编号】/【产线1编号】/tcs/core {
rewrite ^/api/[^/]+/[^/]+/tcs/core/?(.*)$ /tcs/core/$1 break;
proxy_pass http://【调度系统IP】:7566;
proxy_read_timeout 10s;
}
location /api/【工厂编号】/【产线2编号】/tcs/core {
rewrite ^/api/[^/]+/[^/]+/tcs/core/?(.*)$ /tcs/core/$1 break;
proxy_pass http://【调度系统IP】:7566;
proxy_read_timeout 10s;
}
location /api/【工厂编号】/【产线1编号】/websocket {
proxy_pass http://【调度系统IP】:7567;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# 处理跨域预检请求的响应头
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
# 可选:处理 OPTIONS 请求
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
return 204; # 204 No Content 表示成功处理预检请求
}
}
location /api/【工厂编号】/【产线2编号】/websocket {
proxy_pass http://【调度系统IP】:7567;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# 处理跨域预检请求的响应头
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
# 可选:处理 OPTIONS 请求
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Upgrade, Connection, Host";
return 204; # 204 No Content 表示成功处理预检请求
}
}
}shell
sudo systemctl restart nginx创建后端服务
shell
sudo nano /etc/systemd/system/data-agv-yanfeng.serviceshell
[Unit]
Description=Data AGV Yanfeng Service
[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/var/www
ExecStart=/usr/bin/java -Xmx3g -Xms3g -XX:+UseG1GC -jar /var/www/data-agv-yanfeng-1.0.jar
Restart=on-failure
SuccessExitStatus=143
[Install]
WantedBy=multi-user.targetshell
sudo systemctl daemon-reload
sudo systemctl enable data-agv-yanfeng
sudo systemctl start data-agv-yanfengshell
systemctl status data-agv-yanfeng
journalctl -u data-agv-yanfeng配置定时任务采集数据
shell
sudo crontab -eshell
0 1 * * * /usr/bin/curl -s http://{localhost:8088}/monitor/line/handle?date=$(date -d "yesterday" +\%Y\%m\%d)
0 2 * * * /usr/bin/curl -s http://{localhost:8088}/monitor/line/sync?date=$(date -d "yesterday" +\%Y\%m\%d)检查
打开浏览器,输入ip:9000,用户名密码admin acbd@1234如果有页面,说明前端部署成功
再进行重启检查,以检验软件服务在系统重启后是否会自启
shell
sudo reboot now异常处理参考
如遇到500错误:后端服务已经停止,要重启后端服务,并检查日志;
如遇到502错误:后端服务运行正常,但是在处理请求时内部发生错误,应检查该接口的业务逻辑是否错误;
如遇到400错误:前端发送的请求有错误,需要检查请求体、请求参数是否有错误;
如遇到404错误:请求路径有误,需检查Nginx反向代理配置是否有错误;
……
