# sentinel-dashboard安装、运行

# 下载jar包

地址: https://github.com/alibaba/Sentinel/releases (opens new window)

wget https://github.com/alibaba/Sentinel/releases/download/1.6.3/sentinel-dashboard-1.6.3.jar

# dashboard启动

# 启动脚本

#!/bin/bash
#filename:  startup.sh
#description: sentinel-dashboard 启动脚本

# 判断是否有 sentinel-dashboard 正在运行,有就退出
pid=`ps ax | grep -i 'sentinel-dashboard'|grep java|grep -v grep| awk '{print $1}'`
if [ "$pid" ] ; then
        echo "sentinel-dashboard is running. pid = $pid"
        exit -1;
fi

# $0: 当前脚本的文件名
# dirname: 去除文件名的非目录部分,删除最后一个"/"或"\"后面的路径,即显示上级目录
export BASE_DIR=`cd $(dirname $0); pwd`

# 启动 sentinel-dashboard
nohup java -Dserver.port=8850 \
     -Dcsp.sentinel.dashboard.server=localhost:8850 \
     -Dproject.name=sentinel-dashboard \
     -Dcsp.sentinel.api.port=8719 \
     -Dcsp.sentinel.log.dir=log \
     -Dcsp.sentinel.log.output.type=file \
     -jar sentinel-dashboard-*.jar >> ${BASE_DIR}/logs/start.out 2>&1 &

echo "sentinel.dashboard is starting,you can check the ${BASE_DIR}/logs/start.out"

# 停止脚本

#!/bin/bash
#filename:  shutdown.sh
#description: sentinel-dashboard 停止脚本

# 查询出 sentinel-dashboard 运行的 pid
pid=`ps ax | grep -i 'sentinel-dashboard'|grep java|grep -v grep| awk '{print $1}'`

# 判断 $pid 的值 是否为空
if [ -z "$pid" ] ; then
        echo "No sentinel-dashboard running."
        exit -1;
fi

echo "The sentinel-dashboard(${pid}) is running..."

# 杀死进程
kill ${pid}

echo "Send shutdown request to sentinel-dashboard(${pid}) OK"

# 将脚本添加到环境变量中

SENTINEL_HOME=/opt/deploy/sentinel
alias sentinelup='${SENTINEL_HOME}/startup.sh'
alias sentineldown='${SENTINEL_HOME}/shutdown.sh'

# 命令详解

官方给出的端口为8080

windows

java -Dserver.port=8080 \
     -Dcsp.sentinel.dashboard.server=localhost:8080 \
     -Dproject.name=sentinel-dashboard \
     -Dcsp.sentinel.api.port=8719 \
     -Dcsp.sentinel.log.dir=log \
     -Dcsp.sentinel.log.output.type=file \
     -jar sentinel-dashboard-1.6.3.jar

linux

java -Dserver.port=8080 \
     -Dcsp.sentinel.dashboard.server=localhost:8080 \
     -Dproject.name=sentinel-dashboard \
     -Dcsp.sentinel.api.port=8719 \
     -Dcsp.sentinel.log.dir=log \
     -Dcsp.sentinel.log.output.type=file \
     -jar sentinel-dashboard-1.6.3.jar 2>&1 &

说明

-Dserver.port=8080 控制台端口,sentinel控制台是一个spring boot程序。客户端配置文件需要填对应的配置,如:spring.cloud.sentinel.transport.dashboard=192.168.1.102:8080

-Dcsp.sentinel.dashboard.server=localhost:8080 控制台的地址,指定控制台后客户端会自动向该地址发送心跳包。

-Dproject.name=sentinel-dashboard 指定Sentinel控制台程序的名称

-Dcsp.sentinel.api.port=8719 (默认8719) 客户端提供给Dashboard访问或者查看Sentinel的运行访问的参数

注:csp.sentinel.dashboard.server这个配置是用在客户端,这里Sentinel控制台也使用是用于自己监控自己程序的api,否则无法显示控制台的api情况,当然这个也可以根据情况不显示。

注:csp.sentinel.api.port=8719是客户端的端口,需要把客户端设置的端口穿透防火墙,可在控制台的“机器列表”中查看到端口号,这里Sentinel控制台也使用是用于自己程序的api传输,由于是默认端口所以控制台也可以不设置。

注:客户端需向控制台提供端口,配置文件配置,如:spring.cloud.sentinel.transport.port=8720

控制台推送规则的日志在 :${user.home}/logs/csp/sentinel-dashboard.log 中,

客户端接收规则日志在 ${user.home}/logs/csp/record.log

启动配置wiki: https://github.com/alibaba/Sentinel/wiki/启动配置项 (opens new window)

spring cloud alibaba配置、整合feign、动态数据源支持 等的wiki:https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel (opens new window)

# dashboard添加到linux守护进程

新建sh脚本

vim startup.sh

脚本中填入

#!/bin/bash

nohup>start.log java -Dserver.port=8080 \
     -Dcsp.sentinel.dashboard.server=localhost:8080 \
     -Dproject.name=sentinel-dashboard \
     -Dcsp.sentinel.api.port=8719 \
     -Dcsp.sentinel.log.dir=/Users/sky/app/sentinel/log \
     -Dcsp.sentinel.log.output.type=file \
     -jar /Users/sky/app/sentinel/sentinel-dashboard-1.6.3.jar 2>&1 &%

赋予权限

chmod 777 /opt/sentinel-dashboard/startup.sh

创建守护进程

vim /lib/systemd/system/sentinel-dashboard.service

文件中填入

[Unit]
Description=sentinel-dashboard
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
ExecStart=/opt/sentinel-dashboard/startup.sh
Restart=always
PrivateTmp=true

[Install]
WantedBy=multi-user.target

赋予权限

chmod 777 /lib/systemd/system/sentinel-dashboard.service

启用服务

systemctl enable sentinel-dashboard.service
systemctl daemon-reload

运行

systemctl start sentinel-dashboard.service

查看状态

systemctl status sentinel-dashboard.service

查看进程和端口

ps -ef|grep sentinel-dashboard
netstat -anltp|grep 8080
netstat -anltp|grep 8719