Skip to content

配置

  • 数据库配置文件 /usr/local/sunlight/dvs/etc 数据库配置文件 dvs-robot.appsettings.json
{
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information"
        }
    },
    "Urls": "http://*:3021",
    "ConnectionStrings": {
        "MySQL": "server=XXXX;Port=XXXX;uid=XXXX;pwd=XXXX;database=robot;convert zero datetime=true;Charset=utf8mb4",
    },
    "Redis": {
        "ConnectionString": "localhost:6379,password=XXXX,defaultDatabase=0"
    }
}

主要是设置后端接口服务接口、mysql数据库链接、redis服务链接

  • systemd系统服务配置文件 /usr/lib/systemd/system 文件名 dvs-robot.service
[Unit]
Description=dvs-robot
After=network-online.target
Wants=network-online.target

[Service]
# modify when deploy in prod env
User=dvs
Group=dvs

Type=simple
ExecStart=/usr/local/dotnet-sdk/dotnet /usr/local/sunlight/dvs/dvs-robot/SLRobot.Admin.dll
WorkingDirectory=/usr/local/sunlight/dvs/dvs-robot

Restart=always
RestartSec=1
StartLimitInterval=0

[Install]
WantedBy=multi-user.target

主要是设置 sdk和可执行文件路径

  • 设置服务和设置开启启动
// 设置开机启动
systemctl enable dvs-robot.service

// 启动服务
systemctl start dvs-robot.service
  • 查看systemctl 启动的日志
//查看某个服务的日志情况
journalctl -u dvs-robot.service

// 查看实时的服务日志
journalctl -u dvs-robot.service -f

//查看时间区间
journalctl -u dvs-robot.service --since "2023-06-01" --until "2023-06-02 03:00"
  • tail查看linux日志
// 实时查看app.log日志
tail -f app.log

// 使用-n可以设置显示的行数
tail -n 20 -f app.log
  • nginx中添加前端项目

前端项目nginx配置

    location /robot{
        alias /usr/local/sunlight/dvs/dvs-ui/robot/;
        index index.html;
    }

后端接口服务配置

upstream robotservers{
    server 192.168.0.28:3021  max_fails=30  fail_timeout=10s;
}

location /api/robot{
    proxy_pass http://robotservers;
    client_max_body_size 100m;
}

upstream 负载均衡

http {
    upstream backend {
        server backend1.example.com;
        server backend2.example.com;
        server backend3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://backend;
        }
    }
}

自动负载三个域名1:1:1

也可以设置权重

http {
    upstream backend {
        server backend1.example.com weight=3;
        server backend2.example.com;
        server backup1.example.com backup;
    }

    server {
        ...
    }
}

三个服务承受负载的比重分别为:3:1:1