美文网首页
cassandra3节点集群安装

cassandra3节点集群安装

作者: 江南救世 | 来源:发表于2018-09-11 17:18 被阅读132次

    操作系统 centos 7
    1、安装java 8

    [root@ca ~]# java -version
    java version "1.8.0_111"
    Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
    

    2、安装python 2

    [root@ca ~]# python -V
    Python 2.7.5
    

    3、在/etc/hosts里面添加集群服务器信息

    192.168.1.74 harbor
    192.168.1.75 jenkins
    192.168.1.76 ca
    

    4、进行linux 系统内核 文件连接数的修改

    vi /etc/sysctl.conf
    
    vm.zone_reclaim_mode=0
    vm.max_map_count = 262144
    vm.swappiness = 1
    
    sysctl -p
    
    vi /etc/security/limits.conf
    * soft nofile 65536
    * hard nofile 65536
    * soft nproc 65536
    * hard nproc 65536
    
    

    5、创建cassandra用户名和数据存放目录

    useradd cassandra
    mkdir /opt/data1
    mkdir /opt/data2
    chmod 777 -R /opt/data1
    chmod 777 -R /opt/data2
    

    6、下载客户端

    cd /opt
    wget http://mirrors.hust.edu.cn/apache/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz
    tar xvf apache-cassandra-3.11.3-bin.tar.gz -C /opt
    mv /opt/apache-cassandra-3.11.3    /opt/cassandra
    chown -R cassandra.cassandra /opt/cassandra
    

    7、却换到cassandra用户下

    su - cassandra
    mkdir /opt/data1/commitlog
    mkdir /opt/data1/data1file
    mkdir /opt/data2/data2file
    mkdir /opt/data2/saved_caches
    
    cd /opt/cassandra/conf/
    修改 cassandra.yaml 配置文件,配置第一台为seeds。
    第一台配置:
    cluster_name: 'prod Cluster'
    data_file_directories:
         -  /opt/data1/data1file
         -  /opt/data2/data2file
    commitlog_directory: /opt/data1/commitlog
    saved_caches_directory: /opt/data2/saved_caches
    - seeds: "192.168.1.74"
    listen_address: 192.168.1.74
    start_rpc: true
    rpc_address: 192.168.1.74
    
    
    第二台配置:
    cluster_name: 'prod Cluster'
    data_file_directories:
         -  /opt/data1/data1file
         -  /opt/data2/data2file
    commitlog_directory: /opt/data1/commitlog
    saved_caches_directory: /opt/data2/saved_caches
    - seeds: "192.168.1.74"
    listen_address: 192.168.1.75
    start_rpc: true
    rpc_address: 192.168.1.75
    
    第三台配置:
    cluster_name: 'prod Cluster'
    data_file_directories:
         -  /opt/data1/data1file
         -  /opt/data2/data2file
    commitlog_directory: /opt/data1/commitlog
    saved_caches_directory: /opt/data2/saved_caches
    - seeds: "192.168.1.74"
    listen_address: 192.168.1.76
    start_rpc: true
    rpc_address: 192.168.1.76
    
    
    然后重启启动,先启动seed
    /opt/cassandra/bin/cassandra
    
    启动完成后,可使用
    /opt/cassandra/bin/nodetool status
    查看集群状态
    [cassandra@harbor conf]$ /opt/cassandra/bin/nodetool status
    Datacenter: datacenter1
    =======================
    Status=Up/Down
    |/ State=Normal/Leaving/Joining/Moving
    --  Address       Load       Tokens       Owns (effective)  Host ID                               Rack
    UN  192.168.1.74  189.2 KiB  256          68.9%             98436d32-5d5d-4e5e-afe2-84550e56daa9  rack1
    UN  192.168.1.75  161.43 KiB  256          64.7%             2f52f14c-acbb-4241-9eff-6ed13b2827e5  rack1
    UN  192.168.1.76  120.67 KiB  256          66.4%             450b02db-90a1-4b76-831a-9b0b9aa42c27  rack1
    
    

    8、如果节点的集群名字和seeds节点的集群名字不一样的,则启动会报错

    ERROR [main] 2018-03-20 17:49:20,497 CassandraDaemon.java:708 - Exception encountered during startup
    java.lang.RuntimeException: Unable to gossip with any seeds
    

    如果配置文件修改成一致的集群名字后,再启动会出现

    已经启动过的node,如果改了配置的clustername,再启动就会报错
    
    org.apache.cassandra.exceptions.ConfigurationException: Saved cluster name Test Cluster != configured name xxx
    
    这是因为已经写到系统表里了。改名字相当于换集群
    因为理论上换了集群老数据就没用了,所以直接rm -rf /data/cassandra之类的数据目录,包括data, commitlog。删干净了再启动即可
    

    9、cqlsh操作

    [cassandra@harbor bin]$ ./cqlsh 192.168.1.74
    Connected to prod Cluster at 192.168.1.74:9042.
    [cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
    Use HELP for help.
    cqlsh> 
    

    10、停止

    pkill -f CassandraDaemon
    

    相关文章

      网友评论

          本文标题:cassandra3节点集群安装

          本文链接:https://www.haomeiwen.com/subject/nabugftx.html