“CentOS服务搭建-04-运用FRPS服务搭建黑群晖NAS的FRPC”的版本间的差异

来自DeerGrove Wiki
跳转至: 导航搜索
《frpc.ini》文档
第102行: 第102行:
 
server_addr = xxx.xxx.xxx.xxx # 服务器地址
 
server_addr = xxx.xxx.xxx.xxx # 服务器地址
 
server_port = xxxx # 服务器端口
 
server_port = xxxx # 服务器端口
#token = xxxxxx # 有些服务端版本采用这个字节,多数采用“privilege_token”字节,token理解为密码
+
privilege_token = xxxxxx # token = xxxxxx 有些服务端版本采用这个字节,多数采用“privilege_token”字节,token理解为密码
privilege_token = xxxxxx
 
 
protocol = tcp
 
protocol = tcp
  
第110行: 第109行:
 
local_ip = 192.168.x.xx # 群晖的内网IP
 
local_ip = 192.168.x.xx # 群晖的内网IP
 
local_port = xxxxx # 你自己的web服务器端口
 
local_port = xxxxx # 你自己的web服务器端口
#subdomain = nas
 
# 选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置
 
 
custom_domains = xxxxxxx.xxx # 如果你有自己的域名,可以设置你自己的域名,先将自己的顶级域名解析到xxxxxxx.xxx(用CNAME记录,不要用A记录)
 
custom_domains = xxxxxxx.xxx # 如果你有自己的域名,可以设置你自己的域名,先将自己的顶级域名解析到xxxxxxx.xxx(用CNAME记录,不要用A记录)
 +
# subdomain = nas # 选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置
  
 
[ssh]
 
[ssh]
 
type = tcp
 
type = tcp
 
local_ip = 192.168.x.xxx
 
local_ip = 192.168.x.xxx
local_port = xxxxxx
+
local_port = xxxxxx # 需要转发到的端口,ssh端口默认是22
#需要转发到的端口,ssh端口默认是22
+
remote_port = xxxxxx # frp服务端的远程监听端口,即你访问服务端的remote_port就相当于访问客户端的 local_port,如果填0则会随机分配一个端口
remote_port = xxxxxx
 
#frp服务端的远程监听端口,即你访问服务端的remote_port就相当于访问客户端的 local_port,如果填0则会随机分配一个端口
 
  
 
#[DSM]
 
#[DSM]
#type = tcp
+
# type = tcp # tcp协议
# tcp协议
+
# local_ip = 192.168.x.xxx # 127.0.0.1指穿透本机,也可以填写群晖内网IP.
#local_ip = 192.168.x.xxx
+
# local_port = xxxxxx # 群晖内网HTTP端口,默认为5000.
# 127.0.0.1指穿透本机,也可以填写群晖内网IP.
+
# remote_port = xxxx # 映射到外网端口,暴露给服务器,这个客户端必须唯一
#local_port = xxxxxx
+
# subdomain = nas # 选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置
# 群晖内网HTTP端口,默认为5000.
 
#remote_port = xxxx
 
# 映射到外网端口,暴露给服务器,这个客户端必须唯一
 
#subdomain = nas
 
#选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置
 
 
</pre>
 
</pre>

2020年12月22日 (二) 13:17的版本


CentOS 7安装frps端

  • 本次安装服务应用于群晖系统,客户端为frpc0.26.0,因此,frps端使用同版本
  1. su获取root
  2. wget https://github.com/fatedier/frp/releases/download/v0.26.0/frp_0.26.0_linux_amd64.tar.gz
  3. 解压:tar xf frp_0.26.0_linux_amd64.tar.gz
  4. 改名:mv frp_0.26.0_linux_amd64 frp
  5. 进入目录:cd frp
  6. 删除没用的客户端文件:rm -f frpc*
  7. 配置文件:vim frps.ini
  8. 编辑ini文件 按ins进入编辑(精简)

《frps.ini》文档

[common]
 bind_addr = xxx.xxx.xxx.xxx # frps内网服务器地址,如果有防火墙的话,设置下述端口映射
 bind_port = xxxxx # frps服务端口
 vhost_http_port = xxxxx # http服务端口
 vhost_https_port = xxxxx # https服务端口
 privilege_token = xxxxxxxx # 握手密钥
 dashboard_port = xxxx # 服务器面板端口
 dashboard_user = xxxxx # 服务器面板用户
 dashboard_pwd = xxxxxxx # 服务器面板密码

frps的调试

  1. 临时运行:
     ./frps -c ./frps.ini
  2. 一次性开机运行:nohup ./frps -c ./frps.ini &
    命令启动之后如果不重启VPS就会一直运行,以下操作可以省略。只需要在服务器重启之后,重新cd到程序目录,输入一次nohup ./frps -c ./frps.ini &命令即可
  3. 停止:先找到这个进程,使用ps -ef 查看进程ID
    ps -aux | grep frp
  4. 然后:kill -9 PID

frps.service自启动文档

  1. 新建frps目录:mkdir /etc/frps
  2. mkdir /usr/etc/frps
  3. 拷贝frps.ini 到/etc/frps:cp /源目录/frps.ini /etc/frps/
  4. 拷贝frps到/usr/etc/frps:cp /源目录/usr/etc/frps
  5. 使用systemd配置开机自启(适用于 centos7 Ubuntu 16 或 debian 8)
     sudo vim /etc/systemd/system/frps.service 新建此文件,并写入以下内容

《frps.service》文档

[Unit]
Description=frps daemon
 
[Service]
Type=simple
ExecStart=/usr/etc/frps/frps -c /etc/frps/frps.ini
# /usr/etc/frps 文件目录,注意service文件中要指向frps运行程序(这个搞了半天才运行成功!!!)
# /etc/frps/frps.ini 配置目录
[Install]
WantedBy=multi-user.target

frps.service自启动

  1. vim编辑退出:Esc,# :wq(保存退出)
  2. 启动并设为开机自启。
sudo systemctl start frps
# (把start改为stop即终止frps)
sudo systemctl enable frps
systemctl status frp
# 查看frps状态

Centos6.5及以下版本frps自启动

  1. vi /etc/rc.local
  2. 在最下面加一行/usr/sbin/frp/frps -c /usr/sbin/frp/frps.ini
  3. 其中 /usr/sbin/frp是程序放置的目录,自己修改,重启ok

frps.service自启动进程查看

  1. 查看frp是否启动:ps aux | grep frps
  2. 查看frp启动状态
    sudo systemctl status frps

frps服务下的防火墙端口开启

  • 开启端口
firewall-cmd --permanent --add-port=xxxx/tcp # 开放bind_port(frps服务)# 必须
firewall-cmd --permanent --add-port=xxxx/tcp # 开放dashboard_port(服务面板http)# 必须
firewall-cmd --permanent --add-port=xxxx/tcp # 开放vhost_http_port(http端口)# 按需
firewall-cmd --permanent --add-port=xxxx/tcp # 开放vhost_http_port(https端口)# 按需
firewall-cmd --permanent --add-port=xxxx/tcp # 开放bind_udp_port端口(udp直连)# 按需
firewall-cmd --permanent --add-port=xxxx/tcp # 开放kcp_bind_port端口(kcp端口)# 按需
firewall-cmd --reload #重启防火墙(修改配置后要重启防火墙)
firewall-cmd --list-all # 查看防火墙规则
  • ssh端口开启(按需):公网服务器防火墙允许对应端口的流量通过,所以需要配置防火墙:
firewall-cmd --zone=public --add-port=10067/tcp --permanent
firewall-cmd --reload
  • 内网机器上面执行 tail -f nohup.out 查看启动命令的执行结果akerlu

NAS端安装FRPC

  1. 下载安装docker
  2. docker注册表,选用frpc 0.26.0版本(可自行选择容易下载的版本,但服务端frps必须对应同版本或者同大版本号的,如:0.34.1的话,可以用0.34.2)
  3. docker注册表下载后,在映像中可以看到。选择映像中的frpc进行启动编辑,启动编辑省略,可以参考github中的导航说明。
  4. 配置frpc.ini,本次基于frpc 0.26.0版本

《frpc.ini》文档

[common]
server_addr = xxx.xxx.xxx.xxx # 服务器地址
server_port = xxxx # 服务器端口
privilege_token = xxxxxx # token = xxxxxx 有些服务端版本采用这个字节,多数采用“privilege_token”字节,token理解为密码
protocol = tcp

[http]
type = http # http协议orhttps协议,如果两个都要的话就单独复制一段[https]
local_ip = 192.168.x.xx # 群晖的内网IP
local_port = xxxxx # 你自己的web服务器端口
custom_domains = xxxxxxx.xxx # 如果你有自己的域名,可以设置你自己的域名,先将自己的顶级域名解析到xxxxxxx.xxx(用CNAME记录,不要用A记录)
# subdomain = nas # 选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置

[ssh]
type = tcp
local_ip = 192.168.x.xxx
local_port = xxxxxx # 需要转发到的端口,ssh端口默认是22
remote_port = xxxxxx # frp服务端的远程监听端口,即你访问服务端的remote_port就相当于访问客户端的 local_port,如果填0则会随机分配一个端口

#[DSM]
# type = tcp # tcp协议
# local_ip = 192.168.x.xxx # 127.0.0.1指穿透本机,也可以填写群晖内网IP.
# local_port = xxxxxx # 群晖内网HTTP端口,默认为5000.
# remote_port = xxxx # 映射到外网端口,暴露给服务器,这个客户端必须唯一
# subdomain = nas # 选择一个可用的子域名,你的访问地址将会是http://nas.xxxxxx.xxx,服务器端必须已绑定顶级域名,否则不要设置