北京企业网站开发多少钱,商城天气,ui培训哪好,网站制作的趋势Redis 单机版安装与部署
Written By: Xinyao Tian
概述
本文档主要描述了 Redis 的生产环境安装及配置方法。
主要步骤
编译及安装
进入 root 用户并上传 Redis 源码安装包
查看 Redis 源码安装包的上传情况:
[rootcentos-host redis]# pwd
/opt/redis
[root centos-ho…Redis 单机版安装与部署
Written By: Xinyao Tian
概述
本文档主要描述了 Redis 的生产环境安装及配置方法。
主要步骤
编译及安装
进入 root 用户并上传 Redis 源码安装包
查看 Redis 源码安装包的上传情况:
[rootcentos-host redis]# pwd
/opt/redis
[root centos-host redis]# ls -l | grep tar
-rw-r--r-- 1 root root 3384618 Oct 26 11:24 redis-7.2.2.tar.gz安装编译器
由于我们选择从源码安装 Redis 故需要编译器的配合:
sudo yum install gcc-c # 使用sudo yum install gcc-c时会自动安装/升级gcc及其他依赖的包解压并运行编译
解压 tar 文件并进入解压后的目录
[rootcentos-host redis-7.2.2]# pwd
/opt/redis/redis-7.2.2
[rootcentos-host redis-7.2.2]# ls
00-RELEASENOTES CONTRIBUTING.md INSTALL README.md runtest-cluster SECURITY.md tests
BUGS COPYING Makefile redis.conf runtest-moduleapi sentinel.conf TLS.md
CODE_OF_CONDUCT.md deps MANIFESTO runtest runtest-sentinel src utils在该路径内使用 make MALLOClibc 和 make install 命令从源代码编译并安装。
make MALLOClibc
make install直接使用 make 命令执行编译会遭遇报错故需要使用如下命令进行编译。
其原因请见 该博客
确认安装情况
待安装完毕后检视默认安装路径 /usr/local/bin 可以发现已经存在 Redis 相关的命令。
[rootcentos-host redis-7.2.2]# ls -l /usr/local/bin | grep redis
-rwxr-xr-x 1 root root 1073312 Oct 26 13:38 redis-benchmark
lrwxrwxrwx 1 root root 12 Oct 26 13:38 redis-check-aof - redis-server
lrwxrwxrwx 1 root root 12 Oct 26 13:38 redis-check-rdb - redis-server
-rwxr-xr-x 1 root root 1790760 Oct 26 13:38 redis-cli
lrwxrwxrwx 1 root root 12 Oct 26 13:38 redis-sentinel - redis-server
-rwxr-xr-x 1 root root 9437552 Oct 26 13:38 redis-server创建路径及修改配置
该部分详见 Redis 官方安装文档
确定 Redis 的监听端口
监听端口在后续配置中十分重要故需要在配置其他事项前先行确定。
此处我们使用 Redis 的默认端口 6379
创建 Redis 相关路径
使用如下命令创建 Redis 相关的配置文件目录与数据目录:
mkdir /data/redis/etc/redis
mkdir /data/redis/var/redis
mkdir /data/redis/var/run
mkdir /data/redis/var/log
mkdir /data/redis/var/6379
touch /data/redis/var/log/redis_6379.log复制 Redis 启动文件至 /etc/init.d 并重命名
在 Redis 成功安装完毕后其安装路径中会出现 util/ 目录。复制其中的 redis_init_script 文件至 /etc/init.d 并重命名。 如下所示:
[rootcentos-host redis-7.2.2]# pwd
/opt/redis/redis-7.2.2
[rootcentos-host redis-7.2.2]# sudo cp utils/redis_init_script /etc/init.d/redis_6379修改启动文件内的部分配置项。主要修改其中的 REDISPORT, PIDFILE 和 CONF 配置项内容。
修改完毕后的配置文件内容如下所示:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFOREDISPORT6379
EXEC/usr/local/bin/redis-server
CLIEXEC/usr/local/bin/redis-cli# PIDFILE/var/run/redis_${REDISPORT}.pid
PIDFILE/data/redis/var/run/redis_${REDISPORT}.pid
# CONF/etc/redis/${REDISPORT}.conf
CONF/data/redis/etc/redis/${REDISPORT}.confcase $1 instart)if [ -f $PIDFILE ]thenecho $PIDFILE exists, process is already running or crashedelseecho Starting Redis server...$EXEC $CONF复制 Redis 启动文件至相应目录并启动
再次进入 Redis 安装目录并复制配置文件至相应路径:
[rootcentos-host redis-7.2.2]# pwd
/opt/redis/redis-7.2.2
[rootcentos-host redis-7.2.2]# sudo cp redis.conf /data/redis/etc/redis/6379.conf修改配置文件中的配置项 vim /data/redis/etc/redis/6379.conf:
# ...# 取消 IP 限制
bind * -::*# 以守护进程的方式启动 Redis
daemonize yes# 服务端口
port 6379# PIDFILE 存储位置用于记录 Daemon 进程号
pidfile /data/redis/var/run/redis_6379.pid# 日志文件位置
logfile /data/redis/var/log/redis_6379.log# 日志文件级别
loglevel notice# Redis 运行时的文件存放位置
# dir ./
dir /data/redis/var/redis/6379# ...以进程的方式启动 Redis
使用如下命令启动 Redis: sudo /etc/init.d/redis_6379 start
[rootcentos-host redis]# sudo /etc/init.d/redis_6379 start
Starting Redis server...查看进程的运行情况:
[rootcentos-host redis]# ps -ef | grep redis
root 170247 162267 0 13:45 pts/0 00:00:00 su - redisuser
redisus 170248 170247 0 13:45 pts/0 00:00:00 -bash
root 171354 171179 0 13:49 pts/1 00:00:00 su - redisuser
redisus 171355 171354 0 13:49 pts/1 00:00:00 -bash
root 198536 1 0 15:31 ? 00:00:00 /usr/local/bin/redis-server *:6379
root 199166 174495 0 15:33 pts/0 00:00:00 grep --colorauto redis检测安装情况
使用 redis-cli ping 命令查看 Redis 服务是否已经被拉起:
[redisusercentos-host ~]$ redis-cli ping
PONG使用 redis-cli 命令执行一次 save
[redisusercentos-host ~]$ redis-cli save
OK查看数据文件是否有 dump 文件被创建:
[rootcentos-host redis]# ls -l /data/redis/var/redis/6379/dump.rdb
-rw-r--r-- 1 root root 88 Oct 26 15:34 /data/redis/var/redis/6379/dump.rdb查看日志文件是否被正确创建:
[redisusercentos-host ~]$ ls -l /data/redis/var/log/redis_6379.log
-rw-r--r-- 1 root root 3782 Oct 26 15:34 /data/redis/var/log/redis_6379.log创建 Redis 相关 Linux 用户
创建用户
创建 uid 为 5052 的 redisuser 用户并设置其用户密码为 123456
useradd -u 5002 redisuser
passwd redisuser赋予新创建的 redisuser 用户 sudo 权限 vim /etc/sudoers
# ...
## Allows people in group wheel to run all commands
%wheel ALL(ALL) ALL
redisuser ALL(ALL) ALL
# ...更改路径权限
更改 Redis 相关的路径权限:
[rootcentos-host redis]# chown -R redisuser:redisuser /data/redis/创建命令别名
使用 redisuser 用户编辑其配置文件 vim ~/.bash_profile
export REDIS_ETC_DIR/data/redis/etc/
export REDIS_VAR_DIR/data/redis/var/alias redis-start/etc/init.d/redis_6379 start
alias redis-stop/etc/init.d/redis_6379 stop加载配置文件 source ~/.bash_profile
ln -s /data/redis/etc/ ~/redis-etc
ln -s /data/redis/var/ ~/redis-var附加给 Redis 默认用户 default 添加密码
修改配置文件中的配置项 vim /data/redis/etc/redis/6379.conf:
# 添加密码
requirepass da28as07References
Redis - Install Redis more properlyCSDN - 异常解决: configure: error: no acceptable C compiler found in $PATHRedis - Install Redis from SourceCSDN - 编译redis的时候出现zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory问题的解决办法