Preparing the Installation Package
Download link: https://download.redis.io/releases/redis-6.2.6.tar.gz
Download and install the package to /usr/local/soft
Write the script file install_redis.sh (CentOS version)
The content of the file is as follows:
#! /usr/bin/bash## Fully automated source code compilation and installation for any versionif [ ! -d "/usr/local/soft" ]then
echo "The folder does not exist, please create a folder and place the installation package here"
exit
fi# Download Redis installation package# Install Redis dependenciesyum -y install gcc gcc-c++ automake autoconf libtool makeyum install -y expectcd /usr/local/softif [ ! -f redis-6.2.6.tar.gz ]then
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
fi
# Extract and install Redis
tar xzf redis-6.2.6.tar.gz
cp -r redis-6.2.6 /usr/local/redis
cd /usr/local/redis
make && make install ## Kernel parameter optimization for the system
cat >> /etc/rc.d/rc.local << "EOF"## Disable Linux's THP (Transparent Huge Pages) to reduce TLB overhead on computers with large memory by using larger memory pages
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
chmod u+x /etc/rc.d/rc.local
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if [ -f /sys/kernel/mm/transparent_hugepage/defrag ]then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
cat >> /etc/sysctl.conf << "EOF"
# Linux system kernel parameter optimization
net.core.somaxconn = 2048
net.ipv4.tcp_max_syn_backlog = 2048
vm.overcommit_memory = 1
EOF
sysctl -p
cat > /etc/security/limits.conf << "EOF"
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
EOF
# Compile and install Redis
cd utils/
sed -i '76,83d' install_server.sh # Delete lines [N,M] of the file
echo "Default operation port, just press enter to operate"
./install_server.sh
# Basic Redis configuration
sed -i "s/bind 127.0.0.1 -::1/bind 0.0.0.0/g" /etc/redis/6379.confsed -i "s/# requirepass foobared/requirepass 123456/g" /etc/redis/6379.conf
# Set to start on boot
systemctl enable redis_6379.servicesystemctl restart redis_6379.servicesystemctl restart redis_6379.service
Place the prepared script file in /usr/local/soft for execution (it can actually be placed elsewhere, but without the installation package, it must be placed in /usr/local/soft), and remember to grant permissions.
Technical accumulation, encountering is fate
