时间:2022-7-7 作者:冰城心无泪 分类: Linux应用
yum -y install wget tcl make vim
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config && setenforce 0
先安装软件集,作用是可以提供多个软件版本同时存在
yum -y install centos-release-scl
安装gcc9(gcc4.8.5可安装也可不安装,因为编译Redis6用不到)
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
临时启用gcc9编译环境
scl enable devtoolset-9 bash
永久使用gcc9编译环境
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile && source /etc/profile
yum -y install gcc
或者
dnf -y install gcc
mkdir /redis
wget -P /home https://download.redis.io/releases/redis-6.2.7.tar.gz
tar -xzvf /home/redis-6.2.7.tar.gz -C /home/ && cd /home/redis-6.2.7
指定目录命令
make PREFIX=/redis install
安装到默认目录命令
make && make install
redis-benchmark 性能测试工具
redis-check-aof 修复有问题的aof文件
redis-check-rdb 修复有问题的rdb文件
redis-cli redis客户端
redis-sentinel 集群管理工具
redis-server redis服务启动工具
cp /home/redis-6.2.7/redis.conf /etc/
默认只允许本机127.0.0.1访问,注释掉使其允许其他IP访问
sed -i 's/^bind 127.0.0.1/# bind 127.0.0.1/' /etc/redis.conf
默认连接redis时只能通过本地localhost,改成NO,使其允许其他IP访问
sed -i 's/^protected-mode yes/protected-mode no/' /etc/redis.conf
redis默认不在后台运行,修改成yes变成守护进程后台运行
sed -i 's/^daemonize no/daemonize yes/' /etc/redis.conf
设置redis连接密码为redis123
sed -i 's/^# requirepass foobared/requirepass redis123/' /etc/redis.conf
设置持久化文件存放位置
sed -i 's#^dir ./#dir /redis#' /etc/redis.conf
更改默认连接端口为16379
sed -i 's/^port 6379/port 16379/' /etc/redis.conf
设置redis日志文件名称
sed -i 's#^logfile.*#logfile "/var/log/Redis.log"#' /etc/redis.conf
默认redis有16个库(0-15),根据需要可以设置更多
sed -i 's/^databases.*/databases 32/' /etc/redis.conf
cat > /etc/systemd/system/redis.service << EOF
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
Type=forking
ExecStart=/redis/bin/redis-server /etc/redis.conf
ExecStop=/redis/bin/redis-cli -p 16379 shutdown
PrivateTmp=true
Restart=always
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable redis
systemctl start redis && tail -f /var/log/Redis.log
若在启动redis的时候出现报警"The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128"
停掉redis,输入下面命令后,再重启redis。
echo 'net.core.somaxconn= 1024' >> /etc/sysctl.conf && sysctl -p
若在启动redis的时候出现报警“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.”
停掉redis,输入下面命令后,再重启redis。
sysctl vm.overcommit_memory=1 && echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf && sysctl -p
若在启动redis的时候出现报警"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"
停掉redis,输入下面两条命令后,再重启redis。
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local && chmod +x /etc/rc.d/rc.local
firewall-cmd --set-default-zone=public
firewall-cmd --zone=public --add-port=16379/tcp --permanent
systemctl restart firewalld