Cassandra3.0集群安装完整版——Cassandra3.11.3

@羲凡——只为了更好的活着

Cassandra集群安装完整版——Cassandra3.11.3

Cassandra是Hadoop生态圈中开源分布式NoSQL数据库系统,Cassandra的安装很简单,而且Cassandra2.0和Cassandra3.0安装都非常类似,完全可以套用。此文中选择Cassandra3.11.3作为示范!

我用三台机器做安装Cassandra集群hostname分别是deptest14、deptest20、deptest23

一、前期准备

1.下载Cassandra安装包

下载地址如下
https://archive.apache.org/dist/cassandra/3.11.3/
Cassandra3.0集群安装完整版——Cassandra3.11.3_第1张图片

2.环境准备(三台机器都要操作)

a.安装jdk1.8。安装cassandra3.11.3官网要求jdk1.8环境

sudo vi /etc/profile
	# JAVA_HOME
	export JAVA_HOME=/usr/local/package/jdk1.8.0_131
	export PATH=$PATH:$JAVA_HOME/bin
# 重新加载/etc/profile文件
source /etc/profile 

输入java -version,显示如下结果则表示java已准备

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

b.关闭防火墙或开放端口(一般运维交到我们手中的机器是符合这个条件的)

# TCP port, for commands and data
storage_port: 7000
# SSL port, for encrypted communication.  Unused unless enabled in encryption_options
ssl_storage_port: 7001
# port for the CQL native transport to listen for clients on
native_transport_port: 9042
# port for Thrift to listen for clients on
rpc_port: 9160

二、官网介绍

这里插播官网介绍,主要是博主觉得cassandra的官网做的非常好,很清晰明了,有时间的朋友可以多多浏览。cassandra官网对参数的介绍很详细,但是对安装只是一带而过。
官网介绍安装的地址
https://cassandra.apache.org/doc/latest/getting_started/installing.html
Cassandra3.0集群安装完整版——Cassandra3.11.3_第2张图片
官网介绍重要参数地址
https://cassandra.apache.org/doc/latest/getting_started/configuring.html
Cassandra3.0集群安装完整版——Cassandra3.11.3_第3张图片
接下来我们配置集群是主要修改上述参数

三、安装Cassandra

先在一台机器(比如deptest23)上操作,再将安装包拷贝到其他机器上

1. 解压Cassandra 的tarball并配置 /etc/profile

# 解压
cd /usr/local/package #进入tar包所在的目录
tar -zxf apache-cassandra-3.11.3-bin.tar.gz -C ../ #解压到当前文件夹
mv apache-cassandra-3.11.3/ cassandra-3.11.3 #重命名文件夹
#添加CASSANDRA_HOME到/etc/profile文件中
sudo vi /etc/profile
   export CASSANDRA_HOME=/usr/local/package/cassandra-3.11.3
   export PATH=$PATH:$CASSANDRA_HOME/bin
source /etc/profile

2. 修改配置文件 cassandra.yaml

#进入$CASSANDRA_HOME/conf配置文件所在的目录
cd $CASSANDRA_HOME/conf 

a.修改cassandra集群的名字(默认是 Test Cluster)

# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: 'AaronTest Cluster'

b.设置集群种子节点IP,如果多个用逗号分隔

# seeds is actually a comma-delimited list of addresses.
# Ex: ",,"
- seeds: "10.11.12.14,10.11.12.20,10.11.12.23"

c.设置监听地址(本机的IP),是为了其他节点能与节点进行通信(默认是 localhost),每台机器填自己机器的IP

# Setting listen_address to 0.0.0.0 is always wrong.
listen_address: 10.11.12.23

d.开启 thrift rpc 服务(默认是 false)

# Whether to start the thrift rpc server.
start_rpc: true

e.设置rpc的地址(默认是 localhost)

# For security reasons, you should not expose this port to the internet.  Firewall it if needed.
rpc_address: 10.11.12.23

f.设置数据文件所在路径(默认是 $CASSANDRA_HOME/data/data)

# If not set, the default directory is $CASSANDRA_HOME/data/data.
data_file_directories:
     - /data1/cassandradata/data
     - /data2/cassandradata/data
     - /data3/cassandradata/data
     - /data4/cassandradata/data
     - /data5/cassandradata/data

g.设置commitlog文件所在路径(默认是 $CASSANDRA_HOME/data/commitlog)

# If not set, the default directory is $CASSANDRA_HOME/data/commitlog.
commitlog_directory: /data6/cassandradata/commitlog

问:为什么要设置 data_file_directoriescommitlog_directory
答:因为这两个文件很大,分散集群中磁盘I/O压力,前者是cassandra实际数据存放的目录,后者是数据写入commitlog的文件目录

3. 分发安装包

a.将cassandra安装包,从deptest23分发到另外两台机器(deptest14和deptest20)上

scp -r cassandra-3.11.3/ deptest14:/usr/local/package/
scp -r cassandra-3.11.3/ deptest20:/usr/local/package/

b.添加CASSANDRA_HOME到/etc/profile文件中

 #添加CASSANDRA_HOME到/etc/profile文件中
sudo vi /etc/profile
	export CASSANDRA_HOME=/usr/local/package/cassandra-3.11.3
	export PATH=$PATH:$CASSANDRA_HOME/bin
source /etc/profile

c.修改 $CASSANDRA_HOME/conf/cassandra.yaml 中的 listen_addressrpc_address 将其设置成自己的IP

3. 启动cassandra

任意目录下输入 cassandra(每台机器都要操作),如果最后出现如下几行则表示启动成功

INFO  [main] 2019-01-17 15:26:36,260 Gossiper.java:1723 - No gossip backlog; proceeding

查看集群各节点状态使用命令 nodetool status

deplab@deptest20:~$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address       Load       Tokens       Owns (effective)  Host ID                               Rack
UN  10.11.12.20  103.66 KiB  256          66.3%             271cf5c2-c317-4c3f-8d71-f41848a2ea53  rack1
UN  10.11.12.23  160.23 KiB  256          64.6%             312ee4ff-c6bf-48ab-be58-4b552c98abd6  rack1
UN  10.11.12.14  103.65 KiB  256          69.1%             f0d2bd06-9663-495d-b3ef-0f3ee83c9a9a  rack1

可以看到IP地址前面都是 UN ,说明三台机器启动成功且运行正常(不正常显示 DN)。

三、报错解决

因为cassandra安装比较简单,按照上述步骤绝对没问题的啦,但有可能因为端口问题产生报错,比如

ERROR [main] 2019-01-17 15:21:24,370 CassandraDaemon.java:708 - Port already in use: 7199; nested exception is: 
	java.net.BindException: Address already in use (Bind failed)
java.net.BindException: Address already in use (Bind failed)
	at java.net.PlainSocketImpl.socketBind(Native Method) ~[na:1.8.0_131]
	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) ~[na:1.8.0_131]
	at java.net.ServerSocket.bind(ServerSocket.java:375) ~[na:1.8.0_131]
	at java.net.ServerSocket.<init>(ServerSocket.java:237) ~[na:1.8.0_131]
	at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231) ~[na:1.8.0_131]
	at org.apache.cassandra.utils.RMIServerSocketFactoryImpl.createServerSocket(RMIServerSocketFactoryImpl.java:42) ~[apache-cassandra-3.11.3.jar:3.11.3]
	at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:666) ~[na:1.8.0_131]
	at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:330) ~[na:1.8.0_131]
	at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:249) ~[na:1.8.0_131]
	at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411) ~[na:1.8.0_131]
	at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147) ~[na:1.8.0_131]
	at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:234) ~[na:1.8.0_131]
	at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:195) ~[na:1.8.0_131]
	at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:155) ~[na:1.8.0_131]
	at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:239) ~[na:1.8.0_131]
	at org.apache.cassandra.utils.JMXServerUtils.createJMXServer(JMXServerUtils.java:75) ~[apache-cassandra-3.11.3.jar:3.11.3]
	at org.apache.cassandra.service.CassandraDaemon.maybeInitJmx(CassandraDaemon.java:143) [apache-cassandra-3.11.3.jar:3.11.3]
	at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:188) [apache-cassandra-3.11.3.jar:3.11.3]
	at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:602) [apache-cassandra-3.11.3.jar:3.11.3]
	at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:691) [apache-cassandra-3.11.3.jar:3.11.3]

这个报错很明显,端口7199被占用了,解决方法也很简单。
输入 netstat -tunlp |grep 7199命令,找到占用改端口的服务,kill掉它即可。

若对博客中有任何问题,欢迎留言交流

恭喜您已经完成Cassandra 的安装
恭喜您已经完成Cassandra 的安装
恭喜您已经完成Cassandra 的安装

@羲凡——只为了更好的活着

你可能感兴趣的:(Cassandra/Hbase)