rinetd安装
1、更新yum
yum -y update
2、安装依赖
yum install -y gcc
3、下载安装包至/opt/soft
cd /opt/soft wget http://www.rinetd.com/download/rinetd.tar.gz
若官网下载方式被拦截,则也可以在我的百度网盘上下载:https://pan.baidu.com/s/1KaTbLvypXT-sad3Q0Iq0Hw 提取码:7uxq
4、创建目录
mkdir -p /opt/module
5、解压安装包至/opt/module
cd /opt/soft
tar -zxvf rinetd.tar.gz -C /opt/module
6、创建目录
mkdir -p /data/logs/rinetd
mkdir -p /usr/man
7、编译
cd /opt/module/rinetd
sed -i 's/65536/65535/g' rinetd.c
make && make install
8、创建rinetd配置文件
touch /etc/rinetd.conf
9、指定日志文件位置及配置端口转发
echo "logfile /data/logs/rinetd/rinetd.log" > /etc/rinetd.conf
echo "192.168.67.1 3306 10.67.251.1 3306" >> /etc/rinetd.conf
10、启动
/opt/module/rinetd/rinetd -c /etc/rinetd.conf
11、停止
ps -ef | grep /opt/module/rinetd/rinetd | grep -v grep | awk '{print $2}' | xargs kill
12、重启
ps -ef | grep /opt/module/rinetd/rinetd | grep -v grep | awk '{print $2}' | xargs kill
/opt/module/rinetd/rinetd -c /etc/rinetd.conf
13、查看是否启动:
ps -ef | grep /opt/module/rinetd/rinetd | grep -v grep
14、使用systemd管理rinetd服务
(1)创建rinetd服务
vi /etc/systemd/system/rinetd.service
[Unit] Description=rinetd After=network.target [Service] Type=forking ExecStart=/opt/module/rinetd/rinetd -c /etc/rinetd.conf [Install] WantedBy=multi-user.target
(2)刷新配置
systemctl daemon-reload
(3)启动rinetd
systemctl start rinetd
(4)停止rinetd
systemctl stop rinetd
(5)重启rinetd
systemctl restart rinetd
(6)设置开机启动rinetd
systemctl enable rinetd
(7)查看rinetd状态
systemctl status rinetd
15、配置Rinetd挂掉自动拉起
(1)创建文件夹
mkdir -p /opt/module/shell
(2)创建脚本
vim /opt/module/shell/rinetd.sh
#!/bin/bash pid=`ps -ef | grep /opt/module/rinetd/rinetd | grep -v grep` #echo "pid=$pid" if [ "$pid" != "" ];then echo "$(date "+%Y-%m-%d %H:%M:%S"),rinetd进程还存在,无需启动" else echo "$(date "+%Y-%m-%d %H:%M:%S"),重启rinetd" systemctl restart rinetd fi
(3)赋予权限
chmod +x /opt/module/shell/rinetd.sh
(4)定时执行(五分钟执行一次)
vim /etc/crontab
#添加如下内容
*/5 * * * * root /opt/module/shell/rinetd.sh