redis从开始到精通(1)

redis

Posted by XJ on January 12, 2023

linux环境 redis安装部署

下载redis

官网下载redis https://redis.io/download
wget http://download.redis.io/releases/redis-5.0.7.tar.gz

解压并安装redis

tar -zvxf redis-5.0.7.tar.gz

一般将redis放置于 /usr/local/redis 目录

  mv /root/redis-5.0.7 /usr/local/redis

编译

cd到/usr/local/redis目录,输入命令make执行编译命令,接下来控制台会输出各种编译过程中输出的内容。
make


make PREFIX=/usr/local/redis install

这里多了一个关键字 PREFIX= 这个关键字的作用是编译的时候用于指定程序存放的路径。比如我们现在就是指定了redis必须存放在/usr/local/redis 目录 。假设不添加该关键字Linux会将可执行文件存放在/usr/local/bin目录

安装

进入/usr/local/redis/redis-5.0.7/utils
执行 :  ./install_server.sh
Please select the redis port for this instance: [6379] port
port输入自己想设置的端口号  不输入默认6379
我这里输入的是    6382 会弹出一部分安装信息

Please select the redis config file name [/etc/redis/6382.conf]   
Selected default - /etc/redis/6382.conf
Please select the redis log file name [/var/log/redis_6382.log]   
Selected default - /var/log/redis_6382.log
Please select the data directory for this instance [/var/lib/redis/6382]
Selected default - /var/lib/redis/6382
Please select the redis executable path [/usr/local/redisbin/bin/redis-server]
Selected config:
Port           : 6382
Config file    : /etc/redis/6382.conf    -配置文件地址
Log file       : /var/log/redis_6382.log    --日志地址
Data dir       : /var/lib/redis/6382
Executable     : /usr/local/redisbin/bin/redis-server
Cli Executable : /usr/local/redisbin/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6388.conf => /etc/init.d/redis_6388
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

配置redis环境变量

export REDIS_HOME=/usr/local/redisbin
export PATH=$PATH:$REDIS_HOME/bin
source  /etc/profile   --环境变量立即生效 启动客户端

进入配置文件所在路径
cd /etc/redis/6382.conf
redis-server 6382.conf

进入客户端

redis-cli -p 6382
接着就可以畅游redisle