两个问题:
1.在centos上如何开机运行?
2.怎样后台运行,而不用一直开着putty
谢谢
nohup 后台可以用
supervisor
rc.local
systemd
nohup
楼上能详细说说吗? @lnzoro @wxyzh
@impig33 建议这一类的问题可以通过搜索引擎自行解决。
已经解决:
使用systemd配置开机自启,适用于 centos7 Ubuntu 16 或 debian 8。
vi /etc/systemd/system/frps.service 新建此文件,并写入以下内容
:
[Unit]
Description=frps daemon
[Service]
Type=simple
ExecStart=/usr/bin/frps -c /etc/frps/frps.ini
[Install]
WantedBy=multi-user.target
启动并设为开机自启。
$ systemctl start frps
$ systemctl enable frps
参照:lcbk.net/9766.html
------------centos6.5及以下---------------------
vi /etc/rc.local
在最下面加一行/usr/sbin/frp/frps -c /usr/sbin/frp/frps.ini
其中 /usr/sbin/frp是程序放置的目录,重启ok
.
太好用了,使用特权模式服务端免配置,太好用了,谢谢作者。
贴一下我之前无法开机自启frpc的解决办法,原因可能是因为系统开机并未准备好网络,或者其它依赖
sudo vim /etc/systemd/system/frpc.service
按如下修改
[Unit]
Description=frpc daemon
After=syslog.target network.target
Wants=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/frp/frpc -c /etc/frp/frpc.ini
Restart= always
RestartSec=1min
ExecStop=/usr/bin/killall frpc
[Install]
WantedBy=multi-user.target
使用sudo systemctl enable frpc.service启用
@vc5 :+1:
也可以试试 0.11.0 frpc 新增的 login_fail_exit 参数设置为 false,这样启动时没连上服务器就不会自动退出了,而是每隔30s自动重连。
http://free-e.net/109 这篇文章能帮助到您。
If you don't have systemd or your kernel don't support systemd, this is my init.d service file:
#!/bin/sh
### BEGIN INIT INFO
# Provides: frpc
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: frpc service deamon
# Description: frpc service daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/frpc
DAEMON_OPTS=-c\ /etc/frp/frpc.ini
NAME=frpc
USER=eric
set -e
. /lib/lsb/init-functions
start() {
echo -n "Starting $NAME: "
start-stop-daemon --start \
--user $USER \
-m --pidfile /var/run/$NAME.pid \
-b --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
}
stop() {
echo -n "Stopping $NAME: "
start-stop-daemon --stop \
--pidfile /var/run/$NAME.pid || true
echo "$NAME."
}
status() {
status_of_proc -p /var/run/$NAME.pid "$DAEMON" $NAME && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
sleep 2
start
;;
*)
echo "Usage: $NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Hope this can help you.
Oh, by the way, you should put the binary into /usr/bin and put the config file into /etc/frp/
nobody AND ports below 1024AmbientCapabilities support (usually kernel >= linux4.3) [Unit]
Description=FRP Server Daemon
[Service]
Type=simple
AmbientCapabilities=CAP_NET_BIND_SERVICE
ExecStart=/opt/bin/frps -c /opt/etc/frps.ini
Restart=always
RestartSec=2s
User=nobody
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
AmbientCapabilities support,You need apt install libcap2-bin then[Unit]
Description=FRP Server Daemon
[Service]
Type=simple
ExecStartPre=-/usr/sbin/setcap cap_net_bind_service=+ep /opt/bin/frps
ExecStart=/opt/bin/frps -c /opt/etc/frps.ini
Restart=always
RestartSec=2s
User=nobody
PermissionsStartOnly=true
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
[Unit]
Description=FRP Client Daemon
After=network.target
Wants=network.target
[Service]
Type=simple
ExecStart=/opt/bin/frpc -c /opt/etc/frpc.ini
Restart=always
RestartSec=20s
User=nobody
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable frpc
systemctl status frpc
systemctl enable frps
systemctl status frps
Also Archived at https://gist.github.com/ihipop/4dc607caef7c874209521b10d18e35af
centos 6.5 init.d script
centos 6.5 客户端环境下配置后台自启
inspire by
https://serverfault.com/a/869143
https://github.com/utobi/prometheus-rpm/blob/master/node_exporter/contrib/node_exporter.init
ensure binary in /usr/bin/frpc, and configure file in /etc/frp/frpc.ini
edit /etc/init.d/frpc and chkconfig add frpc
#!/bin/bash
# chkconfig: - 85 15
# # description: frp init script
RETVAL=0
PROG="frpc"
EXEC="/usr/bin/frpc"
LOCKFILE="/var/lock/subsys/$PROG"
OPTIONS="-c /etc/frp/frpc.ini"
# Source function library.
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo "/etc/rc.d/init.d/functions is not exists"
exit 0
fi
start() {
if [ -f $LOCKFILE ]
then
echo "$PROG is already running!"
else
echo -n "Starting $PROG: "
#$EXEC $OPTIONS &
nohup $EXEC $OPTIONS >/dev/null 2>&1 &
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE && success || failure
echo
return $RETVAL
fi
}
stop() {
echo -n "Stopping $PROG: "
killproc $EXEC
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -r $LOCKFILE && success || failure
echo
}
restart ()
{
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $PROG
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
in server with ubuntu 16.04, systemd is available
cat /etc/systemd/system/frps.service
[Unit]
Description=Frps Service
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/var/run/frps.pid
ExecStart=/usr/sbin/frp/frps -c /etc/frp/frps.ini
Restart=on-failure
[Install]
WantedBy=multi-user.target
Most helpful comment
贴一下我之前无法开机自启frpc的解决办法,原因可能是因为系统开机并未准备好网络,或者其它依赖
sudo vim /etc/systemd/system/frpc.service按如下修改
使用
sudo systemctl enable frpc.service启用