本文共 2755 字,大约阅读时间需要 9 分钟。
要开始 Redis 的安装之前,需要先下载 Redis 的源码。可以通过以下 Wget 命令下载最新版本的 Redis:
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
下载完成后,你会得到一个压缩包 redis-5.0.5.tar.gz
,接下来的步骤将解压并安装 Redis。
进入下载目录,解压 Redis 的源码,生成一个名为 redis-5.0.5
的目录:
tar -zxvf redis-5.0.5.tar.gz
确保系统中已经安装了 GCC 和 GCC++,如果没有安装可以使用以下命令进行安装(如果已有这些工具可以跳过此步骤):
yum install gcc gcc-c++
进入 Redis 源码目录,执行编译命令:
cd redis-5.0.5/
然后编译并安装 Redis:
makemake install
编译完成后,Redis 会被安装到你的系统中。如果要随时启动 Redis 服务,可以直接运行以下命令:
由于 Redis 服务器在 /usr/local/bin
目录中已配置到 PATH 中,tac Therefore, 你可以直接在任意目录运行 Redis 命令:
redis-server
或者打开 Redis 遥会话客户端:
redis-cli
将 Redis 的默认配置文件复制到目标目录:
cp redis.conf /etc/redis/
使用 Vim编辑器打开配置文件并根据需要进行修改:
vim /etc/redis/redis.conf
以下是推荐的默认配置文件内容示例:
bind 0.0.0.0 ::1protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised nologlevel noticedatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass 123456appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64zshll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
运行以下命令启动 Redis 服务,同时加载配置文件:
redis-server redis.conf
启动一个 Redis 客户端:
redis-cli
使用 Vim编辑器创建服务文件:
vi /lib/systemd/system/redis.service
在文件中添加以下内容:
[Unit]Description=redisAfter=network.target[Service]Type=forkingPIDFile=/var/run/redis_6379.pidExecStart=/TRS/APP/redis/src/redis-server /TRS/APP/redis/redis.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target
加载 Systemctl 服务:
systemctl daemon-reload
将 Redis 服务设置为开机启动,并立即启动:
systemctl enable redis.servicesystemctl start redis
查看 Redis 服务状态:
systemctl status redis
进行防火墙设置,开放 Redis 的默认端口 6379:
firewall-cmd --permanent --add-port=6379/tcpfirewall-cmd --reload
以上步骤将为你提供一个功能完善的 Redis 安装与配置环境。如果你遇到任何问题,可以参考 Redis 的官方文档或相关社区获取进一步帮助。
转载地址:http://hswnz.baihongyu.com/