配置防火墙
修改/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 //重启