# VPP Agent Getting Started ## 容器部署 ### 部署 docker ``` $ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun ``` ### 拉取 vpp-agent 镜像 镜像包含 vpp-agent 和 vpp ``` $ docker pull ligato/vpp-agent ``` ### 拉取 etcd 镜像 和启动 etcd ``` $ docker pull quay.io/coreos/etcd:v3.1.0 $ docker run -p 2379:2379 --name etcd --rm quay.io/coreos/etcd:v3.1.0 /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 ``` ### 启动 vpp-agent 和 vpp ``` docker run -it --rm --name vpp-agent -p 5002:5002 -p 9191:9191 --privileged ligato/vpp-agent ``` 查看信息 ``` docker ps -f name=vpp-agent ``` ## 编译部署 ### 安装 go ``` $ wget https://golang.google.cn/dl/go1.16.7.linux-amd64.tar.gz $ tar -C /usr/local -xzf go1.16.7.linux-amd64.tar.gz $ export PATH=$PATH:/usr/local/go/bin ``` ### 拉取代码 ``` git clone https://github.com/ligato/vpp-agent.git ``` ### 编译最新稳定版本 使用国内代理 ``` $ export GO111MODULE=on $ export GOPROXY=https://goproxy.cn ``` 编译 ``` $ cd vpp-agent $ make cmd ``` 查看对应的二进制 ``` $ ls cmd ``` ### 设置配置 创建配置集目录 ``` $ mkdir /opt/vpp-agent/dev ``` /opt/vpp-agent/dev/etcd.conf ``` insecure-transport: true dial-timeout: 1s endpoints: - "127.0.0.1:2379" ``` /opt/vpp-agent/dev/grpc.conf ``` endpoint: 0.0.0.0:9111 ``` /opt/vpp-agent/dev/supervisor.conf vpp-agent-init 使用 ``` programs: - name: "vpp" executable-path: "/usr/bin/vpp" executable-args: ["-c", "/etc/vpp/vpp.conf"] - name: "agent" executable-path: "/bin/vpp-agent" executable-args: ["--config-dir=/opt/vpp-agent/dev"] hooks: - cmd: "/opt/vpp-agent/dev/init_hook.sh" ``` /opt/vpp-agent/dev/init_hook.sh ``` #!/usr/bin/env bash terminate_process () { PID=$(pidof $1) if [[ ${PID} != "" ]]; then kill ${PID} echo "process $1 terminated" fi } if [[ "${SUPERVISOR_PROCESS_NAME}" = "agent" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then terminate_process vpp-agent-init fi if [[ "${SUPERVISOR_PROCESS_NAME}" = "vpp" && "${SUPERVISOR_PROCESS_STATE}" = "terminated" ]]; then terminate_process vpp-agent-init ``` ### 启动 ``` $ ./vpp-agent -config-dir=/opt/vpp-agent/dev ``` 测试一下 ``` $ curl -X GET http://localhost:9191/dump/vpp/v2/interfaces ``` ## Astri 分支部署 ### 拉取分支 ``` $ git clone -b main http://gitlab.sh.99cloud.net/5GS/vpp-agent.git ``` ### 编译生成 deb 包 ``` $ cd vpp-agent $ git tag -a v1.0 -m "test" $ make deb ``` ### 安装 ``` $ sudo dpkg -i docker/astri/*.deb ``` ### 配置文件 redis-server 的配置文件,使用 docker/astri/prod/redis-server.conf vpp-agent 配置文件位于 /etc/vpp-agent 下 redis.conf ``` # NodeConfig db: 0 dial-timeout: 0 enable-query-on-slave: false endpoint: 127.0.0.1:6379 password: "" pool: busy-timeout: 0 idle-check-frequency: 0 idle-timeout: 0 max-connections: 0 ead-timeout: 0 tls: ca-file: "" cert-file: "" enabled: false key-file: "" skip-verify: false write-timeout: 0 ``` vpp-ifplugin.conf ifplugin stopwatch 数据库 ``` stopwatch: true status-publishers: [etcd, redis] ``` vpp-ifplugin.conf ``` stopwatch: true status-publishers: [etcd, redis] ``` filedb.conf ``` # A set of files/directories with configuration files. If target is a directory, all .json or .yaml files are read. configuration-paths: ["/etc/vpp-agent/"] # Path where the status data will be stored. If not defined, status is not propagated. File extension determines # whether the data will be stored as .json or .yaml. Target may cannot a directory. status-path: "/etc/vpp-agent/ha.json" ``` vpp-upfplugin.conf ``` # VPP agent allows to send context data back to ETCD/Redis. # To allow it, add desired status publishers. Currently supported # for [etcd] and [redis] (both options can be chosen together) publishers: - redis instanceid: "upfconfig-123" grpcserver: "mp.default.svc.cluster.local:8081" ``` ### 启动 ``` $ vpp-agent ``` ## 调试 ### 安装调试工具 ``` $ git clone https://github.com/go-delve/delve $ cd delve $ go install github.com/go-delve/delve/cmd/dlv ``` ### 调试 ``` $ dlv exec vpp-agent/cmd/vpp-agent -- -config-dir=/etc/vpp-agent ``` 如果调试失败,可以尝试直接 go build 生成二进制文件 ``` $ cd vpp-agent/cmd/vpp-agent $ go build ```