商城网站具体需求,免费产品推广网站,作文生成器,中国商业网点建设中心linux服务器安装zookeeper本地项目远程连接
zookeeper linux 服务器安装#xff0c;本地idea连接
先决条件#xff1a;一台linux服务器#xff0c;服务器里面已经安装好java环境#xff08;安装Java看这里#xff1a;https://blog.csdn.net/qq_43842093/article/details…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项目引入依赖
dependencies!-- SpringBoot整合Web组件 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- SpringBoot整合zookeeper客户端 --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-zookeeper-discovery/artifactId!--先排除自带的zookeeper3.5.3--exclusionsexclusiongroupIdorg.apache.zookeeper/groupIdartifactIdzookeeper/artifactId/exclusion/exclusions/dependency!--添加zookeeper3.4.9版本--dependencygroupIdorg.apache.zookeeper/groupIdartifactIdzookeeper/artifactIdversion3.5.8/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency
/dependencies建application.yml文件
#8004表示注册到zookeeper服务器的服务提供者端口号
server:port: 8004
#服务别名----注册zookeeper到注册中心名称
spring:application:name: cloud-zookeeper-democloud: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);}
}启动不报错访问后的结果