Linux frpc 自启动设置方法 - 详细教程
Linux frpc 自启动设置方法
本文将详细介绍如何在 Linux 系统中设置 frpc 自启动,以确保 frpc 能够在系统启动时自动运行。
1. 创建启动脚本
在 Linux 系统中创建一个启动脚本,例如将以下内容保存到 /etc/init.d/frpc 文件中:
#!/bin/sh
#
# frpc - startup script for frpc
#
# chkconfig: - 85 15
description: frpc is a fast reverse proxy client for remote access
processname: frpc
config: /etc/frpc.ini
pidfile: /var/run/frpc.pid
### BEGIN INIT INFO
# Provides: frpc
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fast reverse proxy client for remote access
# Description: frpc is a fast reverse proxy client for remote access
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
# Path to the frpc binary.
FRPC_BIN="/usr/local/bin/frpc"
# Path to the frpc configuration file.
FRPC_CONF="/etc/frpc.ini"
# Path to the frpc pid file.
FRPC_PID_FILE="/var/run/frpc.pid"
# Check if the frpc binary exists.
if [ ! -x "$FRPC_BIN" ]; then
echo "Error: frpc binary not found or not executable."
exit 1
fi
# Check if the frpc configuration file exists.
if [ ! -f "$FRPC_CONF" ]; then
echo "Error: frpc configuration file not found."
exit 1
fi
# Check if the frpc pid file exists.
if [ -f "$FRPC_PID_FILE" ]; then
PID=$(cat "$FRPC_PID_FILE")
if [ -n "$PID" ] && [ -d /proc/$PID ]; then
echo "Error: frpc is already running (pid $PID)."
exit 1
fi
fi
# Start frpc.
echo -n "Starting frpc: "
daemon --pidfile="$FRPC_PID_FILE" "$FRPC_BIN" -c "$FRPC_CONF"
RETVAL=?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/frpc
# Stop frpc.
stop() {
echo -n "Stopping frpc: "
killproc -p "$FRPC_PID_FILE" "$FRPC_BIN"
RETVAL=?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/frpc
}
# Restart frpc.
restart() {
stop
start
}
# Check frpc status.
status() {
status -p "$FRPC_PID_FILE" "$FRPC_BIN"
}
# Main program.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
2. 设置脚本权限
将启动脚本设置为可执行文件:
chmod +x /etc/init.d/frpc
3. 添加服务到系统列表
将 frpc 添加到系统服务列表中:
chkconfig --add frpc
4. 启动服务
启动 frpc 服务:
service frpc start
5. 确认服务启动成功
确认 frpc 服务已经启动成功:
service frpc status
停止和重启服务
如果需要停止或重启 frpc 服务,可以使用以下命令:
service frpc stop
service frpc restart
完成以上步骤后,frpc 将会在 Linux 系统启动时自动启动。
注意:
- 请根据您的实际情况修改启动脚本中的
FRPC_BIN、FRPC_CONF和FRPC_PID_FILE的路径。 - 如果您使用的是其他 Linux 发行版,启动脚本的路径和命令可能略有不同。
- 本文仅介绍基本的设置步骤,具体操作请参考 frpc 的官方文档。
原文地址: https://www.cveoy.top/t/topic/lwY2 著作权归作者所有。请勿转载和采集!