redis安装
redis官网:https://redis.io
1.1、根据需求下载redis对应版本
下载地址:https://download.redis.io/releases/?_ga=2.185991273.1782951645.1617865616-1544382325.1617865616
下载之后上传至服务器,然后解压到/usr/local/src目录下
[root@redis-server ~]# tar -xf redis-4.0.14.tar.gz -C /usr/local/src
[root@redis-server ~]# cd !$
[root@redis-server src]# ll
总用量 4
drwxrwxr-x. 6 root root 4096 3月 19 2019 redis-4.0.14
[root@redis-server redis-4.0.14]# ll
总用量 304
-rw-rw-r--. 1 root root 166629 3月 19 2019 00-RELEASENOTES
-rw-rw-r--. 1 root root 53 3月 19 2019 BUGS
-rw-rw-r--. 1 root root 1815 3月 19 2019 CONTRIBUTING
-rw-rw-r--. 1 root root 1487 3月 19 2019 COPYING
drwxrwxr-x. 6 root root 124 3月 19 2019 deps
-rw-rw-r--. 1 root root 11 3月 19 2019 INSTALL
-rw-rw-r--. 1 root root 151 3月 19 2019 Makefile
-rw-rw-r--. 1 root root 4223 3月 19 2019 MANIFESTO
-rw-rw-r--. 1 root root 20543 3月 19 2019 README.md
-rw-rw-r--. 1 root root 58766 3月 19 2019 redis.conf
-rwxrwxr-x. 1 root root 271 3月 19 2019 runtest
-rwxrwxr-x. 1 root root 280 3月 19 2019 runtest-cluster
-rwxrwxr-x. 1 root root 281 3月 19 2019 runtest-sentinel
-rw-rw-r--. 1 root root 7921 3月 19 2019 sentinel.conf
drwxrwxr-x. 3 root root 4096 3月 19 2019 src
drwxrwxr-x. 10 root root 167 3月 19 2019 tests
drwxrwxr-x. 8 root root 4096 3月 19 2019 utils
1.2、编译安装
1.2.1、下载依赖
[root@redis-server redis-4.0.14]# yum install gcc-c++ -y
1.2.2、下载epel源
# 详细下载请参考centos7下安装阿里epel源
https://blog.csdn.net/qq_37867279/article/details/115526343
1.2.3、执行make MALLOC=libc命令
[root@redis-server redis-4.0.14]# make MALLOC=libc
如果不执行以上命令可也行会有如下报错:
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
#include <jemalloc/jemalloc.h>
1.2.4、执行编译安装
[root@redis-server redis-4.0.14]# make
如果需要指定安装路径可以如下:
[root@redis-server redis-4.0.14]# make PREFIX=/root/redis
1.2.5、修改redis配置文件
# 修改之前先做备份
cp /usr/local/src/redis-4.0.14/redis.conf /usr/local/src/redis-4.0.14/redis.conf.bak+日期
# 修改配置文件,将136行中的daemonize no改为yes
vim /usr/local/src/redis-4.0.14/redis.conf
134 # By default Redis does not run as a daemon. Use 'yes' if you need it.
135 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
136 daemonize yes
**注意:**如果不修改配置文件可能会启动或连接redis失败,这是因为配置文件中,以守护进程方式启动,默认是关闭的,这是设置为允许以守护进程方式启动服务
1.2.6、启动redis服务
cd /usr/local/src/redis-4.0.14/src
./redis-server /usr/local/src/redis-4.0.14/redis.conf
# 查看redis服务是否启动
ps aux |grep redis
# 查看redis端口是否正常监听
netstat -anput |grep 6379
# 进入redis的控制台
cd /usr/local/src/redis-4.0.14/src
./redis-cli
1.2.7、查看redis的版本
cd /usr/local/src/redis-4.0.14/src
[root@redis-server bin]# ./redis-server -v
Redis server v=4.0.14 sha=00000000:0 malloc=libc bits=64 build=ad32f7d3c6c1b9ac
# 也可通过 --help查看更多参数
[root@redis-server src]# ./redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel