# 七、Lars啟動工具腳本
我們提供一個啟動lars系統子系統和測試工具的一個腳本工具,`run_lars`
> Lars/run_lars
```bash
#!/bin/bash
LARS_REPORTER_PATH="./lars_reporter"
LARS_DNS_PATH="./lars_dns"
LARS_LBAGENT_PATH="./lars_loadbalance_agent"
LARS_WEB_PATH="./larsWeb"
LARS_API_EXAMPLE_PATH="./api/cpp/example"
usage()
{
echo ""
echo "=======啟動子系統=========="
echo "Usage ./run_lars [reporter|dns|lbagent|web|test]"
echo
echo "=======測試工具============"
echo "Usage ./run_lars test gethost ModID CmdID"
echo "Usage ./run_lars test getroute ModID CmdID"
echo "Usage ./run_lars test report ModID CmdID IP Port 0|1 --- 0:SUCC, 1:OVERLOAD"
echo "Usage ./run_lars test simulator ModID CmdID [errRate(0-10)] [queryCnt(0-999999)]"
echo "Usage ./run_lars test qps ThreadNum"
echo "Usage ./run_lars test example ModID CmdID"
echo
}
if [ "$1" = "test" ]; then
if [ "$2" = "gethost" ]; then
$PWD/$LARS_API_EXAMPLE_PATH/get_host $3 $4
elif [ "$2" = "getroute" ]; then
$PWD/$LARS_API_EXAMPLE_PATH/get_route $3 $4
elif [ "$2" = "report" ]; then
$PWD/$LARS_API_EXAMPLE_PATH/report $3 $4 $5 $6 $7
elif [ "$2" = "example" ]; then
$PWD/$LARS_API_EXAMPLE_PATH/example $3 $4
elif [ "$2" = "simulator" ]; then
if [ $# -eq 4 ]; then
$PWD/$LARS_API_EXAMPLE_PATH/simulator $3 $4
elif [ $# -eq 5 ]; then
$PWD/$LARS_API_EXAMPLE_PATH/simulator $3 $4 $5
elif [ $# -eq 6 ]; then
$PWD/$LARS_API_EXAMPLE_PATH/simulator $3 $4 $5 $6
else
usage
fi
elif [ "$2" = "qps" ]; then
$PWD/$LARS_API_EXAMPLE_PATH/qps $3
fi
elif [ "$1" = "reporter" ]; then
cd $LARS_REPORTER_PATH
./bin/lars_reporter
elif [ "$1" = "dns" ]; then
cd $LARS_DNS_PATH
./bin/lars_dns
elif [ "$1" = "lbagent" ]; then
cd $LARS_LBAGENT_PATH
./bin/lars_lb_agent
elif [ "$1" = "web" ]; then
cd $LARS_WEB_PATH
./lars-web
elif [ "$1" = "help" ]; then
usage
else
usage
fi
```
**啟動 Lars Reporter**
```bash
$ ./run_lars reporter
▄▄
██
██ ▄█████▄ ██▄████ ▄▄█████▄
██ ? ▄▄▄██ ██? ██▄▄▄▄ ?
██ ▄██???██ ██ ????██▄
██▄▄▄▄▄▄ ██▄▄▄███ ██ █▄▄▄▄▄██
???????? ???? ?? ?? ??????
Load balance And Remote service schedule System
_____ _
| __ \ | |
| |__) |___ _ __ ___ _ __| |_ ___ _ __
| _ // _ \ '_ \ / _ \| '__| __/ _ \ '__|
| | \ \ __/ |_) | (_) | | | || __/ |
|_| \_\___| .__/ \___/|_| \__\___|_|
| |
|_|
ITCAST(https://www.itcast.cn)
------------------------------------
create 0 thread
create 1 thread
create 2 thread
create 3 thread
create 4 thread
add msg cb msgid = 3
```
**啟動 Lars dns**
```bash
$ ./run_lars dns
▄▄
██
██ ▄█████▄ ██▄████ ▄▄█████▄
██ ? ▄▄▄██ ██? ██▄▄▄▄ ?
██ ▄██???██ ██ ????██▄
██▄▄▄▄▄▄ ██▄▄▄███ ██ █▄▄▄▄▄██
???????? ???? ?? ?? ??????
Load balance And Remote service schedule System
_____
| __ \
| | | |_ __ ___
| | | | '_ \/ __|
| |__| | | | \__ \
|_____/|_| |_|___/
ITCAST(https://www.itcast.cn)
------------------------------------
create 0 thread
create 1 thread
create 2 thread
create 3 thread
create 4 thread
add msg cb msgid = 1
lars dns service ....
now route version is 1574674421
```
**啟動 Lars Lb Agent**
```c
$ ./run_lars lbagent
▄▄
██
██ ▄█████▄ ██▄████ ▄▄█████▄
██ ? ▄▄▄██ ██? ██▄▄▄▄ ?
██ ▄██???██ ██ ????██▄
██▄▄▄▄▄▄ ██▄▄▄███ ██ █▄▄▄▄▄██
???????? ???? ?? ?? ??????
Load balance And Remote service schedule System
_ _ _
| | | | /\ | |
| | | |__ / \ __ _ ___ _ __ | |_
| | | '_ \ / /\ \ / _` |/ _ \ '_ \| __|
| |____| |_) | / ____ \ (_| | __/ | | | |_
|______|_.__/ /_/ \_\__, |\___|_| |_|\__|
__/ |
|___/
ITCAST(https://www.itcast.cn)
------------------------------------
```
**其他測試工具啟動方式**
```bash
$ ./run_lars help
=======啟動子系統==========
Usage ./run_lars [reporter|dns|lbagent|web|test]
=======測試工具============
Usage ./run_lars test gethost ModID CmdID
Usage ./run_lars test getroute ModID CmdID
Usage ./run_lars test report ModID CmdID IP Port 0|1 --- 0:SUCC, 1:OVERLOAD
Usage ./run_lars test simulator ModID CmdID [errRate(0-10)] [queryCnt(0-999999)]
Usage ./run_lars test qps ThreadNum
Usage ./run_lars test example ModID CmdID
```
---
### 關于作者:
作者:`Aceld(劉丹冰)`
mail: [danbing.at@gmail.com](mailto:danbing.at@gmail.com)
github: [https://github.com/aceld](https://github.com/aceld)
原創書籍: [http://www.hmoore.net/@aceld](http://www.hmoore.net/@aceld)

>**原創聲明:未經作者允許請勿轉載, 如果轉載請注明出處**
- 一、Lars系統概述
- 第1章-概述
- 第2章-項目目錄構建
- 二、Reactor模型服務器框架
- 第1章-項目結構與V0.1雛形
- 第2章-內存管理與Buffer封裝
- 第3章-事件觸發EventLoop
- 第4章-鏈接與消息封裝
- 第5章-Client客戶端模型
- 第6章-連接管理及限制
- 第7章-消息業務路由分發機制
- 第8章-鏈接創建/銷毀Hook機制
- 第9章-消息任務隊列與線程池
- 第10章-配置文件讀寫功能
- 第11章-udp服務與客戶端
- 第12章-數據傳輸協議protocol buffer
- 第13章-QPS性能測試
- 第14章-異步消息任務機制
- 第15章-鏈接屬性設置功能
- 三、Lars系統之DNSService
- 第1章-Lars-dns簡介
- 第2章-數據庫創建
- 第3章-項目目錄結構及環境構建
- 第4章-Route結構的定義
- 第5章-獲取Route信息
- 第6章-Route訂閱模式
- 第7章-Backend Thread實時監控
- 四、Lars系統之Report Service
- 第1章-項目概述-數據表及proto3協議定義
- 第2章-獲取report上報數據
- 第3章-存儲線程池及消息隊列
- 五、Lars系統之LoadBalance Agent
- 第1章-項目概述及構建
- 第2章-主模塊業務結構搭建
- 第3章-Report與Dns Client設計與實現
- 第4章-負載均衡模塊基礎設計
- 第5章-負載均衡獲取Host主機信息API
- 第6章-負載均衡上報Host主機信息API
- 第7章-過期窗口清理與過載超時(V0.5)
- 第8章-定期拉取最新路由信息(V0.6)
- 第9章-負載均衡獲取Route信息API(0.7)
- 第10章-API初始化接口(V0.8)
- 第11章-Lars Agent性能測試工具
- 第12章- Lars啟動工具腳本