【运维、Consul】Consul在CentOS7下后台启动和自启动配置

安装

1.下载Consul

[root@localhost 20190903]

wget https://releases.hashicorp.com/consul/0.9.3/consul_0.9.3_linux_amd64.zip

2.解压

[root@localhost 20190903]# unzip consul_0.9.3_linux_amd64.zip

3.验证是否安装consul成功

[root@localhost consul]# ./consul

出现如图所是则表示安装成功。

3.启动consul

-dev表示开发模式运行,另外还有-server表示服务模式运行

[root@localhost consul]# ./consul agent –dev

4.远程访问

[root@localhost consul]# ./consul agent -dev -client 192.168.126.139

在浏览器 输入:http://192.168.126.139:8500/ui/

开机自动重启配置

1.在/etc/init.d/目录下创建consul

[root@localhost consul]# cd  /etc/init.d/

[root@localhost init.d]#vi  consul

Consul内容如下图所示:

具体脚本如下图所示:

#!/bin/sh

#chkconfig: - 85 15

#description: consul service

#author: fab

export JAVA_HOME=/usr/java/jdk1.8.0_211

export JAVA_BIN=/usr/java/jdk1.8.0_211/bin

export PATH=$PATH:$JAVA_HOME/bin

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in

start)

cd /usr/local/consul

./consul agent -dev -client=192.168.126.139

!

echo "consul startup"

;;

stop)

es_pid=`ps aux|grep consul | grep -v 'grep consul' | awk '{print $2}'`

kill -9 $es_pid

echo "consul stopped"

;;

restart)

es_pid=`ps aux|grep consul | grep -v 'grep consul' | awk '{print $2}'`

kill -9 $es_pid

echo "consul stopped"

cd /usr/local/consul

./consul agent -dev -client=192.168.126.139

!

echo "consul startup"

;;

*)

echo "start|stop|restart"

;;

esac

exit $?

2.修改consul可执行权限

[root@localhost init.d]# chmod +x consul

3.添加consul到系统服务中

[root@localhost init.d]# chkconfig --add consul

4.设置consul服务为开机启动

[root@localhost init.d]# chkconfig consul on

5.开机启动测试

[root@localhost init.d]# reboot

[root@localhost init.d]# ps -elf|grep consul

4 S root       3405      1  0  80   0 -  9667 futex_ 14:22 ?        00:00:02 ./consul agent -dev -client=192.168.126.139

0 S root       3824   3089  0  80   0 - 28182 pipe_w 14:28 pts/0    00:00:00 grep --color=auto consul

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值