wget安装
[root@RedisSrv1 ~]# yum install wget
安装gcc依赖
[root@RedisSrv1 ~]# yum install gcc -y
-- 请先检查gcc的版本是否低于5,如果是请先升级,可以使用以下命令:
[root@RedisSrv1 redis-stable]# gcc -v
CentOS7默认安装的是4.8.5,而redis6.0只支持5.3以上版本,这里将gcc升级到9
[root@RedisSrv1 redis-stable]# yum -y install centos-release-scl
[root@RedisSrv1 redis-stable]# yum install devtoolset-9-gcc*
gcc版本切换
临时切换:scl enable devtoolset-9 bash
永久切换:echo “source /opt/rh/devtoolset-9/enable” >> /etc/profile
下载最新稳定版 Redis
[root@RedisSrv1 /]# cd /opt/
[root@RedisSrv1 /]# wget http://download.redis.io/releases/redis-stable.tar.gz
解压redis安装包
[root@RedisSrv1 opt]# tar -zxvf redis-stable.tar.gz
进到解压后的redis目录中进行编译
[root@RedisSrv1 opt]# cd redis-stable
[root@RedisSrv1 redis-stable]# make MALLOC=libc
make[1]: Leaving directory `/opt/redis-stable/src'
编译完成后,进入到src目录下,可以看到,生成了可执行文件
生成了src目录文件之后,进入src(源文件目录)继续编译
[root@RedisSrv1 redis-stable]# cd src/
#安装到 /usr/local/redis-stable 目录
[root@RedisSrv1 src]# make install PREFIX=/usr/local/redis-stable
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
--将配置文件移动到/home/redis/目录
cp /opt/redis-stable/redis.conf /usr/local/redis-stable
--修改文件权限
chmod -R 700 /usr/local/redis-stable/
[root@RedisSrv1 redis-stable]# cd /usr/local/redis-stable/bin
[root@RedisSrv1 bin]# ./redis-server /usr/local/redis-stable/redis.conf
--关闭redis进程
[root@server01 src]# ps -ef | grep redis
root 1177 1 0 09:09 ? 00:00:00 ./redis-server 0.0.0.0:6379
root 1185 1147 0 09:11 pts/0 00:00:00 grep --color=auto redis
[root@server01 src]#
[root@server01 src]# ps -aux | grep redis
root 1177 0.0 0.2 144008 2028 ? Ssl 09:09 0:00 ./redis-server 0.0.0.0:6379
root 1187 0.0 0.0 112708 976 pts/0 R+ 09:11 0:00 grep --color=auto redis
[root@server01 src]#
[root@server01 src]# kill -9 1177
[root@server01 src]#
[root@server01 src]# ps -aux | grep redis
root 1189 0.0 0.0 112708 980 pts/0 R+ 09:12 0:00 grep --color=auto redis
[root@server01 src]#
开放防火墙6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
重新加载防火墙设置
firewall-cmd --reload
查看是否生效
firewall-cmd --list-ports
卸载Redis
查看进程
[root@RedisSrv1 src]# ps aux |grep redis
杀掉进程
kill -9 进程号
查看相关文件
[root@RedisSrv1 src]# find / -name "redis*"
删除文件
rm -rf 文件
Redis 自启动
[root@RedisSrv1 ~]# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis-stable/bin/redis-server /usr/local/redis-stable/redis.conf --supervised systemd
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/usr/local/redis-stable/bin/redis-cli -p 6379 shutdown
[Install]
WantedBy=multi-user.target
[root@RedisSrv1 ~]# systemctl daemon-reload
[root@RedisSrv1 ~]# systemctl start redis
[root@RedisSrv1 ~]# systemctl status redis
[root@RedisSrv1 ~]# systemctl stop redis