1.下载redis,安装
redis4.0.11下载地址
2.解压redis4.0.11
[root@instance-q7vjqvds work]# tar -zxvf redis-4.0.11.tar.gz
3.修改文件夹名称
[root@instance-q7vjqvds work]# mv redis-4.0.11 redis
4.编译安装
[root@instance-q7vjqvds redis]# make
执行make命令会报下面错误,系统上没有安装C语言环境,需要安装,在linux系统上的C环境是gcc,因此需要安装gcc。
make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/home/work/redis/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/home/work/redis/deps'
make[1]: [persist-settings] Error 2 (ignored)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/work/redis/src'
make: *** [all] Error 2
5.安装gcc,可以从官网下载iso镜像,从里面packages找出来,我一个写java的看到这些头晕,这些是从网上整理出来的(15个文件不要漏掉!!)
gc.zip下载地址
6.解压gcc.zip,编译安装
[root@instance-q7vjqvds soft]# unzip gcc.zip
[root@instance-q7vjqvds soft]# cd gcc
[root@instance-q7vjqvds soft]# rpm -Uvh *.rpm --nodeps --force
查看gcc版本,出现以下界面,表示安装成功
[root@instance-q7vjqvds gcc]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
[root@instance-q7vjqvds gcc]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
7.编译安装redis
[root@instance-q7vjqvds redis]# make MALLOC=libc
[root@instance-q7vjqvds redis]# cd src && make install
8.启动redis
[root@instance-q7vjqvds src]# ./redis-server
以下为设置redis开机自启,并且添加到系统服务
1、复制redis配置文件
[root@instance-q7vjqvds redis]# mkdir /etc/redis
[root@instance-q7vjqvds redis]# cp redis.conf /etc/redis/6379.conf
2、将启动文件拷贝到init.d中
[root@instance-q7vjqvds redis]# cp utils/redis_init_script /etc/init.d/redisd
3、修改启动脚本参数
[root@instance-q7vjqvds redis]# vi /etc/init.d/redisd
添加以下代码,:wq保存退出
# chkconfig: 2345 10 90
# description: Start and Stop redisd
EXEC=/home/soft/redis/src/redis-server
CLIEXEC=/home/soft/redis/src/redis-cli
PIDFILE=/home/redis/redis_${REDISPORT}.pid
4、增加脚本执行权限
[root@instance-q7vjqvds redis]# chmod +x /etc/init.d/redisd
5、增加系统服务
[root@instance-q7vjqvds redis]# chkconfig --add redisd
[root@instance-q7vjqvds redis]# chkconfig --list redisd
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
redisd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
6、启动redis服务测试
[root@instance-q7vjqvds redis]# service redisd start
配置完毕,重启服务器,测试是否成功