linux centos redis-6.2.6一键安装及配置密码
#!/bin/bash
# 一键安装Redis 6.2.6并配置密码
# 安装依赖
yum install -y gcc tcl
# 下载Redis
cd /usr/local/src || exit
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
# 解压Redis
tar xzf redis-6.2.6.tar.gz
cd redis-6.2.6 || exit
# 编译Redis
make MALLOC=libc
make install
# 创建配置文件目录
mkdir /etc/redis
# 复制配置文件
cp redis.conf /etc/redis/redis.conf
# 设置Redis为后台守护进程
sed -i 's/daemonize no/daemonize yes/' /etc/redis/redis.conf
# 设置密码
echo "requirepass yourpassword" >> /etc/redis/redis.conf
# 创建启动脚本
echo "[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/redis.service
# 允许远程访问
sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' /etc/redis/redis.conf
# 重载systemd以识别新服务
systemctl daemon-reload
# 启动Redis服务
systemctl start redis.service
# 设置Redis服务开机自启
systemctl enable redis.service
请将上述脚本保存为.sh
文件,然后在Linux CentOS系统中运行。确保将yourpassword
替换为您想要设置的实际Redis密码。这个脚本会下载Redis 6.2.6,编译安装,创建配置文件,设置密码,创建启动脚本,并配置Redis服务开机自启。
评论已关闭