使用ORAY蒲公英异地组网实现树莓派异地SSH访问

一、树莓派设置蒲公英进行外网访问

1.1 树莓派安装蒲公英客户端

PgyVPN_Raspbian_2.2.1_armhf_systemd.deb.txt

1.2 创建启动蒲公英服务脚本

  1. #!/bin/sh
  2. #/etc/init.d/pgyvpnservice.sh
  3. ### BEGIN INIT INFO
  4. # Provides:testboot
  5. # Required-Start:$remote_fs $syslog
  6. # Required-Stop:$remote_fs $syslog
  7. # Default-Start:2 3 4 5
  8. # Default-Stop:0 1 6
  9. # Short-Description: testboot
  10. # Description: This service is used to start my applaction
  11. ### END INIT INFO
  12. case "$1" in
  13. start)
  14. echo "启动蒲公英异地组网"
  15. su root -c "pgyvpn" # 以root模式执行pgyvpn指令打开蒲公英
  16. ;;
  17. stop)
  18. echo "执行完毕"
  19. ;;
  20. esac

五、其他

5.1 创建网络检测脚本

  1. #!/bin/bash
  2. #检测网络链接&&ftp上传数据
  3. declare -i n=0 #创建变量n并声明为数值
  4. while [ $n -ne 1 ] #判断n是否不等于1
  5. do
  6. ret_code=`curl -I -s --connect-timeout 5 baidu.com -w %{http_code} | tail -n1` #网络值
  7. if [ "$ret_code" = "200" ]; then
  8. nohup /home/pi/Desktop/pgyvpnservice.sh & #网络连接成功后需要启动的程序脚本,即pgyvpnservice.sh
  9. n=1;
  10. else
  11. n=0; #失败等待
  12. fi
  13. done