Linux: 其他服务
- TAGS: Linux
shell版HTTP服务
比较老的方案就是 xinetd. 现在已被systemd代替。
xinetd 是 Linux 的守护进程,全称为 extended interent daemon,扩展的网络守护进程
xinetd 可以打开一个端口,等待连接,你可以告诉 xinetd 运行哪个脚本,当有连接进来后,xinetd 便会执行脚本,然后直接返回脚本输出的内容
1.安装xinetd服务
yum install xinetd -y
2.编写 xinetd 服务
服务名为hd-rds,文件名 /etc/xinetd.d/change-rds
cat <<\EOF> /etc/xinetd.d/change-rds
service hd-rds
{
disable = no
port = 9990
socket_type = stream
protocol = tcp
wait = no
user = root
server = /root/test.sh
server_args = test
}
EOF
说明:
- port 指定监听的端口
- server 指定要执行的脚本
脚本内容
cat <<\EOF> test.sh
#!/bin/bash
echo Welcome.
EOF
chmod +x 给脚本添加可执行权限
3.加入服务列表
修改 /etc/services
#找到定义端口的位置,注释掉原有的,添加要修改的服务 #osm-appsrvr 9990/tcp # OSM Applet Server hd-rds 9990/tcp
- 测试
分别用 nc 和 telnet 两个命令测试一下
nc localhost 9990 telnet localhost 9990