redhat添加服务

配置防火墙
修改/etc/sysconfig/iptables
内容为:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20502 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
此配置文件可以防ping,对外开放22和20502端口(工时系统服务器的端口)
用root用户重启防火墙服务
#service iptables restart

1.在 /etc/init.d/ 下创建文件gongshiserver,内容如下:

#!/bin/bash
# chkconfig: 2345 30 30
# description: gongshiserver

if [ $UID = 500 -o $UID = 0 ]; then
        case "$1" in
                'start')
                        echo "Starting gongshiserver ..."

                        if [ $UID = 0 ]; then

                                su - gongshi -c "cd /home/gongshi/server1450;./server&" 1>>/home/gongshi/gongshi.log 2>>/home/gongshi/gongshierr.log
                        else
                                cd /home/gongshi/server1450;source /home/gongshi/.bash_profile;./server 1>>/home/gongshi/gongshi.log 2>>/home/gongshi/gongshierr.log&

                        fi
                        echo "Done"
                 ;;


                'stop')
                        killall -9 server
                        echo "gongshiserver is stoped"
                 ;;


                'restart')
                        $0 stop
                        $0 start
                ;;
        esac
else
        echo "insufficient privileges to operate"
fi

#注意脚本的第二三行必须要有,而且编号不能离谱,比如30可以,但是200不可以,2345代表运行级别


2.改变文件权限
# chmod 755 /etc/init.d/gongshiserver

3.添加服务
# chkconfig --add gongshiserver

4. 使用方法
# service gongshiserver start    //启动
# service gongshiserver stop    //关闭
# service gongshiserver restart //重启

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值