准备主机:
[root@net01 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.135.139 netmask 255.255.255.0 broadcast 192.168.135.255
inet6 fe80::e51f:8a9b:f2ce:e9ca prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ab:5c:d4 txqueuelen 1000 (Ethernet)
·····
下载tar包:
[root@net01 ~]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz
解压:
[root@net01 ~]# tar xf redis-3.2.12.tar.gz
移动目录并创建软连接
[root@net01 ~]# mv redis-3.2.12 /usr/local/
[root@net01 ~]# cd /usr/local/
[root@net01 local]# ln -s redis-3.2.12 redis
[root@net01 local]# ls
bin etc games include lib lib64 libexec redis redis-3.2.12 sbin share src
安装依赖包
[root@net01 local]# yum install -y gcc gcc-c++
安装redis
[root@net01 local]# cd redis
[root@net01 redis]# make
启动redis
[root@net01 redis]# ./src/redis-server &
连接redis
[root@net01 redis]# ./src/redis-cli
#配置环境变量
[root@net01 redis]# vim /etc/profile.d/redis.sh
export PATH=/usr/local/redis/src:$PATH
[root@net01 redis]# source /etc/profile
关闭redis
[root@net01 redis]# redis-cli shutdown
[root@net01 redis]# redis-cli
not connected> shutdown
13282:M 09 May 10:38:54.893 # User requested shutdown...
13282:M 09 May 10:38:54.893 * Saving the final RDB snapshot before exiting.
13282:M 09 May 10:38:54.895 * DB saved on disk
13282:M 09 May 10:38:54.895 # Redis is now ready to exit, bye bye...
not connected> quit
修改redis配置文件
#默认的配置文件
[root@net01 ~]# ll /usr/local/redis/redis.conf
-rw-rw-r-- 1 root root 46695 May 9 10:41 /usr/local/redis/redis.conf
#一般都是自己手动写配置文件
1.创建存放配置文件的目录
[root@net01 ~]# mkdir /server/redis/6379 -p
2.编写配置文件
[root@net01 ~]# vim /server/redis/6379/redis.conf
daemonize yes #启动守护进程,指定配置文件启动直接后台启动
bind 192.168.135.139 127.0.0.1 #绑定的主机地址
port 6379 #指定端口
pidfile /server/redis/6379/redis.pid #指定pid文件路径
loglevel notice #指定日志级别
logfile /server/redis/6379/redis.log #指定日志文件路径
protected-mode no #关闭安全模式
3.指定配置文件启动redis
[root@net01 ~]# redis-server /server/redis/6379/redis.conf