sonic 安装概要
1.新建 docker-compose.yml
version: '3'
services:
sonic-mysql:
image: mysql:5.7
restart: always
container_name: s_mysql
volumes:
- ./mysql/db:/var/lib/mysql
- ./mysql/log:/var/log/mysql
- ./mysql/conf:/etc/mysql/mysql.conf.d
- ./mysql/backup:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_ROOT_HOST: ${MYSQL_ROOT_HOST}
MYSQL_USER: ${MYSQL_USER_NAME}
MYSQL_PASSWORD: ${MYSQL_USER_PWD}
ports:
- 3306:3306
sonic-server-simple:
image: 'sonicorg/sonic-server-simple:v1.3.0-beta1'
environment:
#以下为MySql配置,localhost请替换为自己MySql服务的ipv4地址
- MYSQL_HOST=10.55.165.36
- MYSQL_PORT=3306
- MYSQL_DATABASE=sonic
- MYSQL_USERNAME=root
- MYSQL_PASSWORD=00000000
#在服务器部署的话,localhost改为服务器ip,port更改为sonic-server-simple暴露的port(一般不变)
- SONIC_API_HOST=10.55.165.36
- SONIC_API_PORT=8094
- SONIC_NETTY_PORT=8095
#token加密的key值
- SECRET_KEY=com.knx.vxhcm
#身份验证token有效天数
- EXPIRE_DAY=14
#前端页面访问地址,不填默认为http://localhost:3000
- CLIENT_HOST=http://10.55.165.36:3000
#文件保留天数(指测试过程产生的文件,包括图片、录像等等)
- FILE_KEEP_DAY=60
#测试结果保留天数
- RESULT_KEEP_DAY=60
#以下均为Cron表达式
#清理文件定时任务
- FILE_CRON=0 0 12 * * ?
#清理测试结果定时任务
- RESULT_CRON=0 0 12 * * ?
#发送日报定时任务
- DAY_CRON=0 0 10 * * ?
#发送周报定时任务
- WEEK_CRON=0 0 10 ? * Mon
networks:
- sonic-network
volumes:
- ./files:/keepFiles/
- ./files:/imageFiles/
- ./files:/recordFiles/
- ./files:/packageFiles/
- ./files:/logs/
ports:
- '8094:8094'
- '8095:8095'
sonic-client-web:
image: 'sonicorg/sonic-client-web:v1.3.0-beta1.1'
environment:
#在服务器部署的话,localhost改为服务器ip,port更改为sonic-server-simple暴露的port(一般不变)
- SONIC_API_HOST=10.55.165.36
- SONIC_API_PORT=8094
networks:
- sonic-network
ports:
- '3000:80'
volumes:
files:
networks:
sonic-network:
driver: bridge
2. docker-compose.yml 同级新建一个名为.env 的文件。
文件内容:
# root用户密码
MYSQL_ROOT_PASSWORD=00000000
MYSQL_ROOT_HOST=%
# 使用 新增用户
MYSQL_USER_NAME=jsha
# 使用 新增用户密码
MYSQL_USER_PWD=11111111
2. docker-compose.yml 同级新建名为 mysql 的目录。
如下目录文件结构:
mysql
├── backup
├── conf
│ └── mysqld.cnf
├── db
└── log
mysql.cnf 文件 内容:
# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
default-character-set=utf8
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#以下是启动log-bin的配置
log-bin = binlog
server-id=1
binlog-format = ROW
binlog_rows_query_log_events = off
default-time_zone = '+8:00'
# 更改字符集 如果想Mysql在后续的操作中文不出现乱码,则需要修改配置文件内容
symbolic-links=0
docker-compose up -d --build
运行镜像内 mysql:
docker exec -it s_mysql mysql -uroot -p00000000
创建数据库 sql:
CREATE DATABASE IF NOT EXISTS sonic DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
退出 mysql docker:
.exit
前后端部署完毕!可以打开浏览器访问 http://localhost:3000,然后可 直接前往 部署 Agent 端界面
(附)如果提示系统出错了,请检查 mysql 是否连接正常,是否能用 ip 去访问数据库(如不能请百度),simple 容器是否启动。
# 错误速查
#### could not create connection to database server(sonic-server-simple docker log)
docker-compose 内 MYSQL_HOST、SONIC_API_HOST 、SONIC_API_HOST、CLIENT_HOST 内网地址不能是 127.0.0.1 或者 0.0.0
### docker 操作
···
docker ps -a #查看启动的服务
docker kill [CONTAINER ID] 杀死指定进程
docker kill $(docker ps -a -q) 杀死所有正在运行的容器
docker rm $(docker ps -a -q) 删除所有已经停止的容器
docker rmi [MAGE ID] 删除指定镜像
docker rmi $(docker images -q) 删除所有镜像
docker log -f [CONTAINER ID/NAMES] 查看指定容器日志
docker-compose up -d 后台启动服务
docker-compose up -d --build 后台启动(重新编译新镜像)
docker-compose -h #帮助命令
docker-compose down #停止并删除服务
docker-compose restart #重启服务
docker-compose stop #停止服务
docker-compose start #开始服务
docker-compose logs -f #显示日志日志
docker exec -it [镜像名/ID] bash #运行镜像bash
docker exec -it [镜像名/ID] mysql -uroot -p #运行镜像内mysql
···