本地demo服务器搭建计划——(二)服务中心consul安装&防火墙配置

安装consul

1、安装consul
直接yum安装,或者官网获取安装包
https://developer.hashicorp.com/consul/downloads

 sudo yum install -y yum-utils
 # 如果已经安装了yum-utils,可以跳过第一个
 sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
 sudo yum -y install consul

安装好之后直接启动

nohup consul agent -dev -client 0.0.0.0 -ui &

-dev : 以dev模式启动(单节点)
-client : 指定客户端地址,全零放通
-ui :启动ui页面,默认端口8500,需要放通防火墙访问

关闭防火墙服务

以CentOS7为例,CentOS7之前使用iptables,CentOS7使用firewalld

简单粗暴

# 查看防火墙状态
systemctl status firewalld
firewall-cmd --state
# 简单粗暴
systemctl stop firewalld
# 禁止开机自启
systemctl disable firewalld

端口放行

# 查看zone,默认启动public。firewalld命令有很多,简单列几个常用的,有兴趣自己研究不展开
firewall-cmd --list-all-zones
firewall-cmd --get-default-zone
# 查看已放行的端口
firewall-cmd --list-ports [--permanent]
--permanent 永久生效,重启后不失效
# 放行端口
firewall-cmd --add-port=8500/tcp [--permanent]
# 删除放行
firewall-cmd --remove-port=8500/tcp [--permanent]

配置端口放行后,需要重启firewalld服务

systemctl restart firewalld

添加链接描述

放行端口后就可以访问consul的控制台了

consul控制台 : http://YOUR_HOST_IP:8500
比较完整的配置参考这篇blog https://blog.51cto.com/u_15069485/2611956

启动consul集群

nohup后台启动

以server模式启动consul集群建议至少三个节点。你可以安装三个虚拟机

# -bootstrap-except 集群最少的server数量,少于这个数量报错
# -node 节点名换成呢个
# -bind 节点的地址
nohup consul agent -server -bootstrap-except 2 -data-dir=/demo/consul/data -node=node1 -bind=10.0.0.1 >/dev/null &
nohup consul agent -server -bootstrap-except 2 -data-dir=/demo/consul/data -node=node2 -bind=10.0.0.2 >/dev/null &
nohup consul agent -server -bootstrap-except 2 -data-dir=/demo/consul/data -node=node3 -bind=10.0.0.3 >/dev/null &
# 在server2 server3中将当前节点加入集群
consul join 10.0.0.1
# 查看集群成员
consul members

docker 启动

参考这篇blog https://www.cnblogs.com/woxpp/p/11849002.html
dockerhub https://hub.docker.com/_/consul

# server模式启动
$ docker run -d --net=host -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' \
consul agent -server -bind=<external ip> -retry-join=<root agent ip> -bootstrap-expect=<number of server agents>

其他

rsyslogd配置详解(服务日志) http://c.biancheng.net/view/1102.html
logrotate配置详解(日志转储)http://c.biancheng.net/view/1106.html

猜你喜欢

转载自blog.csdn.net/q863672107/article/details/127952425
今日推荐