Linux端口轉發-rinted工具部署、配置、使用

編者按:mysql


    近期因爲公司開啓定製項目規劃,對於每一個項目都會開啓一個測試服務器,實施方會用到測試服務器的ssh端口、mysql端口、web端口,爲了節省資源(公網IP、服務器資源複用),基於rinted工具搭建一個端口轉發的服務器。下面的流程圖將更好的表達本文即將實現的功能!
web

rinted端口轉發示意圖.jpg


一、源碼安裝rinted:
sql

    下載和解壓源碼包:
shell

cd /usr/local/src && wget https://boutell.com/rinetd/http/rinetd.tar.gz && tar xf rinetd.tar.gz && cd rinetd

    修改編譯配置:c#

sed -i 's/65536/65535/g' rinetd.c# 修改端口範圍,不然會報錯

    編譯安裝:bash

mkdir -p /usr/man/man8 && make && make install

    編輯配置文件:/etc/rinetd.conf
服務器

#自定義mysql端口:3001/3100
#自定義ssh端口:2001/2500
#自定義web端口:801/899
#端口轉發:[Source Address] [Source Port] [Destination Address] [Destination Port]
0.0.0.0 8080 10.124.162.114 8080
0.0.0.0 443 10.124.162.114 8080
0.0.0.0 3001 10.124.162.114 33080
#端口映射: bindaddress bindport connectaddress connectport

logfile /var/log/rinetd.log

    啓動與關閉:
ssh

#啓動
/usr/sbin/rinetd -c /etc/rinetd.conf 
#關閉
pkill rinetd

   啓動腳本:/home/shell/rinetd  使用方法:sh /home/shell/rinetd start|stop|restart|reloadide

#!/bin/bash
#
# Startup script for Rinetd - this script starts and stops the rinetd daemon
#
# chkconfig: - 85 15
# description: Rinetd is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: rinetd
# config: /etc/rinetd.conf
# pidfile: /var/lock/subsys/rinetd
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
rinetd="/usr/sbin/rinetd"
prog=$(basename $rinetd)
 
RINETD_CONF_FILE="/etc/rinetd.conf"
 
#[ -f /etc/sysconfig/rinetd ] && . /etc/sysconfig/rinetd
 
lockfile=/var/lock/subsys/rinetd
 
start() {
    [ -x $rinetd ] || exit 5
    [ -f $RINETD_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $rinetd -c $RINETD_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    #killproc $rinetd -HUP
    daemon pkill $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    sleep 1
    start
}
 
reload() {
    echo -n $"Reloading $prog: "
    killproc $rinetd -HUP
    RETVAL=$?
    echo
}
 
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|reload}"
        exit 2
esac
相關文章
相關標籤/搜索