1.解压redis安装包
[root@localhost app]# tar -zxvf redis-6.2.6.tar.gz
2.安装gcc
[root@localhost app]# yum install -y gcc-c++
3.查看gcc版本
[root@localhost app]# 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-44) (GCC)
4.在redis目录执行make编译
[root@localhost redis]# make
cd src && make all
make[1]: Entering directory `/app/redis/src'
CC Makefile.dep
make[1]: Leaving directory `/app/redis/src'
make[1]: Entering directory `/app/redis/src'
......
如有报错请看这里:
错误: jemalloc/jemalloc.h
- 错误原因
因为以前编译失败,有残留文件
- 解决方案
make distclean
make && make install
编译完成
CC sha256.o
CC timeout.o
CC setcpuaffinity.o
CC monotonic.o
CC mt19937-64.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
CC cli_common.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/app/redis/src'
5.修改redis配置文件,因为Redis默认不是后台启动的
[root@localhost redis]# vim redis.conf
修改daemonize 的值为yes
6.启动redis
[root@localhost redis]# redis-server ./redis.conf
[root@localhost redis]# redis-cli -p 6379
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
7.查看redis进程
[root@localhost redis]# ps -ef|grep redis
root 15951 1 0 21:43 ? 00:00:05 redis-server 127.0.0.1:6379
root 16043 1628 0 22:19 pts/0 00:00:00 grep --color=auto redis
8.关闭redis服务
[root@localhost redis]# redis-server ./redis.conf
[root@localhost redis]# redis-cli -p 6379
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> shutdown
not connected>
not connected>
not connected>
事实上,我觉得以上步骤太麻烦了,所以写了个脚本来安装,省事儿
但这玩意一般也很少直接装,大都用cachecloud管理
#! /bin/bash
function redisInstall(){
echo "
----------------redis-----------------
1、Redis Version
2、Redis Install&start
3、Redis Stop&Remove
4、Redis Start
5、Redis Stop
6、Redis Enable
7、Redis Disable
8、Redis Status
9、Exit
0、Menu
"
while true
do
read -p "input info:" char
case ${char} in
1)
#
if ! test -z "$(find /usr/local/bin/ -name redis-server)" || ! test -z "$(find /usr/bin/ -name redis-server)" ;then
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Version~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
redis-server -v
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Version~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
else
echo "Exception: Version information does not exist!"
fi
;;
2)
yum install -y redis && systemctl start redis
;;
3)
read -p "Are you sure you want to uninstall redis???(yes/no | y/n)": yesOrNo
if [ "${yesOrNo}" = "yes" -o "${yesOrNo}" = "y" ];
then
i=0
while true;do
sleep 0.1
let i++
if [ "${i}" -eq 80 ];then
break
fi
echo -n "."
done
echo "start Uninstall!!!"
systemctl stop redis && yum remove -y redis && rm -rf /var/lib/redis /var/log/redis /usr/local/bin/redis-server /usr/bin/redis-server && echo "Uninstall complete!" || echo "Exception: Service does not exist!"
elif [ "${yesOrNo}" = "no" -o "${yesOrNo}" = "n" ];
then
:<<EOF i=0
while true;do
sleep 0.6
let i++
if [ "${i}" -eq 5 ];then
break
fi
echo -n "."
done
sh /app/nas/redisStatusInfo.sh
else
EOF
sh /app/nas/redisStatusInfo.sh
fi
;;
4)
systemctl start redis || echo "Exception: Service does not exist!"
;;
5)
systemctl stop redis || echo "Exception: The service is not started or does not exist!"
;;
6)
systemctl enable redis || echo "Exception: The service does not exist or is abnormal!"
;;
7)
systemctl disable redis || echo "Exception: The service does not exist or is abnormal!"
;;
8)
systemctl status redis || echo "Exception: The service is not started or does not exist!"
;;
9)
exit
;;
0)
sh /app/nas/redisStatusInfo.sh
;;
*)
if [ ! -z "${char}" ];then
echo "warning!"
fi
esac
done
}
redisInstall