zookeeper安装一:单机安装

    xiaoxiao2021-04-15  327

    实验环境:

    1. centos7.6最小化安装 2. jdk1.8 3. zookeeper-3.4.14

    1. 安装jdk环境(略)

    2. 下载zookeeper

    3. 将下载好的压缩包上传到linux目录 /soft中

    4. 解压这个压缩包

    [root@localhost soft]# tar -zxvf zookeeper-3.4.14.tar.gz

    5. 进入压缩包,拷贝生成新的配置文件

    [root@localhost zookeeper-3.4.14]# cp conf/zoo_sample.cfg conf/zoo.cfg

    6. 修改配置文件 zoo.cfg配置

    将dataDir修改为/soft/zookeeper-3.4.14/dataDir

    7. 创建dataDir目录

    [root@localhost zookeeper-3.4.14]# mkdir /soft/zookeeper-3.4.14/dataDir

    8. 启动Server

    [root@localhost zookeeper-3.4.14]# cd /soft/zookeeper-3.4.14/bin [root@localhost bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /soft/zookeeper-3.4.14/bin/…/conf/zoo.cfg Starting zookeeper … STARTED

    9. 启动客户端连接这个Server

    [root@localhost bin]# ./zkCli.sh Connecting to localhost:2181 … Welcome to ZooKeeper! … WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] 看到这里说明成功的连接到了服务端

    10. 使用命令行测试zookeeper服务端

    10.1 列举出"/"节点下的结构

    [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper]

    10.2 创建节点"/zkdemo"并绑定数据

    [zk: localhost:2181(CONNECTED) 1] create /zkdemo "this is a demo" Created /zkdemo

    10.3 再次列举出"/"节点下的结构

    [zk: localhost:2181(CONNECTED) 2] ls / [zookeeper, zkdemo]

    10.4 获取节点"/zkdemo"下绑定的字符串

    [zk: localhost:2181(CONNECTED) 3] get /zkdemo this is a demo cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x2 mtime = Tue May 21 23:17:38 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 14 numChildren = 0

    10.5 修改节点"/zkdemo"下绑定的字符串

    [zk: localhost:2181(CONNECTED) 4] set /zkdemo "another" cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x3 mtime = Tue May 21 23:21:43 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0

    10.6 再次获取节点"/zkdemo"下的绑定字符串

    [zk: localhost:2181(CONNECTED) 5] get /zkdemo another cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x3 mtime = Tue May 21 23:21:43 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0

    10.7 删除节点"/zkdemo"

    [zk: localhost:2181(CONNECTED) 6] delete /zkdemo [zk: localhost:2181(CONNECTED) 7] ls / [zookeeper]

    10.8 退出客户端

    [zk: localhost:2181(CONNECTED) 8] quit Quitting… 2019-05-21 23:27:21,823 [myid:] - INFO [main:ZooKeeper@693] - Session: 0x1000025f0f80000 closed 2019-05-21 23:27:21,829 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@522] - EventThread shut down for session: 0x1000025f0f80000

    11 关闭Server端

    [root@localhost bin]# ./zkServer.sh stop ZooKeeper JMX enabled by default Using config: /soft/zookeeper-3.4.14/bin/…/conf/zoo.cfg Stopping zookeeper … STOPPED 其他:上面启动zkServer是后台执行的方式,如果想前台启动的话使用命令: [root@localhost bin]# ./zkServer.sh start-foreground


    最新回复(0)