新建cassandra用户并修改密码
[k8s-g2@k8s2 ~]$ sudo useradd cassandra
[k8s-g2@k8s2 ~]$ sudo passwd cassandra
配置用户
用户给cassandra用户增加权限
[k8s-g2@k8s2 home]$ sudo vim /etc/sudoers
切换用户
[k8s-g2@k8s2 ~]$ su - cassandra
安装java环境
[cassandra@k8s2 ~]$ sudo yum -y install java-1.8.0-openjdk*
yum安装的java的默认安装路径在 /usr/lib/jvm,配置环境变量
[cassandra@k8s2 ~]$ vim .bashrc
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-1.el8_2.x86_64
:wq
让配置生效
[cassandra@k8s2 ~]$ source ~/.bashrc
如果想全体用户都可以使用java的话,需要修改/etc/profile文件,添加JAVA_HOME
vi /etc/profile
#set java environment
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
:wq
. /etc/profile //使配置生效
验证java是否安装成功
- 验证JAVA_HOME
[cassandra@k8s2 ~]$ echo $JAVA_HOME
- 验证java安装是否成功
[cassandra@k8s2 ~]$ java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
- 验证jdk是否安装成功
[cassandra@k8s2 ~]$ javac
用法: javac <options> <source files>
下载安装cassandra
下载cassandra忽略证书检查
wget https://mirrors.cnnic.cn/apache/cassandra/3.11.9/apache-cassandra-3.11.9-bin.tar.gz --no-check-certificate
解压缩cassandra
[cassandra@k8s2 ~]$ tar -zxvf apache-cassandra-3.11.9-bin.tar.gz
到指定的位置创建文件夹,这里使用的是/
[cassandra@k8s2 /]$ sudo mkdir cassandra
[cassandra@k8s2 /]$ sudo mv apache-cassandra-3.11.9/* /cassandra.
配置cassandra.yaml及环境变量
[cassandra@k8s2 cassandra]$ cd conf/
修改cassandra.yaml文件。验证以下配置。 默认情况下,这些值将设置为指定的目录。
- data_file_directories “/var/ lib/cassandra/data”
- commitlog_directory “/var/lib/cassandra/commitlog”
- saved_caches_directory “/var/lib/cassandra/saved_caches”
确保这些目录存在并且可以写入,如下所示。
[root@linux cassandra]# mkdir /var/lib/cassandra
[root@linux cassandra]# mkdir /var/log/cassandra
[root@linux /]# chmod 777 /var/lib/cassandra
[root@linux /]# chmod 777 /var/log/cassandra
本次测试建立另一个目录保存
[cassandra@k8s2 /]$ sudo mkdir data
[cassandra@k8s2 /]$ sudo mkdir data/{data,commitlog,saved_caches} -p
[cassandra@k8s2 /]$ sudo chmod 777 -R data/
因此目录对应关系如下:
- data_file_directories “/data/data”
- commitlog_directory “/data/commitlog”
- saved_caches_directory “/data/saved_caches”
按照此对应修改cassandra.yaml文件
配置环境变量
[cassandra@k8s2 ~]$ vim .bashrc
export CASSANDRA_HOME=/cassandra
export PATH=$PATH:$CASSANDRA_HOME/bin
[cassandra@k8s2 ~]$ source ~/.bashrc
[cassandra@k8s2 ~]$ echo $CASSANDRA_HOME
/cassandra
启动cassandra
[cassandra@k8s2 bin]$ ./cassandra -f
本次启动报错
OpenJDK 64-Bit Server VM warning: Cannot open file /cassandra/logs/gc.log due to No such file or directory
于是手工建立一个logs这个目录
[cassandra@k8s2 cassandra]$ sudo mkdir logs
[cassandra@k8s2 cassandra]$ sudo chown cassandra:cassandra logs
再次启动,报错
ERROR [main] 2020-11-25 14:47:55,403 CassandraDaemon.java:803 - Local host name unknown: java.net.UnknownHostException: bogon: bogon: 未知的名称或服务
修改hostname,host,网卡中指定hostname
再次启动,报错
ERROR [main] 2020-11-25 15:21:46,387 CassandraDaemon.java:803 - Has no permission to create directory /cassandra/data/hints
手工建立相关目录,再次启动,成功
正常启动
[cassandra@k8s2 bin]$ ./cassandra -f
[cassandra@k8s2 network-scripts]$ netstat -tpln
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:46253 0.0.0.0:* LISTEN 12781/java
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 192.168.56.102:9042 0.0.0.0:* LISTEN 12781/java
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 192.168.56.102:7000 0.0.0.0:* LISTEN 12781/java
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:7199 0.0.0.0:* LISTEN 12781/java
tcp 0 0 0.0.0.0:5355 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 ::1:631 :::* LISTEN -
tcp6 0 0 ::1:6010 :::* LISTEN -
tcp6 0 0 ::1:6011 :::* LISTEN -
tcp6 0 0 :::5355 :::* LISTEN -
在命令行窗口执行命令bin/cassandra -f,按“Control-C” 停止Cassandra.
如果是通过命令行bin/cassandra后台启动Cassandra,那么必须调用kill pid or pkill -f CassandraDaemon 来停止Cassandra, 其中pid是Cassandra的进程id, 此pid能够通过执行pgrep -f CassandraDaemon得到。