Linux Centos下安装iperf3并注册成服务[原创]

iperf3 是一款网络性能测试工具,用于在TCP和UDP数据流之间测量最大带宽。它可以帮助您测试网络连接的速度、延迟、丢包等参数。

下面介绍如何在Linux Centos下部署方法,并且注册成服务

一、安装iperf3

  打开终端并执行命令`sudo yum install iperf3`来安装iperf3。

二、配置服务配置

  1、创建配置文件,文件名为iperf3.service:命令: vim /usr/lib/systemd/system/iperf3.service 

  2、把下面文件内容编写在iperf3.service文件中

 1 [Unit]
 2 Description=iperf3 service
 3 After=network.target
 4 
 5 [Service]
 6 Type=forking
 7 ExecStart=/usr/bin/iperf3 -s -D
 8 ExecReload=/bin/kill -s HUP $MAINPID
 9 ExecStop=/bin/kill -s QUIT $MAINPID
10 PrivateTmp=true
11 
12 [Install]
13 WantedBy=multi-user.target 

文件参数介绍

[Unit]:服务的说明
Description:描述服务
After:描述服务类别

[Service] 服务运行参数的设置
Type=forking 后台运行的形式
ExecStart 服务的具体运行命令
ExecReload 重启命令
ExecStop 停止命令
PrivateTmp=True 给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径

[Install] 服务安装的相关设置,可设置为多用户 
其中ExecStart=/usr/bin/iperf3 -s -D 这一行中的-D参数必须添加,代表进程守护方式运行,可以不卡光标行

  3、刷新iperf3.service 配置信息,命令:systemctl daemon-reload

  4、设置开机启动,命令:systemctl enable iperf3.service
  如果返回类似“Created symlink from /etc/systemd/system/multi-user.target.wants/iperf3.service to /usr/lib/systemd/system/iperf3.service.”的消息,代表注册成功!

三、相关命令

systemctl is-enabled iperf3.service #查询服务是否开机启动
systemctl enable iperf3.service #开机运行服务
systemctl disable iperf3.service #取消开机运行
systemctl start iperf3.service #启动服务
systemctl stop iperf3.service #停止服务
systemctl restart iperf3.service #重启服务
systemctl reload iperf3.service #重新加载服务配置文件
systemctl status iperf3.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

 

posted @ 2024-03-05 20:59  大宋666  阅读(386)  评论(0编辑  收藏  举报