redis5.0 源码安装手册(适用于任何linux系统 本文以ubuntu16 做为例子)

redis5.0 源码安装手册(适用于任何linux系统)

一 安装并配置开机自启动

创建安装目录
/usr/local/redis5

解压
tar -zxvf redis-5.0.13.tar.gz

cd redis-5.0.13

make 

cd redis-5.0.13/src

sudo make install PREFIX=/usr/local/redis5

配置环境变量

sudo vim /etc/profile

export  REDIS_HOME=/usr/local/redis5
export PATH=$PATH:$REDIS_HOME/bin

切换root用户让配置立即生效
source /etc/profile

安装redis服务
切换到工具文件夹
cd redis-5.0.13/utils

root@ubuntu:/home/zmh/redis-5.0.13/utils# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis5/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/redis5/bin/redis-server
Cli Executable : /usr/local/redis5/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Success!
Starting Redis server...

测试
root@ubuntu:/home/zmh/redis-5.0.13/utils# redis-cli
127.0.0.1:6379> set test test
OK
127.0.0.1:6379> 

服务关闭
service redis_6379 stop

服务启动
service redis_6379 start

查看服务状态
service redis_6379 status
● redis_6379.service - LSB: start and stop redis_6379
   Loaded: loaded (/etc/init.d/redis_6379; bad; vendor preset: enabled)
   Active: active (running) since Fri 2021-07-30 15:33:00 CST; 1min 25s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1513 ExecStop=/etc/init.d/redis_6379 stop (code=exited, status=0/SUCCESS)
  Process: 1551 ExecStart=/etc/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
    Tasks: 4
   Memory: 2.1M
      CPU: 113ms
   CGroup: /system.slice/redis_6379.service
           └─1555 /usr/local/redis5/bin/redis-server 127.0.0.1:6379      

Jul 30 15:33:00 ubuntu systemd[1]: Starting LSB: start and stop redis_6379...
Jul 30 15:33:00 ubuntu redis_6379[1551]: Starting Redis server...
Jul 30 15:33:00 ubuntu systemd[1]: Started LSB: start and stop redis_6379

设置远程访问(正式环境尽量不要开启远程访问,如果要开启则要设置远程访问密码)
先关闭服务
service redis_6379 stop

vim /etc/redis/6379.conf
找到
:/bind
bind 0.0.0.0
protected-mode no
修改好后重新启动  service redis_6379 start


二 持久化配置

redis4.0 开始支持RDB-AOF混合持久化

vim /etc/redis/6379.conf
开启混合模式
aof-use-rdb-preamble yes   

rdb是默认开启的
# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis/6379

这里我们开启AOF

appendonly yes
# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"

保存后重启

服务关闭
service redis_6379 stop

服务启动
service redis_6379 start


原文地址:https://www.cnblogs.com/syzjzmh/p/15080345.html