ssh reverse proxy Raspberry Pi + motion, realizing public network by remote video surveillance

Note: This article is part of the public network remote monitoring needs the cloud server has a public IP were ssh reverse proxy.

First, by means of video surveillance within the network to achieve motion

  • ready
    • Plug camera, and then enter the ls /dev/video*command to check whether the identified camera
  • Installing motion
    • motion linux is open source, raspberries come in use in sudo apt-get install motionorder to install, easy to install.
  • Modify motion configuration
    • Common configuration and meaning
    # Start in daemon (background) mode and release terminal (default: off)
    # 在后台运行。设置为off将在前台运行
    daemon on
    # Videodevice to be used for capturing  (default /dev/video0)
    # for FreeBSD default is /dev/bktr0
    # 视频设备,刚才ls /dev/video*看到的
    videodevice /dev/video0
    # Image width (pixels). Valid range: Camera dependent, default: 352
    # 图像宽
    width 320
    # Image height (pixels). Valid range: Camera dependent, default: 288
    # 图像高
    height 240
    # The setting for keep-alive of network socket, should improve performance on compatible net cameras.
    # off: The historical implementation using HTTP/1.0, closing the socket after each http request.
    # force: Use HTTP/1.0 requests with keep alive header to reuse the same connection.
    # on: Use HTTP/1.1 requests that support keep alive as default.
    # Default: off
    # 开启KeepAlive功能
    netcam_keepalive on
    # Output 'normal' pictures when motion is detected (default: on)
    # Valid values: on, off, first, best, center
    # When set to 'first', only the first picture of an event is saved.
    # Picture with most motion of an event is saved when set to 'best'.
    # Picture with motion nearest center of picture is saved when set to 'center'.
    # Can be used as preview shot for the corresponding movie.
    # 禁用自动拍照保存的功能
    output_pictures off
    # Use ffmpeg to encode movies in realtime (default: off)
    # 禁用自动拍摄视频保存的功能
    ffmpeg_output_movies off
    # The mini-http server listens to this port for requests (default: 0 = disabled)
    # 视频监听的端口,默认8081
    stream_port 1001
    # Quality of the jpeg (in percent) images produced (default: 50)
    # 图像质量
    stream_quality 50
    # Output frames at 1 fps when no motion is detected and increase to the
    # rate given by stream_maxrate when motion is detected (default: off)
    stream_motion on
    # Maximum framerate for stream streams (default: 1)
    # 帧数8,需要先把上面的选项改成on
    stream_maxrate 8
    # Set the authentication method (default: 0)
    # 0 = disabled
    # 1 = Basic authentication
    # 2 = MD5 digest (the safer authentication)
    # 改成1,增加授权验证,访问需要输入密码
    stream_auth_method 1
    # Authentication for the stream. Syntax username:password
    # Default: not defined (Disabled)
    # 设置用户名username和密码password
    stream_authentication username:password
    # Restrict stream connections to localhost only (default: on)
    # 改成off允许外网访问视频
    stream_localhost off
    # TCP/IP port for the http server to listen on (default: 0 = disabled)
    # WEB控制台监听的端口,默认8080
    webcontrol_port 1000
    # 改成off允许外网访问web控制台
    webcontrol_localhost off
    
    • Must be modified daemon onare: webcontrol_localhost off, . The default configuration may have significant Caton, then adjust their own parameters. Finally, the effect can be very smooth.
    • Use sudo motioncommand to enable motion
    • Use sudo killall -TERM motioncan turn off the motion
  • test
    • sudo motionAfter input in the browser ip:你设定的端口号(默认8081)to view real-time monitoring. Such as: 192.168.137.30: 8081.
    • Note: At this point only the internal network access.

Second, to achieve the public network remote video monitoring via ssh reverse proxy Raspberry Pi

  • Raspberries come in
    • ssh -CqTfnN -R 0.0.0.0:12345:localhost:8081 ubuntu@yourserver(Test.server cloud server is a domain name or ip)
    • This connection is established yourserver 12345 a local port to the port 8081 of pi, after yourserver can use this communication port and a pi.
  • On the server
    • ssh -fCNL "*:12345:localhost:12346" ubuntu@yourserver
    • 12346 listens to build a port other client's request, when the 12346 port receives data when the data is transferred to port 12345, then 12345 ports that connect to port 8081 Raspberry Pi to achieve a "proxy" effect. When a browser to access the cloud server port 12346, the equivalent access port 8081 Raspberry Pi, enabling real-time monitoring public network.
    • This method of using the ssh reverse proxy can also achieve the public network remote control Raspberry Pi.
  • test
    • After Raspberry Pi open motion, entered in the browser 服务器ip:服务器设置的监听端口(本例为12346)to see motion video.
    • Note: Due to the speed limit, the video may Caton. At this point modify motion configuration, reduce the size, frame rate, image quality, etc. can be eliminated Caton.
Published 10 original articles · won praise 10 · views 9087

Guess you like

Origin blog.csdn.net/nick_young_qu/article/details/105365707