linux服务器安装zookeeper本地项目远程连接 | 您所在的位置:网站首页 › linux如何开启远程访问 › linux服务器安装zookeeper本地项目远程连接 |
linux服务器安装zookeeper本地项目远程连接
zookeeper linux 服务器安装,本地idea连接 先决条件:一台linux服务器,服务器里面已经安装好java环境(安装Java看这里:https://blog.csdn.net/qq_43842093/article/details/116380855) mkdir zookeeper #创建文件夹 cd zookeeper #进入文件夹 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.8/apache-zookeeper-3.5.8-bin.tar.gz #下载zookeeper,这个是编译后的二进制包 tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz #解压安装包 cd apache-zookeper-3.5.8-bin #进入解压后的文件夹 cd conf #进入配置文件夹 cp zoo_sample.cfg zoo.cfg #复制配置文件zoo_sample.cfg并命名为zoo.cfg vi zoo.cfg #编辑配置文件 s编辑,esc + :wq保存退出 vi /etc/profile #配置系统环境变量 #加上下面内容 路径根据实际情况修改 export ZOOKEEPER_HOME=/usr/zookeeper/apache-zookeeper-3.5.7-bin/ PATH=$ZOOKEEPER_HOME/bin:$PATH source /etc/profile #让刚刚添加的配置生效 #切换到bin目录 cd .. cd bin ./zkServer.sh start #启动服务 ./zkServer.sh status #查看状态 ./zkServer.sh stop #关闭服务 tail 日志文件名称 #查看日志(存放在logs目录) ./zkCli.sh #打开客户端zookeeper服务就搭建好了 在阿里云控制台把2181端口放开,配置安全组规则 准备就绪,实现代码 新建maven项目,引入依赖 org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-zookeeper-discovery org.apache.zookeeper zookeeper org.apache.zookeeper zookeeper 3.5.8 org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test建application.yml文件 #8004表示注册到zookeeper服务器的服务提供者端口号 server: port: 8004 #服务别名----注册zookeeper到注册中心名称 spring: application: name: cloud-zookeeper-demo cloud: zookeeper: connect-string: 阿里云公网IP:2181controller层 @RestController public class PaymentController { @Value("${server.port}") private String serverPort; @RequestMapping(value = "/payment/zk") public String paymentZk(){ return "springcloud with zookeeper: "+serverPort+"\t"+ UUID.randomUUID().toString(); } }启动类 @SpringBootApplication @EnableDiscoveryClient //该注解用于向使用consul或者zookeeper作为注册中心时注册服务 public class PaymentMain8004 { public static void main(String[] args) { SpringApplication.run(PaymentMain8004.class,args); } }启动不报错,访问后的结果 |
CopyRight 2018-2019 实验室设备网 版权所有 |