Redisyum and Compile Installation

Keywords: Redis network Windows yum

Articles Catalogue

Linux Installation and Use of Redis

Official download address: http://download.redis.io/releases/

Experiments: windows installs redis

  1. Windows Redis Download Address:
    https://github.com/MicrosoftArchive/redis/releases
    It is strongly not recommended to run Redis services in a production environment using Windows systems.

  2. Edit the configuration file and execute redis-server.exe:

cd C:\Users\ZhangShiJie\Desktop\Redis-x64-3.0.504
redis-server.exe redis.windows.conf
  1. Verify redis service port
netstat -t -n

Experiments: yum installs redis

  1. epel source needs to be installed on centos system.
yum install -y redis
  1. Start up service
systemctl start redis 
systemctl enable redis
  1. Simple use
# redis-cli
127.0.0.1:6379> info
...
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-862.el7.x86_64 x86_64
arch_bits:64
...

Experiments: Compile and install redis

Download the latest release redis source package:

http://download.redis.io/releases/

Official website provides interactive tutorials

http://try.redis.io/

  1. Installation environment
yum -y install gcc gcc-c++
  1. Compile and install the latest redis
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xzf redis-5.0.5.tar.gz
cd redis-5.0.5
make PREFIX=/apps/redis install
mkdir /etc/redis
cp redis.conf /etc/redis/
  1. Front-end start redis
/apps/redis/bin/redis-server /etc/redis/redis.conf

Resolve the current warning prompt

(1) The backlog parameter controls the queue value after the server receives the client ack confirmation number when shaking hands three times.

echo "net.core.somaxconn = 512" >> /etc/sysctl.conf
sysctl -p

(2) The kernel allows all physical memory to be allocated
0: Represents that the kernel will check whether there is enough available memory for the process to use; if there is enough available memory, the memory application is allowed; otherwise, the memory application fails and the error is returned to the application process.
1: Represents that the kernel allows all physical memory to be allocated regardless of the current memory state.
2: Represents that the kernel allows allocation of memory beyond the sum of all physical memory and swap space

echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p

(3) Open the dynamic allocation of large pages of memory, need to close the redis responsible for memory management.

echo never > /sys/kernel/mm/transparent_hugepage/enabled
  1. Start redis again and the warning is gone.
/apps/redis/bin/redis-server /etc/redis/redis.conf

  1. Edit redis service startup script
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/apps/redis/bin/redis-server /etc/redis/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target

Note ExecStart, where the installation path and configuration file path correspond

  1. Create redis users and data directories
useradd -s /sbin/nologin redis
mkdir -pv /apps/redis/{etc,logs,data,run}
chown redis.redis -R /apps/redis/
  1. Verify redis startup
systemctl daemon-reload
systemctl restart redis
systemctl enable redis
  1. Port number: 6379
# ss -tnl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port             
LISTEN      0      511      127.0.0.1:6379                         *:*
...
  1. Creating Soft Links
ln -sv /apps/redis/bin/redis* /usr/local/sbin
  1. start-up
# redis-cli
127.0.0.1:6379> info
...
redis_version:4.0.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:5a6b5123d0fb6431
...

Script: compile and install redis

#!/bin/bash
#
#***********************************************************
#Author:                Jibill Chen
#QQ:                    417060833
#Date:                  2019-08-11
#FileName:              redis_4.0.14_install.sh
#URL:                   http://thson.blog.csdn.net
#Description:           The install script of redis 
#**********************************************************
#function
gecho() {
	echo -e "\e[1;32m $1 \e[0m"
	sleep 1
}
recho() {
	echo -e "\e[1;31m $1 \e[0m"
	sleep 1
}

############Download and decompress redis4.0.14################
gecho "Download and decompress redis4.0.14"
wget http://download.redis.io/releases/redis-4.0.14.tar.gz 
tar xf redis-4.0.14.tar.gz
cd redis-4.0.14
###############################################

#Parameter modification
#- - 1. Installation directory
install_dir="/apps/redis"

#Environmental Installation
gecho "Environmental Installation"
yum -y install gcc gcc-c++  || ( recho "Installation environment failed" ; exit )

#Compile redis
gecho "Compile redis"
make PREFIX=${install_dir} install  || recho "Compilation failure"
gecho "Copy configuration files"
mkdir -p ${install_dir}/{etc,log,data,run}
cp redis.conf ${install_dir}/etc/
cp sentinel.conf ${install_dir}/etc/

#Configuration environment
gecho "Configuration environment"
echo "net.core.somaxconn = 512" >> /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p || recho "Configuration environment failed"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local 
chmod +x /etc/rc.local 

#Configuration startup script
gecho "Configuration startup script"
cat > /usr/lib/systemd/system/redis.service << EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=${install_dir}/bin/redis-server ${install_dir}/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF

#Start up service
gecho "Start up service"
useradd -s /sbin/nologin redis  || recho "redis User already exists"
chown redis.redis -R ${install_dir}
systemctl daemon-reload
systemctl restart redis
systemctl enable redis
ln -sv ${install_dir}/bin/redis* /usr/local/sbin

#Modify configuration files
gecho "Modify configuration files"
sed -i "s@^dir.*@dir \"${install_dir}/data\"@" ${install_dir}/etc/redis.conf
sed -i "/^logfile/s#^.*\$#logfile \"${install_dir}/log/redis.log\"#" ${install_dir}/etc/redis.conf

Posted by davespring on Sat, 07 Sep 2019 02:10:48 -0700