Redis系列 - 编译安装redis
1:下载redis源码包
http://redis.io/download
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
2: 解压
tar xzf redis-5.0.3.tar.gz
cd redis-5.0.3
3:编译参数配置
yum install gcc gcc- c++
make PREFIX=/usr/local/redis install
常见问题:
错误:安装 Redis 执行 make #error “Newer version of jemalloc required”的解决方法:
解决:make MALLOC=libc
文件目录
redis
-> bin
-> redis-benchmark: redis性能测试工具
-> redis-check-aof: 检查aof日志的工具
-> redis-check-rdb: 检查rdb日志的工具
-> redis-cli: 连接用的客户端
-> redis-server: redis服务进程
创建配置文件
cp redis.conf /usr/local/redis/ -> redis配置文件
vim /usr/local/redis/redis.conf
cp sentinel.conf /usr/local/redis/ -> 哨兵配置文件
mkdir /usr/local/redis/logs
logfile /usr/local/redis/logs/redis.log -> redis日志文件
daemonize yes 后台运行
pidfile /usr/local/redis/redis_6379.pid
timeout 300 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
requirepass **** : Redis连接密码
bind 127.0.0.1 : 注释掉 + protected-mode no 允许远程访问
appendonly yes # 解释 是否打开 aof日志功能
appendfsync everysec
no-appendfsync-on-rewrite yes 解释:正在导出rdb快照的过程中,要不要停止同步aof,默认no
appendfilename "appendonly.aof"
dir /usr/local/redis/
解释daemonize
daemonize 设置yes或者no区别
daemonize:yes:redis采用的是单进程多线程的模式。当redis.conf中选项daemonize设置成yes时,代表开启守护进程模式。在该模式下,redis会在后台运行,并将进程pid号写入至redis.conf选项pidfile设置的文件中,此时redis将一直运行,除非手动kill该进程。
daemonize:no: 当daemonize选项设置成no时,当前界面将进入redis的命令行界面,exit强制退出或者关闭连接工具(putty,xshell等)都会导致redis进程退出。
常用配置
port 6379 端口修改
bind 127.0.0.1 绑定的主机地址
配置环境变量
vim /etc/profile.d/redis.sh
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
source /etc/profile
redis-cli -v 查看版本号
启动,关闭
方式一:
启动命令:
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
停止命令
/usr/local/redis/bin/redis-cli shutdown
ps -ef | grep redis 查看是否启动成功
将redis 加入到systemctl中
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/redis/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /usr/lib/systemd/system/redis.service
systemctl enable redis.service //加入开机启动
systemctl start redis //开启redis服务
systemctl stop redis //关闭redis服务
systemctl reload redis //重启redis服务
systemctl status redis //查看redis运行状态
还没有评论,来说两句吧...