sql >> Database >  >> RDS >> Database

Hoe Apache Cassandra te installeren op Ubuntu 20.10/Ubuntu 20.04

In deze blog leggen we uit hoe je Apache Cassandra installeert op Ubuntu 20.10/Ubuntu 20.04. Apache Cassandra is een open-source NoSQL-database die bedoeld is om grote hoeveelheden gegevens op te slaan in een gedecentraliseerd cluster met hoge beschikbaarheid, fouttolerantie, consistentie over meerdere servers en lineaire schaalbaarheid te bieden.

Stappen om Apache Cassandra op Ubuntu te installeren

Stap 1:installeer Java op Ubuntu 20

$ sudo apt install openjdk-8-jdk

Op mijn systeem was Java er al, dus het gaat upgraden.

Stap 2:Java-installatie verifiëren

$ java -version

Voorbeelduitvoer:

root@Cassandra:~# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.10-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

Stap 3:Installeer het afhankelijkheidspakket:

$ sudo apt install apt-transport-https

Stap 4:GPG-sleutel importeren:

$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

Voorbeelduitvoer:

root@Cassandra:~# wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
root@Cassandra:~#

Stap 5:Apache Cassandra's Repository toevoegen

$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

Voorbeelduitvoer:

root@Cassandra:~# sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
root@Cassandra:~#

Stap 6:Ubuntu-systeem bijwerken

$ sudo apt update

Stap 7:Installeer Apache Cassandra in Ubuntu

$ sudo apt install cassandra

U kunt ook de nieuwste Cassandra-versie bekijken

Na installatie wordt de Cassandra-service automatisch gestart.

Voorbeelduitvoer:

root@Cassandra:~# sudo apt install cassandra
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
virtualbox-guest-utils
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib
python-is-python2 python2 python2-minimal python2.7 python2.7-minimal
Suggested packages:
cassandra-tools python2-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
cassandra libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib
python-is-python2 python2 python2-minimal python2.7 python2.7-minimal
0 upgraded, 9 newly installed, 0 to remove and 332 not upgraded.
Need to get 34.4 MB of archives.
After this operation, 56.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:2 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 libpython2.7-minimal amd64 2.7.18-1build2 [335 kB]
Get:1 https://downloads.apache.org/cassandra/debian 311x/main amd64 cassandra all 3.11.10 [30.7 MB]
Get:3 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 python2.7-minimal amd64 2.7.18-1build2 [1,264 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 python2-minimal amd64 2.7.18-2 [13.5 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 libpython2.7-stdlib amd64 2.7.18-1build2 [1,867 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 python2.7 amd64 2.7.18-1build2 [248 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 libpython2-stdlib amd64 2.7.18-2 [7,332 B]
Get:8 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 python2 amd64 2.7.18-2 [9,068 B]
Get:9 http://us.archive.ubuntu.com/ubuntu groovy/universe amd64 python-is-python2 all 2.7.17-4 [2,496 B]
Fetched 34.4 MB in 1min 12s (474 kB/s) 
Selecting previously unselected package libpython2.7-minimal:amd64.
(Reading database ... 155984 files and directories currently installed.)
Preparing to unpack .../0-libpython2.7-minimal_2.7.18-1build2_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.18-1build2) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../1-python2.7-minimal_2.7.18-1build2_amd64.deb ...
Unpacking python2.7-minimal (2.7.18-1build2) ...
Selecting previously unselected package python2-minimal.
Preparing to unpack .../2-python2-minimal_2.7.18-2_amd64.deb ...
Unpacking python2-minimal (2.7.18-2) ...
Selecting previously unselected package libpython2.7-stdlib:amd64.
Preparing to unpack .../3-libpython2.7-stdlib_2.7.18-1build2_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.18-1build2) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../4-python2.7_2.7.18-1build2_amd64.deb ...
Unpacking python2.7 (2.7.18-1build2) ...
Selecting previously unselected package libpython2-stdlib:amd64.
Preparing to unpack .../5-libpython2-stdlib_2.7.18-2_amd64.deb ...
Unpacking libpython2-stdlib:amd64 (2.7.18-2) ...
Setting up libpython2.7-minimal:amd64 (2.7.18-1build2) ...
Setting up python2.7-minimal (2.7.18-1build2) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python2-minimal (2.7.18-2) ...
Selecting previously unselected package python2.
(Reading database ... 156719 files and directories currently installed.)
Preparing to unpack .../python2_2.7.18-2_amd64.deb ...
Unpacking python2 (2.7.18-2) ...
Selecting previously unselected package python-is-python2.
Preparing to unpack .../python-is-python2_2.7.17-4_all.deb ...
Unpacking python-is-python2 (2.7.17-4) ...
Selecting previously unselected package cassandra.
Preparing to unpack .../cassandra_3.11.10_all.deb ...
Unpacking cassandra (3.11.10) ...
Setting up libpython2.7-stdlib:amd64 (2.7.18-1build2) ...
Setting up python2.7 (2.7.18-1build2) ...
Setting up libpython2-stdlib:amd64 (2.7.18-2) ...
Setting up python2 (2.7.18-2) ...
Setting up python-is-python2 (2.7.17-4) ...
Setting up cassandra (3.11.10) ...
Adding group `cassandra' (GID 141) ...
Done.
vm.max_map_count = 1048575
net.ipv4.tcp_keepalive_time = 300
update-rc.d: warning: start and stop actions are no longer supported; falling b
ack to defaults
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for systemd (246.6-1ubuntu1) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu4) ...
root@Cassandra:~#

Casandra-service automatisch starten bij het opstarten:

sudo systemctl enable cassandra

Voorbeelduitvoer:

root@Cassandra:~# sudo systemctl enable cassandra
cassandra.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable cassandra
root@Cassandra:~#

Stap 8:controleer de status van Cassandra en nodetool

$ sudo systemctl status cassandra

Controleer de statistieken van uw node

$ sudo nodetool status

De VN letters in het uitgangssignaal dat het cluster werkt.

Stap 9:Log in op Cassandra-terminal

$ cqlsh

Voorbeelduitvoer:

root@Cassandra:~# cqlsh
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>

Stap 10:Apache Cassandra configureren in Ubuntu

  • Configuratiebestanden –> /etc/cassandra 
  • Gegevens worden opgeslagen -> /var/lib/cassandra
  • Opstartbestand –> /etc/default/cassandra

De standaard Cassandra-clusternaam is "Testcluster", om de aanmelding voor de clusternaam bij te werken naar Cassandra.

$ cqlsh

In mijn geval zal ik de Cassandra-clusternaam instellen op "SysAdminXpert Cluster"

UPDATE system.local SET cluster_name = 'SysAdminXpert Cluster' WHERE KEY = 'local';

Commando om de Cassandra-prompt af te sluiten

EXIT;

We raden aan een back-up te maken voordat u de "cassandra.yaml" . bewerkt bestand

sudo cp /etc/cassandra/cassandra.yaml /etc/cassandra/cassandra.yaml.org-backup

Zoek en bewerk “cassandra.yaml” bestand en werk de clusternaam bij.

$ sudo vim /etc/cassandra/cassandra.yaml

Zoek naar de "cluster_name" en update de clusternaam, ik heb deze ingesteld op "SysAdminXpert Cluster".

IP-adressen van Cassandra-knooppunten toevoegen. Open het configuratiebestand en zoek onder het gedeelte seed _provider de seeds invoer:

Opslaan en afsluiten "cassandra.yaml" bestand, om de wijzigingen weer te geven, start u de Cassandra-service opnieuw.

Herstart Cassandra-service en controleer de status:

$ sudo systemctl restart cassandra && sudo systemctl status cassandra

Log opnieuw in op Cassandra Terminal en verifieer de clusternaam die is bijgewerkt zoals hieronder weergegeven.

$ cqlsh

Cassandra cqlsh gebruik:

Cassandra Query Language Shell (CQLSH) is in feite een communicatiemedium tussen Cassandra en de gebruiker. CQLSH is een platform waarmee de gebruiker de Cassandra-querytaal (CQL) kan starten.

root@Cassandra:~# cqlsh --help
Usage: cqlsh.py [options] [host [port]]

CQL Shell for Apache Cassandra

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-C, --color Always use color output
--no-color Never use color output
--browser=BROWSER The browser to use to display CQL help, where BROWSER
can be:
- one of the supported browsers in
https://docs.python.org/2/library/webbrowser.html.
- browser path followed by %s, example: /usr/bin
/google-chrome-stable %s
--ssl Use SSL
--no_compact No Compact
-u USERNAME, --username=USERNAME
Authenticate as user.
-p PASSWORD, --password=PASSWORD
Authenticate using password.
-k KEYSPACE, --keyspace=KEYSPACE
Authenticate to the given keyspace.
-f FILE, --file=FILE Execute commands from FILE, then exit
--debug Show additional debugging information
--encoding=ENCODING Specify a non-default encoding for output. (Default:
utf-8)
--cqlshrc=CQLSHRC Specify an alternative cqlshrc file location.
--cqlversion=CQLVERSION
Specify a particular CQL version, by default the
highest version supported by the server will be used.
Examples: "3.0.3", "3.1.0"
--protocol-version=PROTOCOL_VERSION
Specify a specific protcol version otherwise the
client will default and downgrade as necessary
-e EXECUTE, --execute=EXECUTE
Execute the statement and quit.
--connect-timeout=CONNECT_TIMEOUT
Specify the connection timeout in seconds (default: 5
seconds).
--request-timeout=REQUEST_TIMEOUT
Specify the default request timeout in seconds
(default: 10 seconds).
-t, --tty Force tty mode (command prompt).

Connects to 127.0.0.1:9042 by default. These defaults can be changed by
setting $CQLSH_HOST and/or $CQLSH_PORT. When a host (and optional port number)
are given on the command line, they take precedence over any defaults.
root@Cassandra:~#

Opdracht om versie op te halen:

Deze opdracht toont u de versie van cqlsh, Cassandra, CQL en het native protocol.

Voorbeeld:

root@Cassandra:~# cqlsh
Connected to SysAdminXpert 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>

Opdracht om host te tonen:

Deze opdracht toont u de naam van het cluster, het IP-adres met poort.

Voorbeeld:

cqlsh> show host
Connected to Test Cluster at 127.0.0.1:9042.
cqlsh>

Opdracht om te BESCHRIJVEN:

Dit commando geeft de beschrijving van alle onderstaande schema-elementen zoals hieronder vermeld:

Syntaxis:

DESCRIBE CLUSTER
DESCRIBE SCHEMA
DESCRIBE TABLES
DESCRIBE TABLE <table name>
DESCRIBE INDEX <index name>
DESCRIBE KEYSPACES
DESCRIBE KEYSPACE <keyspace name>
DESCRIBE TYPES
DESCRIBE TYPE <type name>
DESCRIBE FUNCTIONS
DESCRIBE FUNCTION <function name>
DESCRIBE AGGREGATES
DESCRIBE AGGREGATE <aggregate function name>
DESCRIBE MATERIALIZED VIEW <view name>

Voorbeeld:

cqlsh> describe cluster

Cluster: SysAdminXpert Cluster
Partitioner: Murmur3Partitioner

cqlsh>

Opdracht om de console te wissen:

Syntaxis:

CLEAR
CLS

Einde artikel. We hebben gezien hoe we Apache Cassandra op Ubuntu 20.10 kunnen installeren.


  1. Verwijzen naar een tabel in een ander schema waarbij de schemanaam wordt weggelaten

  2. SQL-query om productverkopen per maand te vergelijken

  3. Een manier om SQLBulkCopy in te voegen of bij te werken als deze bestaat?

  4. SQL Server hoofdlettergevoeligheid controleren?