Redis(레디스; REmote DIctionary System)은 요즘 각광 받고 있는 In-memory Data(key-value) Store입니다.
Redis Cluster는 최대 1000개의 노드로 구성이 가능하며, session clustering , cache server 용도로 Redis를 많이 사용합니다.
저는 NaverCloud에서 구성하였습니다!
테스트 구성 정보
Server
|
Public IP
|
Private IP
|
비고
|
Redis1
|
115.85.*.*
|
192.168.100.51
|
192.168.100.54 (vip)
|
Redis2
|
49.50.*.*
|
192.168.100.52
|
|
Sentinel
|
118.67.*.*
|
192.168.100.53
|
|
사전 준비
※ NCP 사용시 network interface 추가 후 직접 서버에서 nic를 up해줘야 192.168.100.x 대역 사용가능합니다. 각 서버별 수행하여 nic를 올려줍니다.
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
IPADDR=192.168.100.51
NETMASK=255.255.255.0
[root@redis1]# cd /etc/sysconfig/network-scripts/
[root@redis1 network-scripts]# ifup ifcfg-eth1
[root@redis1 network-scripts]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.41.219.90 netmask 255.255.254.0 broadcast 10.41.219.255
ether f2:20:cd:e8:e2:4e txqueuelen 1000 (Ethernet)
RX packets 1440423 bytes 854193944 (814.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 244707 bytes 148076038 (141.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.51 netmask 255.255.255.0 broadcast 192.168.100.255
ether f2:d7:cf:cf:d0:50 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 252 (252.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 318 bytes 29320 (28.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 318 bytes 29320 (28.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Redis 설치
■ 사전 필요 패키지 설치
[root@redis1 ~]# yum -y install gcc-c++
■ memory 설정
0 : 커널 기본값, Heuristic 하게 Overcommit을 허용
(Page Cache + Swap Memory + Slab Reclaimable 값이 요청한 메모리 수 보다 클 경우 허용)
1 : 항상 Overcommit을 허용
2 : 제한적 Overcommit 허용
[root@redis1 ~]# sysctl vm.overcommit_memory=1
vm.overcommit_memory = 1
[root@redis1 ~]# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
[root@redis1 ~]# sysctl -p
net.ipv4.conf.all.arp_notify = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.log_martians = 1
vm.overcommit_memory = 1
[root@redis1 ~]# sysctl -a | grep vm.overcommit
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.eth0.stable_secret"
sysctl: reading key "net.ipv6.conf.eth1.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.overcommit_kbytes = 0
vm.overcommit_memory = 1
vm.overcommit_ratio = 50
■THP 설정
Redis에서 Hugepage를 Disable 설정을 권장. 하지만 enable 시켜줌
재부팅 시에도 설정값 유지를 위해 /etc/rc.local 에 명령어 추가해줌.
[root@redis1 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@redis1 ~]# vi /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@redis1 ~]# cat /proc/meminfo | grep AnonHugePages
AnonHugePages: 0 kB
■ 다운로드 & 설치 (ALL server)
공식 사이트에서 stable 버전 download 가능
공식 사이트 URL : https://redis.io/download
[root@redis1 ~]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[root@redis1 ~]# tar -zxvf redis-3.2.8.tar.gz
[root@redis1 ~]# cd redis-3.2.8/
[root@redis1 redis-3.2.8]# make && make install
[root@redis1 redis-3.2.8]# cd utils/
■ 전부 enter를 입력하여 default 경로로 설치한다.
[root@redis1 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@redis1 utils]# ps -ef | grep redis
root 65144 1 0 11:05 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 66172 60443 0 11:21 pts/0 00:00:00 grep --color=auto redis
■ Redis 접속 & TEST
[root@redis1 utils]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name kim
OK
127.0.0.1:6379> get name
"kim"
## password 입력해서 접속 가능[root@redis1]# redis-cli -h 10.41.219.90 -a test
10.41.219.90:6379> ping
PONG
Replication
■port 6379/26379 open
<Master 설정 (redis1)> ## bind , requirepass 값 수정
[root@redis1 utils]# vi /etc/redis/6379.conf
bind 0.0.0.0
masterauth test
requirepass test
<Slave 설정 (redis2)>
bind 0.0.0.0
slaveof 192.168.100.51 6379 => Master ip 입력, port 입력
requirepass test
## Restart (Master/Slave)
[root@redis1 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...
■ replication 확인
<Master>
[root@redis1 utils]# redis-cli
127.0.0.1:6379> auth test
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.100.52,port=6379,state=online,offset=43,lag=1
master_repl_offset:43
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:42
<Slave>
[root@redis2 ~]# redis-cli
127.0.0.1:6379> auth test
OK
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.100.51
master_port:6379
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:71
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
## Master Set
127.0.0.1:6379> set kim jh
OK
## Slave Set
127.0.0.1:6379> get kim
"jh"
여기까지 Redis 설치 및 replication 설정이였습니다.
참조 :
'Others > Opensource Tool' 카테고리의 다른 글
[Ansible - AWX설치] (0) | 2022.04.24 |
---|---|
[pt-query-digest - Mysql slowquery 분석 ] (0) | 2022.03.12 |
[Ansible - MySQL 설치 & 배포] (0) | 2022.02.05 |
[Pacemaker & corosync 구성 Vip failover] (0) | 2022.01.20 |
[Redis - Sentinel 설정 & Failover test] part 2 (0) | 2022.01.20 |