1、安装redis

第一步:下载redis安装包

wget http://download.redis.io/releases/redis-4.0.6.tar.gz

1
2
3
4
5
6
7
8
9
10
11
[root@iZwz991stxdwj560bfmadtZ local]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz
--2017-12-13 12:35:12--  http://download.redis.io/releases/redis-4.0.6.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1723533 (1.6M) [application/x-gzip]
Saving to: ‘redis-4.0.6.tar.gz’
 
100%[==========================================================================================================>] 1,723,533    608KB/s   in 2.8s  
 
2017-12-13 12:35:15 (608 KB/s) - ‘redis-4.0.6.tar.gz’ saved [1723533/1723533]

 

第二步:解压压缩包

tar -zxvf redis-4.0.6.tar.gz

1
[root@iZwz991stxdwj560bfmadtZ local]# tar -zxvf redis-4.0.6.tar.gz

 

第三步:yum安装gcc依赖

yum install gcc 

yum install gcc-c++

1
[root@iZwz991stxdwj560bfmadtZ local]# yum install gcc  
1
遇到选择,输入y即可<br><br><br>

第四步:跳转到redis解压目录下

cd redis-4.0.6

1
[root@iZwz991stxdwj560bfmadtZ local]# cd redis-4.0.6

 

第五步:编译安装

make 

1
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# make MALLOC=libc

  

将/usr/local/redis-4.0.6/src目录下的文件加到/usr/local/bin目录

cd src && make install

1
2
3
4
5
6
7
8
9
10
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src && make install
    CC Makefile.dep
 
Hint: It's a good idea to run 'make test' ;)
 
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

  

第六步:测试是否安装成功 

先切换到redis src目录下

1
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src

 

1、直接启动redis

./redis-server

如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。

 

按 ctrl + c可以关闭窗口。

  

2、以后台进程方式启动redis

第一步:修改redis.conf文件

1
daemonize no  

修改为

1
daemonize yes

  

第二步:指定redis.conf文件启动

1
./redis-server /usr/local/redis-4.0.6/redis.conf
1
2
3
4
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server /usr/local/redis-4.0.6/redis.conf
18713:C 13 Dec 13:07:41.109 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18713:C 13 Dec 13:07:41.109 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18713, just started
18713:C 13 Dec 13:07:41.109 # Configuration loaded

 

第三步:关闭redis进程

首先使用ps -aux | grep redis查看redis进程

1
2
3
[root@iZwz991stxdwj560bfmadtZ src]# ps -aux | grep redis
root     18714  0.0  0.1 141752  2008 ?        Ssl  13:07   0:00 ./redis-server 127.0.0.1:6379
root     18719  0.0  0.0 112644   968 pts/0    R+   13:09   0:00 grep --color=auto redis

 

使用kill命令杀死进程

1
[root@iZwz991stxdwj560bfmadtZ src]# kill -9 18714

 

创建存储redis文件目录

mkdir -p /usr/local/redis

复制redis-server redis-cli到新建立的文件夹

cp ./redis-server /usr/local/redis/
cp ./redis-cli /usr/local/redis/

 复制redis的配置文件

cd ..
cp redis.conf /usr/local/redis/

添加开机启动服务

vim /etc/systemd/system/redis-server.service

粘贴一下内容

[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

 
   

 设置开机启动

systemctl daemon-reload 
systemctl start redis-server.service 
systemctl enable redis-server.service


创建redis命令软连接
systemctl daemon-reload 
systemctl start redis-server.service 
systemctl enable redis-server.service

创建redis命令软连接

ln -s /usr/local/redis/redis-cli /usr/bin/redis