Ubuntu 20.04 üzerinde Redis cluster kurulumu ve konfigürasyonu / Installing and configuring Redis cluster on Ubuntu 20.04
- Redis, açık kaynaklı, hafıza-tabanlı (in-memory) bir veritabanı yönetim sistemidir. Ana amaçlarından biri, yüksek performanslı ve ölçeklenebilir veritabanları sağlamaktır. Redis, anahtar-değer (key-value) mağazası olarak çalışır ve hızlı bir şekilde erişim sağlamak için verileri bellekte tutar. Ayrıca, Redis verilerini disk üzerinde saklamak için de kullanılabilir. Redis, özellikle önbellek, oturum yönetimi, sıralama ve gerçek zamanlı uygulamalar gibi alanlarda popüler bir veritabanı çözümüdür.
- Redis is an open-source, in-memory database management system. One of its main goals is to provide high-performance and scalable databases. Redis works as a key-value store and keeps data in memory for fast access. It can also be used to store data on disk. Redis is a popular database solution, especially in areas such as caching, session management, sorting, and real-time applications.
1-) Kurulumdan önce işletim sistemimizin paketlerini güncellemek için aşağıdaki komutları çalıştırıyoruz.
sudo apt-get update
sudo apt-get upgrade
• Redis kurulumu yapmak için aşağıdaki komutu çalıştırmamız gerekiyor.
• We need to run the following command to install Redis.
sudo apt-get install redis-server
sudo systemctl disable redis-server.service
3-) After completing the installation, we need to run the following commands to allow access to the ports.
sudo ufw allow 7000
sudo ufw allow 7001
sudo ufw allow 17000
sudo ufw allow 17001
Eğer işletim sisteminizde Vim kurulu değilse bu işlemi gerçekleştirmeden önce Vim editörünü kurmanız gerekmektedir. Vim editörünü kurmak için aşağıdaki komutu çalıştırabilirsiniz.
If Vim is not installed on your operating system, you need to install the Vim editor before performing this process. To install the Vim editor, you can run the following command.
sudo apt-get install vim
vim /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl -w net.core.somaxconn=65535
exit 0 ' '
chmod +x /etc/rc.local
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
vim /etc/sysctl.conf
vm.overcommit_memory=1
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
sudo mkdir /etc/redis/cluster
sudo mkdir /etc/redis/cluster/7000
sudo mkdir /var/lib/redis/7000
sudo mkdir /etc/redis/cluster/7001
mkdir /etc/redis/cluster/7001
8-) Aşağıdaki komutu çalıştırarak /etc/redis/cluster/7000/redis_7000.conf dosyasını oluşturun ve düzenleyin.
8-) Create and edit the /etc/redis/cluster/7000/redis_7000.conf file by running the following command.
vim /etc/redis/cluster/7000/redis_7000.conf
port 7000
dir /var/lib/redis/7000/
appendonly no
protected-mode no
cluster-enabled yes
cluster-node-timeout 5000
cluster-config-file /etc/redis/cluster/7000/nodes_7000.conf
pidfile /var/run/redis/redis_7000.pid
logfile /var/log/redis/redis_7000.log
loglevel notice
requirepass judajudajudajudajuda
masterauth judajudajudajudajuda
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
9-) Aşağıdaki komutu çalıştırarak /etc/redis/cluster/7001/redis_7001.conf dosyasını oluşturun ve düzenleyin.
9-) Create and edit the /etc/redis/cluster/7001/redis_7001.conf file by running the following command.
vim /etc/redis/cluster/7001/redis_7001.conf
port 7001
dir /var/lib/redis/7001
appendonly no
protected-mode no
cluster-enabled yes
cluster-node-timeout 5000
cluster-config-file /etc/redis/cluster/7001/nodes_7001.conf
pidfile /var/run/redis/redis_7001.pid
logfile /var/log/redis/redis_7001.log
loglevel notice
masterauth judajudajudajudajuda
requirepass judajudajudajudajuda
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
10-) Redis Server servisleri için bir redis kullanıcısı ve bir redis grubu oluşturun ve aşağıdaki komutları çalıştırarak onlara doğru izinleri verin.
10-) Create a redis user and a redis group for the Redis Server services and give them the correct permissions by running the following commands.
sudo chown redis:redis -R /var/lib/redis
sudo chmod 770 -R /var/lib/redis
sudo chown redis:redis -R /etc/redis
11-) Aşağıdaki komutu çalıştırarak /etc/systemd/system/redis_7000.service dosyasını oluşturun ve düzenleyin.
11-) Create and edit the /etc/systemd/system/redis_7000.service file by running the following command.
vim /etc/systemd/system/redis_7000.service
[Unit]
Description=Redis key-value database on 7000
After=network.target
[Service]
ExecStart=/usr/bin/redis-server /etc/redis/cluster/7000/redis_7000.conf --supervised systemd
ExecStop=/bin/redis-cli -h 127.0.0.1 -p 7000 shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
12-) Aşağıdaki komutu çalıştırarak /etc/systemd/system/redis_7001.service dosyasını oluşturun ve düzenleyin.
12-) Create and edit the /etc/systemd/system/redis_7001.service file by running the following command.
vim /etc/systemd/system/redis_7001.service
[Unit]
Description=Redis key-value database on 7001
After=network.target
[Service]
ExecStart=/usr/bin/redis-server /etc/redis/cluster/7001/redis_7001.conf --supervised systemd
ExecStop=/bin/redis-cli -h 127.0.0.1 -p 7001 shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=/etc/redis/cluster/7001
RuntimeDirectoryMode=0755
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
• Dosyayı kaydedip çıkın.
• Save the file and exit.
:wq!
13-) systemd'nin redis_7000.service ve redis_7001.service hizmetlerini otomatik olarak başlatmasını sağlamak için aşağıdaki komutları çalıştırın.
13-) Run the following commands to make systemd automatically start the redis_7000.service and redis_7001.service services.
sudo systemctl enable /etc/systemd/system/redis_7000.service
sudo systemctl enable /etc/systemd/system/redis_7001.service
sudo reboot
15-) Aşağıdaki komutu çalıştırarak 7000 numaralı bağlantı noktasında çalışan redis-server hizmeti için log dosyasının içeriğini (son 100 satır) kontrol edin.
15-) Run the following command to check the contents of the log file (last 100 lines) for the redis-server service running on port 7000.
tail -n 100 /var/log/redis/redis_7000.log
16-) Aşağıdaki komutu çalıştırarak 7001 numaralı bağlantı noktasında çalışan redis-server hizmeti için log dosyasının içeriğini (son 100 satır) kontrol edin.
16-) Run the following command to check the contents of the log file (last 100 lines) for the redis-server service running on port 7001.
tail -n 100 /var/log/redis/redis_7001.log
17-) Aşağıdaki komutu çalıştırarak 7000 numaralı çalışan redis-server hizmetinin durumunu kontrol edin.
17-) Run the following command to check the status of the redis-server service running on port 7000.
systemctl status redis_7000.service
18-) Aşağıdaki komutu çalıştırarak 7001 numaralı çalışan redis-server hizmetinin durumunu kontrol edin.
18-) Run the following command to check the status of the redis-server service running on port 7001.
systemctl status redis_7001.service
1-) 192.168.152.136
2-) 192.168.152.134
3-) 192.168.152.135
redis-cli -a judajudajudajudajuda --cluster create 192.168.152.136:7000 192.168.152.134:7000 192.168.152.135:7000 192.168.152.136:7001 192.168.152.134:7001 192.168.152.135:7001 --cluster-replicas 1
sudo chown -R redis:redis /run/redis
systemctl start redis-server.service
systemctl restart redis-server.service
systemctl start redis_7001.service
systemctl restart redis_7001.service
systemctl start redis_7000.service
systemctl restart redis_7000.service
vim /etc/redis/redis.conf
pidfile /var/run/redis/redis-server.pid
redis-cli -c -h 192.168.152.136 -p 7000 -a judajudajudajudajuda
redis-cli -c -h 192.168.152.136 -p 7001 -a judajudajudajudajuda
set a 1
set b 2
set c 3
set d 4
get b
get a
get c
get d
• Aşağıdaki komutu çalıştırarak 40 saniye boyunca Sunucu 1'de Master'ın yük devretmesini simüle edin.
redis-cli -c -h 192.168.152.136 -p 7000 -a judajudajudajudajuda DEBUG sleep 40
• Bu komutun çıktısı olarak "OK" almalısınız.
• You should get OK as the output of this command.