GNU/Linux >> Belajar Linux >  >> Cent OS

Clustered RabbitMQ Centos 7

Pengantar

RabbitMQ adalah skema perpesanan perusahaan open-source yang awalnya didasarkan pada standar Advanced Messaging Queuing Protocol (AMQP), tetapi sekarang mendukung banyak protokol lainnya. Ringan dan mudah digunakan di tempat atau di cloud, RabbitMQ adalah perpesanan sumber terbuka paling populer. Untuk memastikan kinerja RabbitMQ yang optimal, pemantauan RabbitMQ sangatlah penting. Namun, sulit bagi organisasi untuk menemukan alat pemantauan RabbitMQ Berkelompok yang memberikan visibilitas lengkap ke dalam infrastruktur mereka. Juga, periksa RabbitMQ di Centos8 dan dokumentasi situs rabbitmq

Apa yang bisa dilakukan RabbitMQ?

Keandalan

Jadi RabbitMQ menawarkan berbagai fitur untuk memungkinkan Anda menukar kinerja dengan keandalan, termasuk ketekunan, dukungan pengiriman, konfirmasi penerbit, dan ketersediaan tinggi.

Perutean Fleksibel

Pesan dirutekan melalui pertukaran sebelum tiba di antrian.

RabbitMQ juga memiliki beberapa tipe pertukaran bawaan untuk logika perutean yang khas.

Juga Untuk perutean yang lebih kompleks, Anda dapat mengikat pertukaran bersama-sama atau bahkan menulis jenis pertukaran Anda sendiri sebagai plugin.

Mengelompokkan RabbitMQ

Beberapa server RabbitMQ di jaringan lokal dapat dikelompokkan bersama, membentuk satu broker logis.

Federasi

Untuk server yang perlu terhubung lebih longgar dan tidak dapat diandalkan daripada yang dimungkinkan oleh pengelompokan, RabbitMQ menawarkan model federasi.

Antrian Sangat Tersedia

Jadi Antrian dapat dicerminkan di beberapa mesin dalam sebuah cluster, memastikan bahwa bahkan jika terjadi kegagalan perangkat keras, pesan Anda tetap aman.

Multi-protokol

RabbitMQ mendukung pengiriman pesan melalui berbagai protokol pengiriman pesan.

Banyak Klien yang Dikelompokkan

Juga Ada klien RabbitMQ untuk hampir semua bahasa yang dapat Anda pikirkan.

UI Manajemen

RabbitMQ dikirimkan dengan UI manajemen yang mudah digunakan yang memungkinkan Anda memantau dan mengontrol setiap aspek broker pesan Anda.

Prasyarat

  • Persyaratan penting untuk penyiapan Cluster RabbitMQ adalah memiliki minimal 2 node dengan CentOS 7 yang akan kita gunakan artikel ini. Kemudian, atur FQDN dan pengaturan jaringan dasar mereka
  • Setidaknya dua instans CentOS 7 yang baru digunakan dan diperbarui dalam subnet yang sama dengan jaringan pribadi yang diaktifkan
  • RabbitMQ diinstal dengan konsol manajemen yang diaktifkan di setiap server.
  • Pengguna non-admin dengan hak sudo

Menginstal RabbitMQ

Jadi Instal repositori Epel dan paket RabbitMQ Clustered

[root@master ~]# yum install epel-release -y
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.icidc.com
 * extras: mirrors.icidc.com
 * updates: mirrors.icidc.com
base                                                                                                                                                                                       | 3.6 kB  00:00:00
extras                                                                                                                                                                                     | 2.9 kB  00:00:00
updates                                                                                                                                                                                    | 2.9 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                                                                                                                                                          | 242 kB  00:00:00
(2/4): base/7/x86_64/group_gz                                                                                                                                                              | 153 kB  00:00:00
(3/4): base/7/x86_64/primary_db                                                                                                                                                            | 6.1 MB  00:00:02
(4/4): updates/7/x86_64/primary_db                                                                                                                                                         | 9.6 MB  00:00:05
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                Arch                                             Version                                           Repository                                        Size
==================================================================================================================================================================================================================
Installing:
 epel-release                                           noarch                                           7-11                                              extras                                            15 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm                                                                                                                                                               |  15 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                                                                       1/1
  Verifying  : epel-release-7-11.noarch                                                                                                                                                                       1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@master ~]# 

Juga Instal Clustered RabbitMQ dan paket yang diperlukan

[root@master ~]# yum -y install rabbitmq-server erlang
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                       | 8.4 kB  00:00:00
 * base: mirrors.icidc.com
 * epel: download.nus.edu.sg
 * extras: mirrors.icidc.com
 * updates: mirrors.icidc.com
epel                                                                                                                                                                                       | 4.7 kB  00:00:00
(1/3): epel/x86_64/group_gz                                                                                                                                                                |  96 kB  00:00:00
(2/3): epel/x86_64/updateinfo                                                                                                                                                              | 1.0 MB  00:00:00
(3/3): epel/x86_64/primary_db                                                                                                                                                              | 6.9 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.3.5-34.el7 will be installed
--> Processing Dependency: erlang-erts >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-kernel >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-mnesia >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-os_mon >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch


......................

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                    Arch                                         Version                                                 Repository                                  Size
==================================================================================================================================================================================================================
Installing:
 rabbitmq-server                                            noarch                                       3.3.5-34.el7                                            epel                                       4.0 M
Installing for dependencies:
 erlang-asn1                                                x86_64                                       R16B-03.18.el7                                          epel                                       758 k
 erlang-compiler                                            x86_64                                       R16B-03.18.el7                                          epel                                       1.0 M
 erlang-crypto                                              x86_64                                       R16B-03.18.el7                                          epel                                        86 k
 erlang-erts                                                x86_64                                       R16B-03.18.el7                                          epel                                       2.5 M
 erlang-hipe                                                x86_64                                       R16B-03.18.el7                                          epel                                       2.4 M
                             293 k
 erlang-sd_notify                                           x86_64                                       0.1-1.el7                                               epel                                       9.1 k
 erlang-snmp                                                x86_64                                       R16B-03.18.el7                                          epel                                       1.5 M
 erlang-ssl                                                 x86_64                                       R16B-03.18.el7                                          epel                                       588 k
 erlang-stdlib                                              x86_64                                       R16B-03.18.el7                                          epel                                       2.2 M
 erlang-syntax_tools                                        x86_64                                       R16B-03.18.el7                                          epel                                       336 k
 erlang-tools                                               x86_64                                       R16B-03.18.el7                                          epel                                       566 k
 erlang-xmerl                                               x86_64                                       R16B-03.18.el7                                          epel                                       998 k
 lksctp-tools                                               x86_64                                       1.0.17-2.el7                                            base                                        88 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package (+21 Dependent packages)

Total download size: 21 M
Installed size: 36 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/erlang-asn1-R16B-03.18.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY                                    ]  0.0 B/s | 624 kB  --:--:-- ETA
Public key for erlang-asn1-R16B-03.18.el7.x86_64.rpm is not installed
(1/22): erlang-asn1-R16B-03.18.el7.x86_64.rpm                                                                                                                                              | 758 kB  00:00:00
..........                                                                                                                                                           4/22
  Verifying  : erlang-compiler-R16B-03.18.el7.x86_64                                                                                                                                                         5/22
  Verifying  : erlang-mnesia-R16B-03.18.el7.x86_64                                                                                                                                                           6/22
  Verifying  : erlang-crypto-R16B-03.18.el7.x86_64                                                                                                                                                           7/22
  Verifying  : erlang-hipe-R16B-03.18.el7.x86_64                                                                                                                                                             8/22
  Verifying  : erlang-inets-R16B-03.18.el7.x86_64                                                                                                                                                            
  Verifying  : erlang-os_mon-R16B-03.18.el7.x86_64                                                                                                                                                          17/22
  Verifying  : erlang-otp_mibs-R16B-03.18.el7.x86_64                                                                                                                                                        18/22
  Verifying  : erlang-tools-R16B-03.18.el7.x86_64                                                                                                                                                           19/22
  Verifying  : erlang-snmp-R16B-03.18.el7.x86_64                                                                                                                                                            20/22
  Verifying  : erlang-syntax_tools-R16B-03.18.el7.x86_64                                                                                                                                                    21/22
  Verifying  : erlang-asn1-R16B-03.18.el7.x86_64                                                                                                                                                            22/22

Installed:
  rabbitmq-server.noarch 0:3.3.5-34.el7

Dependency Installed:
  erlang-asn1.x86_64 0:R16B-03.18.el7             erlang-compiler.x86_64 0:R16B-03.18.el7               erlang-crypto.x86_64 0:R16B-03.18.el7               erlang-erts.x86_64 0:R16B-03.18.el7
  erlang-hipe.x86_64 0:R16B-03.18.el7             erlang-inets.x86_64 0:R16B-03.18.el7                  erlang-kernel.x86_64 0:R16B-03.18.el7               erlang-mnesia.x86_64 0:R16B-03.18.el7
  erlang-os_mon.x86_64 0:R16B-03.18.el7           erlang-otp_mibs.x86_64 0:R16B-03.18.el7               erlang-public_key.x86_64 0:R16B-03.18.el7           erlang-runtime_tools.x86_64 0:R16B-03.18.el7
  erlang-sasl.x86_64 0:R16B-03.18.el7             erlang-sd_notify.x86_64 0:0.1-1.el7                   erlang-snmp.x86_64 0:R16B-03.18.el7                 erlang-ssl.x86_64 0:R16B-03.18.el7
  erlang-stdlib.x86_64 0:R16B-03.18.el7           erlang-syntax_tools.x86_64 0:R16B-03.18.el7           erlang-tools.x86_64 0:R16B-03.18.el7                erlang-xmerl.x86_64 0:R16B-03.18.el7
  lksctp-tools.x86_64 0:1.0.17-2.el7

Complete!
[root@master ~]# 

Mulai dan aktifkan layanan

[root@master ~]# systemctl start rabbitmq-server

[root@master ~]# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.

Menambahkan pengguna untuk RabbitMQ

Gunakan RabbitMQ, tambahkan pengguna terlebih dahulu. Secara default, hanya pengguna tamu yang ada dan dia dapat menghubungkan satu-satunya localhost

[root@master ~]# rabbitmqctl add_user rabbit password
Creating user "rabbit" ...
...done.
[root@master ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
rabbit  []
...done.
[root@master ~]#

Berikan hak Admin kepada pengguna rabbitmq

Berikan izin kepada pengguna untuk virtualhost

[root@master ~]# rabbitmqctl set_user_tags rabbit administrator
Setting tags for user "rabbit" to [administrator] ...
...done.
[root@master ~]# 

Tambahkan virtualhost ke Clustered RabbitMQ

Gunakan RabbitMQ, tambahkan virtualhost

[root@master ~]# rabbitmqctl add_vhost /my_vhost
Creating vhost "/my_vhost" ...
...done.
[root@master ~]# rabbitmqctl list_vhosts
Listing vhosts ...
/
/my_vhost
...done.
[root@master ~]#

Instal pustaka klien AMQP

Menerapkan AMQP (Advanced Message Queuing Protocol) yang digunakan untuk Clustered RabbitMQ

[root@master ~]# yum -y install python2-pika
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.rise.ph
 * epel: mirror.telkomuniversity.ac.id
 * extras: mirror.rise.ph
 * updates: mirror.rise.ph
Resolving Dependencies
--> Running transaction check
---> Package python2-pika.noarch 0:0.10.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                               Arch                                            Version                                                Repository                                     Size
==================================================================================================================================================================================================================
Installing:
 python2-pika                                          noarch                                          0.10.0-10.el7                                          epel                                          170 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package

Total download size: 170 k
Installed size: 1.0 M
Downloading packages:
python2-pika-0.10.0-10.el7.noarch.rpm                                                                                                                                                      | 170 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pika-0.10.0-10.el7.noarch                                                                                                                                                              1/1
  Verifying  : python2-pika-0.10.0-10.el7.noarch                                                                                                                                                              1/1

Installed:
  python2-pika.noarch 0:0.10.0-10.el7

Complete!
[root@master ~]#

Buat skrip python untuk menguji koneksi

Mengirim pesan di Python Clustered RabbitMQ

[root@master ~]# cat send_msg.py
#!/usr/bin/env python

import pika

credentials = pika.PlainCredentials('unixcop', 'password')
connection = pika.BlockingConnection(pika.ConnectionParameters(
                                     'localhost',
                                     5672,
                                     '/my_vhost',
                                     credentials))

channel = connection.channel()
channel.queue_declare(queue='Hello_World')

channel.basic_publish(exchange='',
                      routing_key='Hello_World',
                      body='Hello RabbitMQ World!')

print(" [x] Sent 'Hello_World'")

connection.close()
[root@master ~]#

[root@master ~]# python send_msg.py
 [x] Sent 'Hello_World'
[root@master ~]#

Buat skrip untuk memeriksa apakah pesan telah diterima

[root@master ~]# cat receive_msg.py
#!/usr/bin/env python

import signal
import pika

signal.signal(signal.SIGPIPE, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.SIG_DFL)

credentials = pika.PlainCredentials('unixcop', 'password')
connection = pika.BlockingConnection(pika.ConnectionParameters(
                                     'master.example.com',
                                     5672,
                                     '/my_vhost',
                                     credentials))

channel = connection.channel()
channel.queue_declare(queue='Hello_World')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

channel.basic_consume(callback,
                      queue='Hello_World',
                      no_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
[root@master ~]#

[root@master ~]# python receive_msg.py
 [*] Waiting for messages. To exit press CTRL+C
 [x] Received 'Hello RabbitMQ World!'
 [x] Received 'Hello RabbitMQ World!'
^C

Setel cookie erlang ke semua node untuk Clustered RabbitMQ

[root@master ~]# chmod 777 /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@worker1:/var/lib/rabbitmq/.erlang.cookie
[root@master ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@worker2:/var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chmod 400 /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chown rabbitmq /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chgrp rabbitmq /var/lib/rabbitmq/.erlang.cookie

Gabung node ke Clustered RabbitMQ

[root@worker1~]# rabbitmqctl stop_app
[root@worker1 ~]# rabbitmqctl join_cluster rabbit@master
[root@worker1 ~]# rabbitmqctl start_app
#---------------------------------------------------------------------------------#
[root@worker2 ~]# rabbitmqctl stop_app
[root@worker2 ~]# rabbitmqctl join_cluster rabbit@master
[root@worker2 ~]# rabbitmqctl start_app

Instal plugin manajemen RabbitMQ

[root@master ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.

[root@master ~]# systemctl restart rabbitmq-server

Akses ke "http://hostname atau alamat IP):15672/" klien, kemudian, formulir login RabbitMQ terbuka, login dengan pengguna admin.

Dasbor dengan node cluster


Cent OS
  1. Unduh CentOS Linux

  2. Menginstal Tomcat 8 di Centos 6

  3. Menginstal MariaDB di CentOS 7

  1. Cara memperbarui CentOS

  2. AlmaLinux vs CentOS

  3. Aliran CentOS vs CentOS

  1. Instal Odoo 14 di CentOS 8

  2. Instal PHP 7 di CentOS 7

  3. Instal MariaDB di CentOS 7