一、zookeeper
cd /etc/rc.d/init.d/
touch zookeeper
chmod +x zookeeper
vi zookeeper#以下为内容,自行修改 路径#!/bin/bash
##chkconfig:2345 10 90#description:service zookeeper
#修改为自己的目录
export ZOO_LOG_DIR=/data/apache-zookeeper-3.7.0/logs
ZOOKEEPER_HOME=/data/apache-zookeeper-3.7.0/
case "$1" instart) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start;;start-foreground) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh start-foreground;;stop) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh stop;;status) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh status;;restart) su root ${ZOOKEEPER_HOME}/bin/zkServer.sh restart;;upgrade)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh upgrade;;print-cmd)su root ${ZOOKEEPER_HOME}/bin/zkServer.sh print-cmd;;*) echo "requirestart|start-foreground|stop|status|restart|print-cmd";;
esacservice zookeeper start/stop#加入启动,以下二选一执行
chkconfig --add zookeeper
chkconfig zookeeper on#查看启动
chkconfig --list
二、redis
cd /etc/rc.d/init.d/
vi redis#以下为内容,自行修改 路径#!/bin/bash
#chkconfig: 2345 10 90
#description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/data/redis-7.0.4/src/redis-server #对应你自己的配置地址
REDIS_CLI=/data/redis-7.0.4/src/redis-cli #对应你自己的配置地址
PIDFILE=/var/run/redis.pid
CONF="/data/redis-7.0.4/redis.conf" #对应你自己的配置地址
AUTH="Ecan@8722."
case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed." elseecho "Starting Redis server..." $EXEC $CONFfiif [ "$?"="0" ]thenecho "Redis is running..." fi;;stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE exists, process is not running." elsePID=$(cat $PIDFILE)echo "Stopping..." $REDIS_CLI -p $REDISPORT SHUTDOWNsleep 2while [ -x $PIDFILE ] doecho "Waiting for Redis to shutdown..." sleep 1doneecho "Redis stopped" fi;;restart|force-reload)${0} stop${0} start;;*)echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2exit 1
esacchmod +x redis
chkconfig --add redis
chkconfig redis onchkconfig --list
三、rabbitmq
systemctl enable rabbitmq-server
四、activemq
cd /etc/rc.d/init.d/
vi activemq#!/bin/sh
#
# /etc/init.d/activemq
# chkconfig: 345 63 37
# description: activemq servlet container.
# processname: activemq 5.15.2# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/networkexport ACTIVEMQ_HOME=/data/apache-activemq-5.15.0case "$1" instart)sh $ACTIVEMQ_HOME/bin/activemq start;;stop)sh $ACTIVEMQ_HOME/bin/activemq stop;;status)sh $ACTIVEMQ_HOME/bin/activemq status;;restart)sh $ACTIVEMQ_HOME/bin/activemq stopsleep 1sh $ACTIVEMQ_HOME/bin/activemq start;;esac
exit 0chmod 755 activemq
#加入启动,以下二选一执行
chkconfig --add activemq
chkconfig activemq on#查看启动
chkconfig --list
五、开机启动java应用
#进入目录
cd /usr/lib/systemd/system#新建服务 news-app 改为自己应用的名字
vi news-app.service#以下为内容
#!/bin/sh
[Unit]
Description=news-app #改为你自己的应用名字
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/data/news-app/startup.sh #改为你自己的启动脚本
ExecStop=/data/news-app/startup.sh #改为你自己的启动脚本
PrivateTmp=true
[Install]
WantedBy=multi-user.target#文件内容结束,权限授权chmod +x news-app.service
#重新加载服务
systemctl daemon-reload
#启动服务器
systemctl start news-app
#查看服务状态
systemctl status news-app
#开启启动服务
systemctl enable news-app
startup.sh 给大家提供一个springboot的启动脚本,以下脚本每次执行会自动关闭程序并启动程序,避免手动关闭应用的麻烦。
请自行修改所有 news-app 的地方,java 附带参数自行修改,这里涵盖了dubbo。
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
arr=`ps -ef | grep news-app-v1.0.0 | grep -v grep | awk '{print $2}'`
echo get pid: ${arr}
for i in ${arr[@]};do
echo kill pid ${i}...
kill -9 ${i}
done;
echo kill finished!
cd ${basepath}
echo start application
nohup java -Xmx250M -Xms250M -Ddubbo.network.interface.preferred=eth0 -Ddubbo.provider.telnet=cd,clear,count,pwd,exit,invoke,log,ps,select,shutdown,status,trace,help,ls -jar -Dfile.encoding=UTF-8 -Dloader.path=${basepath}/lib,${basepath}/config ${basepath}/news-app-v1.0.0.jar.original >/dev/null 2>&1 &
echo start end...