先去官网找到下载地址
https://cassandra.apache.org/download/
文档:
https://cassandra.apache.org/doc/3.11.10/getting_started/installing.html
-
用户root-安装openjdk
https://blog.csdn.net/mnbwz/article/details/113796063
-
用户root-安装thrift-远程连接依赖此包(cassandra4.0以上的话就不用装了)
[root@centos1 ~]# yum list|grep thrift
libthrift-java.noarch 0.9.1-15.el7 epel
libthrift-javadoc.noarch 0.9.1-15.el7 epel
perl-thrift.noarch 0.9.1-15.el7 epel
python-thrift.x86_64 0.9.1-15.el7 epel
thrift.x86_64 0.9.1-15.el7 epel
thrift-devel.x86_64 0.9.1-15.el7 epel
thrift-glib.x86_64 0.9.1-15.el7 epel
thrift-qt.x86_64 0.9.1-15.el7 epel
[root@centos1 ~]# yum install thrift.x86_64
[root@centos1 ~]#
-
用户db02-配置jdk环境变量
vi .bash_profile
。。。。。。
export JAVA_HOME=/root/bwz/jdk/openjdk-8u262-b10
export PATH=.:$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib
。。。。。。
[db02@centos1 ~]$ . .bash_profile
[db02@centos1 ~]$ java -version
openjdk version "1.8.0-262"
OpenJDK Runtime Environment (build 1.8.0-262-b10)
OpenJDK 64-Bit Server VM (build 25.71-b10, mixed mode)
[db02@centos1 ~]$
-
用户db02-安装cassandra3.11.10
[db02@centos1 ~]$ pwd
/home/db02
[db02@centos1 ~]$ ll
总用量 0
[db02@centos1 ~]$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/cassandra/3.11.10/apache-cassandra-3.11.10-bin.tar.gz
[db02@centos1 ~]$ tar -xzvf apache-cassandra-3.11.10-bin.tar.gz
[db02@centos1 ~]$ ll
总用量 37392
drwxrwxr-x. 10 db02 db02 208 2月 11 02:21 apache-cassandra-3.11.10
-rw-rw-r--. 1 db02 db02 38289255 1月 29 20:37 apache-cassandra-3.11.10-bin.tar.gz
[db02@centos1 ~]$ vi .bash_profile
。。。。。。
export CASSANDRA_HOME=~/apache-cassandra-3.11.10
export PATH=$PATH:$CASSANDRA_HOME/bin
。。。。。。
[db02@centos1 ~]$ . .bash_profile
[db02@centos1 ~]$ echo $CASSANDRA_HOME
/home/db02/apache-cassandra-3.11.10
[db02@centos1 ~]$
-
用户db02-cassandra启动、停止、查看状态
Start Cassandra in the foreground by invoking bin/cassandra -f from the command line. Press “Control-C” to stop Cassandra.
Start Cassandra in the background by invoking bin/cassandra from the command line. Invoke kill pid or pkill -f CassandraDaemon to stop Cassandra, where pid is the Cassandra process id, which you can find for example by invoking pgrep -f CassandraDaemon.
Verify that Cassandra is running by invoking bin/nodetool status from the command line.
-
用户db02-cassandra启动告警
[db02@centos1 logs]$ pwd
/home/db02/apache-cassandra-3.11.10/logs
[db02@centos1 logs]$ cat system.log |grep -v INFO
#硬盘太小
WARN [main] 2021-02-11 03:27:36,892 DatabaseDescriptor.java:579 - Only 55.370GiB free across all data volumes. Consider adding more capacity to your cluster or removing obsolete snapshots
#修改ulimit -a|grep 'max locked memory'解决
WARN [main] 2021-02-11 03:27:37,488 NativeLibrary.java:189 - Unable to lock JVM memory (ENOMEM). This can result in part of the JVM being swapped out, especially with mmapped I/O enabled. Increase RLIMIT_MEMLOCK or run Cassandra as root.
#安装jemalloc包解决
WARN [main] 2021-02-11 03:27:37,491 StartupChecks.java:136 - jemalloc shared library could not be preloaded to speed up memory allocations
#开启jmx远程访问解决
WARN [main] 2021-02-11 03:27:37,492 StartupChecks.java:169 - JMX is not enabled to receive remote connections. Please see cassandra-env.sh for more info.
#禁用swap分区、修改内核参数nofile、nproc解决
WARN [main] 2021-02-11 03:27:37,518 SigarLibrary.java:174 - Cassandra server running in degraded mode. Is swap disabled? : false, Address space adequate? : true, nofile limit adequate? : false, nproc limit adequate? : false
#修改sysctl vm.max_map_count解决
WARN [main] 2021-02-11 03:27:37,536 StartupChecks.java:311 - Maximum number of memory map areas per process (vm.max_map_count) 65530 is too low, recommended value: 1048575, you can change it with sysctl.
#目录不存在,会自动创建,不用管
WARN [main] 2021-02-11 03:27:37,548 StartupChecks.java:332 - Directory /home/db02/apache-cassandra-3.11.10/data/data doesn't exist
WARN [main] 2021-02-11 03:27:37,560 StartupChecks.java:332 - Directory /home/db02/apache-cassandra-3.11.10/data/commitlog doesn't exist
WARN [main] 2021-02-11 03:27:37,561 StartupChecks.java:332 - Directory /home/db02/apache-cassandra-3.11.10/data/saved_caches doesn't exist
WARN [main] 2021-02-11 03:27:37,562 StartupChecks.java:332 - Directory /home/db02/apache-cassandra-3.11.10/data/hints doesn't exist
#未找到 host id
WARN [main] 2021-02-11 03:27:41,974 SystemKeyspace.java:1130 - No host ID found, created ed363b86-b69d-4ba0-a1a4-7317dcc582af (Note: This should happen exactly once per node).
[db02@centos1 logs]$
-
用户root-解决上面告警问题
- 安装jemalloc
[root@centos1 ~]# yum list |grep jemalloc jemalloc.x86_64 3.6.0-1.el7 epel jemalloc-devel.x86_64 3.6.0-1.el7 epel [root@centos1 ~]# yum list installed|grep jemalloc [root@centos1 ~]# yum install jemalloc.x86_64 [root@centos1 ~]# yum install jemalloc-devel.x86_64 [root@centos1 ~]# yum list installed|grep jemalloc jemalloc.x86_64 3.6.0-1.el7 @epel jemalloc-devel.x86_64 3.6.0-1.el7 @epel [root@centos1 ~]#
- 开启jmx远程访问
[db02@centos1 conf]$ cat cassandra-env.sh |grep Djava.rmi.server # JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>" #将注释放开,<public name>改为本机ip [db02@centos1 conf]$ cat cassandra-env.sh |grep LOCAL_JMX if [ "x$LOCAL_JMX" = "x" ]; then LOCAL_JMX=yes #将yes改为no,放开远程访问 if [ "$LOCAL_JMX" = "yes" ]; then [db02@centos1 conf]$ cat cassandra-env.sh |grep '$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate' JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" #改为不需要用户密码 JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false" [db02@centos1 conf]$
- 禁用swap分区
#查看swap分区 [root@centos1 ~]# free -h total used free shared buff/cache available Mem: 3.7G 2.8G 634M 27M 320M 871M Swap: 2.0G 0B 2.0G [root@centos1 ~]# fdisk -l ...... [root@centos1 ~]# swapon -s 文件名 类型 大小 已用 权限 /dev/dm-1 partition 2097148 0 -2 #禁用swap分区 [root@centos1 ~]# swapoff -a [root@centos1 ~]# swapon -s [root@centos1 ~]# vi /etc/fstab #注释掉swap行 [root@centos1 ~]# 需相应调整内核参数vm.swappiness = 0(不使用swap配额),见下文
- 内核参数调整
[root@centos1 ~]# vi /etc/sysctl.conf fs.file-max = 6553600 fs.nr_open = 1048576 kernel.pid_max = 66666 vm.max_map_count = 1048575 vm.swappiness = 0 [root@centos1 ~]#sysctl -p #生效 #sysctl -a|grep xxx 查看 [root@centos1 ~]# vi /etc/security/limits.conf #退出重新登录shell即可生效 * - nofile 99999 * - nproc 66666 * - memlock unlimited #分别使用root和db02用户验证 [root@centos1 ~]# ulimit -a|grep 'open files' [root@centos1 ~]# ulimit -a|grep 'max user processes' [root@centos1 ~]# ulimit -a|grep 'max locked memory'
-
开启远程客户端连接,顺便修改集群配置
#使用127.0.0.1可以登录
[db02@centos1 bin]$ ./cqlsh 127.0.0.1
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.10 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> exit
#使用IP不能登录,远程主机也不能登录
[db02@centos1 bin]$ ./cqlsh 10.6.6.11
Connection error: ('Unable to connect to any servers', {'10.6.6.11': error(111, "Tried connecting to [('10.6.6.11', 9042)]. Last error: Connection refused")})
#修改配置开启远程连接
[db02@centos1 bin]$cd ../conf
[db02@centos1 conf]$ cp cassandra.yaml cassandra.yaml.bak
#改成如下这样即可开启远程客户端连接,顺便修改集群配置
[db02@centos1 conf]$ cat cassandra.yaml|egrep 'cluster_name:|seeds:|listen_address:|start_rpc:|rpc_address:'|grep -v '#'
cluster_name: 'Thingsboard Cluster' #集群名称
- seeds: "10.6.6.11" #种子节点,逗号分隔
listen_address: 10.6.6.11 #用于集群节点之间通信的本节点ip
start_rpc: false #保持默认值false即可
rpc_address: 10.6.6.11 #监听客户端远程连接的本地ip,依赖thrift包
#重启
[db02@centos1 conf]$ cd ../bin
[db02@centos1 bin]$ pgrep -f cassandra
18946
[db02@centos1 bin]$ pkill -f cassandra
[db02@centos1 bin]$ pgrep -f cassandra
[db02@centos1 bin]$ ./cassandra
......
[db02@centos1 bin]$ cqlsh 10.6.6.11
Connected to Thingsboard Cluster at 10.6.6.11:9042.
[cqlsh 5.0.1 | Cassandra 3.11.10 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> exit
[db02@centos1 bin]$