Redis 설치
CentOS 기준으로 작성되었습니다.
1. Redis Compile 필요 항목설치
yum -y install gcc-c++
Loaded plugins: priorities, update-motd, upgrade-helper amzn-main | 2.1 kB 00:00:00 amzn-updates | 2.5 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package gcc-c++.noarch 0:4.8.5-1.22.amzn1 will be installed --> Processing Dependency: gcc = 4.8.5-1.22.amzn1 for package: gcc-c++-4.8.5-1.22.amzn1.noarch --> Processing Dependency: gcc48-c++ >= 4.8.5 for package: gcc-c++-4.8.5-1.22.amzn1.noarch --> Running transaction check ---> Package gcc.noarch 0:4.8.5-1.22.amzn1 will be installed --> Processing Dependency: gcc48 >= 4.8.5 for package: gcc-4.8.5-1.22.amzn1.noarch ---> Package gcc48-c++.x86_64 0:4.8.5-28.142.amzn1 will be installed --> Processing Dependency: libstdc++48(x86-64) = 4.8.5-28.142.amzn1 for package: gcc48-c++-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc48-c++-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: libmpc.so.3()(64bit) for package: gcc48-c++-4.8.5-28.142.amzn1.x86_64 --> Running transaction check ---> Package gcc48.x86_64 0:4.8.5-28.142.amzn1 will be installed --> Processing Dependency: cpp48(x86-64) = 4.8.5-28.142.amzn1 for package: gcc48-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: libgomp(x86-64) >= 4.8.5-28.142.amzn1 for package: gcc48-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: libgcc(x86-64) >= 4.8.5-28.142.amzn1 for package: gcc48-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: glibc-devel(x86-64) >= 2.2.90-12 for package: gcc48-4.8.5-28.142.amzn1.x86_64 --> Processing Dependency: libgomp.so.1()(64bit) for package: gcc48-4.8.5-28.142.amzn1.x86_64 ---> Package libmpc.x86_64 0:1.0.1-3.3.amzn1 will be installed ---> Package libstdc++48.x86_64 0:4.8.5-11.135.amzn1 will be updated ---> Package libstdc++48.x86_64 0:4.8.5-28.142.amzn1 will be an update ---> Package mpfr.x86_64 0:3.1.1-4.14.amzn1 will be installed --> Running transaction check ---> Package cpp48.x86_64 0:4.8.5-28.142.amzn1 will be installed ---> Package glibc-devel.x86_64 0:2.17-260.175.amzn1 will be installed --> Processing Dependency: glibc-headers = 2.17-260.175.amzn1 for package: glibc-devel-2.17-260.175.amzn1.x86_64 --> Processing Dependency: glibc(x86-64) = 2.17-260.175.amzn1 for package: glibc-devel-2.17-260.175.amzn1.x86_64 --> Processing Dependency: glibc-headers for package: glibc-devel-2.17-260.175.amzn1.x86_64 ---> Package libgcc48.x86_64 0:4.8.5-11.135.amzn1 will be updated ---> Package libgcc48.x86_64 0:4.8.5-28.142.amzn1 will be an update ---> Package libgomp.x86_64 0:6.4.1-1.45.amzn1 will be installed --> Running transaction check ---> Package glibc.x86_64 0:2.17-196.172.amzn1 will be updated --> Processing Dependency: glibc(x86-64) = 2.17-196.172.amzn1 for package: glibc-common-2.17-196.172.amzn1.x86_64 ---> Package glibc.x86_64 0:2.17-260.175.amzn1 will be an update --> Processing Dependency: nss-softokn-freebl(x86-64) >= 3.36.0 for package: glibc-2.17-260.175.amzn1.x86_64 ---> Package glibc-headers.x86_64 0:2.17-260.175.amzn1 will be installed --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-260.175.amzn1.x86_64 --> Processing Dependency: kernel-headers for package: glibc-headers-2.17-260.175.amzn1.x86_64 --> Running transaction check ---> Package glibc-common.x86_64 0:2.17-196.172.amzn1 will be updated ---> Package glibc-common.x86_64 0:2.17-260.175.amzn1 will be an update ---> Package kernel-headers.x86_64 0:4.14.109-80.92.amzn1 will be installed ---> Package nss-softokn-freebl.x86_64 0:3.28.3-8.41.amzn1 will be updated ---> Package nss-softokn-freebl.x86_64 0:3.36.0-5.42.amzn1 will be an update --> Processing Dependency: nss-util >= 3.36.0-1 for package: nss-softokn-freebl-3.36.0-5.42.amzn1.x86_64 --> Processing Dependency: nspr >= 4.19.0 for package: nss-softokn-freebl-3.36.0-5.42.amzn1.x86_64 --> Running transaction check ---> Package nspr.x86_64 0:4.13.1-1.0.39.amzn1 will be updated ---> Package nspr.x86_64 0:4.19.0-1.43.amzn1 will be an update ---> Package nss-util.x86_64 0:3.28.4-3.53.amzn1 will be updated ---> Package nss-util.x86_64 0:3.36.0-1.54.amzn1 will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================== Package Arch Version Repository Size ================================================================================================================== Installing: gcc-c++ noarch 4.8.5-1.22.amzn1 amzn-main 4.0 k Installing for dependencies: cpp48 x86_64 4.8.5-28.142.amzn1 amzn-updates 6.7 M gcc noarch 4.8.5-1.22.amzn1 amzn-main 4.1 k gcc48 x86_64 4.8.5-28.142.amzn1 amzn-updates 18 M gcc48-c++ x86_64 4.8.5-28.142.amzn1 amzn-updates 9.8 M glibc-devel x86_64 2.17-260.175.amzn1 amzn-updates 1.2 M glibc-headers x86_64 2.17-260.175.amzn1 amzn-updates 758 k kernel-headers x86_64 4.14.109-80.92.amzn1 amzn-updates 1.2 M libgomp x86_64 6.4.1-1.45.amzn1 amzn-main 204 k libmpc x86_64 1.0.1-3.3.amzn1 amzn-main 53 k mpfr x86_64 3.1.1-4.14.amzn1 amzn-main 237 k Updating for dependencies: glibc x86_64 2.17-260.175.amzn1 amzn-updates 5.8 M glibc-common x86_64 2.17-260.175.amzn1 amzn-updates 28 M libgcc48 x86_64 4.8.5-28.142.amzn1 amzn-updates 155 k libstdc++48 x86_64 4.8.5-28.142.amzn1 amzn-updates 408 k nspr x86_64 4.19.0-1.43.amzn1 amzn-updates 134 k nss-softokn-freebl x86_64 3.36.0-5.42.amzn1 amzn-updates 248 k nss-util x86_64 3.36.0-1.54.amzn1 amzn-updates 88 k Transaction Summary ================================================================================================================== Install 1 Package (+10 Dependent packages) Upgrade ( 7 Dependent packages) Total download size: 73 M Downloading packages: (1/18): gcc-4.8.5-1.22.amzn1.noarch.rpm | 4.1 kB 00:00:00 (2/18): gcc-c++-4.8.5-1.22.amzn1.noarch.rpm | 4.0 kB 00:00:00 (3/18): cpp48-4.8.5-28.142.amzn1.x86_64.rpm | 6.7 MB 00:00:00 (4/18): gcc48-4.8.5-28.142.amzn1.x86_64.rpm | 18 MB 00:00:00 (5/18): gcc48-c++-4.8.5-28.142.amzn1.x86_64.rpm | 9.8 MB 00:00:00 (6/18): glibc-2.17-260.175.amzn1.x86_64.rpm | 5.8 MB 00:00:00 (7/18): glibc-devel-2.17-260.175.amzn1.x86_64.rpm | 1.2 MB 00:00:00 (8/18): glibc-headers-2.17-260.175.amzn1.x86_64.rpm | 758 kB 00:00:00 (9/18): kernel-headers-4.14.109-80.92.amzn1.x86_64.rpm | 1.2 MB 00:00:00 (10/18): libgcc48-4.8.5-28.142.amzn1.x86_64.rpm | 155 kB 00:00:00 (11/18): libstdc++48-4.8.5-28.142.amzn1.x86_64.rpm | 408 kB 00:00:00 (12/18): glibc-common-2.17-260.175.amzn1.x86_64.rpm | 28 MB 00:00:00 (13/18): libmpc-1.0.1-3.3.amzn1.x86_64.rpm | 53 kB 00:00:00 (14/18): libgomp-6.4.1-1.45.amzn1.x86_64.rpm | 204 kB 00:00:00 (15/18): mpfr-3.1.1-4.14.amzn1.x86_64.rpm | 237 kB 00:00:00 (16/18): nspr-4.19.0-1.43.amzn1.x86_64.rpm | 134 kB 00:00:00 (17/18): nss-softokn-freebl-3.36.0-5.42.amzn1.x86_64.rpm | 248 kB 00:00:00 (18/18): nss-util-3.36.0-1.54.amzn1.x86_64.rpm | 88 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------ Total 71 MB/s | 73 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : glibc-common-2.17-260.175.amzn1.x86_64 1/25 Updating : libgcc48-4.8.5-28.142.amzn1.x86_64 2/25 Updating : nss-softokn-freebl-3.36.0-5.42.amzn1.x86_64 3/25 Updating : glibc-2.17-260.175.amzn1.x86_64 4/25 Updating : nspr-4.19.0-1.43.amzn1.x86_64 5/25 Updating : nss-util-3.36.0-1.54.amzn1.x86_64 6/25 Installing : mpfr-3.1.1-4.14.amzn1.x86_64 7/25 Installing : libmpc-1.0.1-3.3.amzn1.x86_64 8/25 Updating : libstdc++48-4.8.5-28.142.amzn1.x86_64 9/25 Installing : cpp48-4.8.5-28.142.amzn1.x86_64 10/25 Installing : libgomp-6.4.1-1.45.amzn1.x86_64 11/25 Installing : kernel-headers-4.14.109-80.92.amzn1.x86_64 12/25 Installing : glibc-headers-2.17-260.175.amzn1.x86_64 13/25 Installing : glibc-devel-2.17-260.175.amzn1.x86_64 14/25 Installing : gcc48-4.8.5-28.142.amzn1.x86_64 15/25 Installing : gcc-4.8.5-1.22.amzn1.noarch 16/25 Installing : gcc48-c++-4.8.5-28.142.amzn1.x86_64 17/25 Installing : gcc-c++-4.8.5-1.22.amzn1.noarch 18/25 Cleanup : nss-util-3.28.4-3.53.amzn1.x86_64 19/25 Cleanup : libstdc++48-4.8.5-11.135.amzn1.x86_64 20/25 Cleanup : glibc-common-2.17-196.172.amzn1.x86_64 21/25 Cleanup : libgcc48-4.8.5-11.135.amzn1.x86_64 22/25 Cleanup : nspr-4.13.1-1.0.39.amzn1.x86_64 23/25 Cleanup : nss-softokn-freebl-3.28.3-8.41.amzn1.x86_64 24/25 Cleanup : glibc-2.17-196.172.amzn1.x86_64 25/25 Verifying : gcc-4.8.5-1.22.amzn1.noarch 1/25 Verifying : libstdc++48-4.8.5-28.142.amzn1.x86_64 2/25 Verifying : glibc-devel-2.17-260.175.amzn1.x86_64 3/25 Verifying : gcc-c++-4.8.5-1.22.amzn1.noarch 4/25 Verifying : nss-softokn-freebl-3.36.0-5.42.amzn1.x86_64 5/25 Verifying : glibc-2.17-260.175.amzn1.x86_64 6/25 Verifying : mpfr-3.1.1-4.14.amzn1.x86_64 7/25 Verifying : gcc48-4.8.5-28.142.amzn1.x86_64 8/25 Verifying : cpp48-4.8.5-28.142.amzn1.x86_64 9/25 Verifying : gcc48-c++-4.8.5-28.142.amzn1.x86_64 10/25 Verifying : kernel-headers-4.14.109-80.92.amzn1.x86_64 11/25 Verifying : glibc-headers-2.17-260.175.amzn1.x86_64 12/25 Verifying : glibc-common-2.17-260.175.amzn1.x86_64 13/25 Verifying : nss-util-3.36.0-1.54.amzn1.x86_64 14/25 Verifying : libgcc48-4.8.5-28.142.amzn1.x86_64 15/25 Verifying : libgomp-6.4.1-1.45.amzn1.x86_64 16/25 Verifying : nspr-4.19.0-1.43.amzn1.x86_64 17/25 Verifying : libmpc-1.0.1-3.3.amzn1.x86_64 18/25 Verifying : nss-util-3.28.4-3.53.amzn1.x86_64 19/25 Verifying : libstdc++48-4.8.5-11.135.amzn1.x86_64 20/25 Verifying : nspr-4.13.1-1.0.39.amzn1.x86_64 21/25 Verifying : glibc-2.17-196.172.amzn1.x86_64 22/25 Verifying : glibc-common-2.17-196.172.amzn1.x86_64 23/25 Verifying : nss-softokn-freebl-3.28.3-8.41.amzn1.x86_64 24/25 Verifying : libgcc48-4.8.5-11.135.amzn1.x86_64 25/25 Installed: gcc-c++.noarch 0:4.8.5-1.22.amzn1 Dependency Installed: cpp48.x86_64 0:4.8.5-28.142.amzn1 gcc.noarch 0:4.8.5-1.22.amzn1 gcc48.x86_64 0:4.8.5-28.142.amzn1 gcc48-c++.x86_64 0:4.8.5-28.142.amzn1 glibc-devel.x86_64 0:2.17-260.175.amzn1 glibc-headers.x86_64 0:2.17-260.175.amzn1 kernel-headers.x86_64 0:4.14.109-80.92.amzn1 libgomp.x86_64 0:6.4.1-1.45.amzn1 libmpc.x86_64 0:1.0.1-3.3.amzn1 mpfr.x86_64 0:3.1.1-4.14.amzn1 Dependency Updated: glibc.x86_64 0:2.17-260.175.amzn1 glibc-common.x86_64 0:2.17-260.175.amzn1 libgcc48.x86_64 0:4.8.5-28.142.amzn1 libstdc++48.x86_64 0:4.8.5-28.142.amzn1 nspr.x86_64 0:4.19.0-1.43.amzn1 nss-softokn-freebl.x86_64 0:3.36.0-5.42.amzn1 nss-util.x86_64 0:3.36.0-1.54.amzn1 Complete!
2. 메모리 설정
Redis 구동시 TCP Backlog 경고시
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
메모리 사용이 허용량을 넘아가게 될 경우에 대한 처리
sysctl vm.overcommit_memory=1 echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
3.TCP Backlog
Redis 구동시 TCP Backlog 경고시
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
somaxconn은 ‘Socket Max Connection’의 약어로 최대 연결 개수를 뜻합니다. 리눅스의 경우 메모리가 128MB 보다 작을 경우 128이 기본이고, 클 경우 1024가 기본입니다.
동시에 너무 많은 요청이 올 경우, 예를 들어, somaxconn 값이 128일 경우 그 이상 요청이 오는 것에 대해서는 연결을 거부하게 됩니다.
sysctl -w net.core.somaxconn=65535 echo "net.core.somaxconn=65535" >> /etc/sysctl.conf
4. THP
Redis 구동시 TCP Backlog 경고시
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’
as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
Transparent Hug Pages (THP)는 대량의 메모리를 관리하기 위한 한 방법으로, 페이지 크기를 확대(2MB or 1GB)하여 사용하는 방법입니다. THP는 성능 개선을 목적으로하며,
대부분의 시스템 설정의 성능을 향상시키지만 DB와 같은 특정 상황에 대해서는 오히려 성능이 악화될 수 있습니다.
Redis는 실행 시 THP가 enabled 되어 있는 경우 경고 메시지를 출력하며, 해당 기능을 끄도록 제안하고 있습니다.
참조 : http://allthatlinux.com/dokuwiki/doku.php?id=thp_transparent_huge_pages_%EA%B8%B0%EB%8A%A5%EA%B3%BC_%EC%84%A4%EC%A0%95_%EB%B0%A9%EB%B2%95
- Transparent Hug Pages 확인
cat /sys/kernel/mm/transparent_hugepage/enabled always [madvise] never
해당 기능은 아래와 같은 명령을 수행하는 것으로 끌 수 있습니다.
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
시작시 마다 해당 명령이 수행되도록 하기 위해 /etc/rc.local 파일에 명령을 추가
sudo sed -i -e '$i \echo never > /sys/kernel/mm/transparent_hugepage/enabled' /etc/rc.d/rc.local sudo sed -i -e '$i \echo never > /sys/kernel/mm/transparent_hugepage/defrag\n' /etc/rc.d/rc.local
5. redis 설치
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make make install cd 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!
6.redis process 확인
ps -elf|grep redis 5 S root 9841 1 0 80 0 - 38473 SyS_ep 03:46 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379 0 S root 9846 9760 0 80 0 - 27629 - 03:47 pts/1 00:00:00 grep --color=auto redis
7.redis log 확인
tail -50f /var/log/redis_6379.log
9840:C 17 Apr 2019 03:46:28.137 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 9840:C 17 Apr 2019 03:46:28.137 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=9840, just started 9840:C 17 Apr 2019 03:46:28.137 # Configuration loaded 9841:M 17 Apr 2019 03:46:28.138 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.4 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 9841 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 9841:M 17 Apr 2019 03:46:28.139 # Server initialized 9841:M 17 Apr 2019 03:46:28.139 * Ready to accept connections
8.redis cli을 이용한 set, get 확인
/usr/local/bin/redis-cli
127.0.0.1:6379> set foo ver OK 127.0.0.1:6379> get foo "ver" 127.0.0.1:6379>