安装
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