【上一篇】 |
The Begin 点点关注,收藏不迷路
|
【下一篇】 |
Redis 4.0.8下载地址
Redis 官网
[root@zyl-docker ~]# ll
total 4608
-rw-r--r-- 1 root root 1729973 Jun 8 16:23 redis-4.0.8.tar.gz
-rw-r--r-- 1 root root 2984823 Jun 8 16:23 redis-7.0.9.tar.gz
[root@zyl-docker ~]# tar -zxvf redis-4.0.8.tar.gz -C /usr/local
[root@zyl-docker local]# cd redis-4.0.8/
[root@zyl-docker redis-4.0.8]# pwd
/usr/local/redis-4.0.8
[root@zyl-docker redis-4.0.8]#
(本环境安装的redis4.0.8,centos 7默认安装的版本为gcc 4.8.5,不需升级也支持)
Redis是基于C语言编写的,安装Redis需要先将Redis的源码进行编译,编译依赖于gcc环境。
yum install -y gcc tcl
升级gcc环境(gcc 4.8.5->gcc 9.3.1):
[root@zyl-docker redis-4.0.8]# yum -y install centos-release-scl
[root@zyl-docker redis-4.0.8]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
####gcc环境设置,长期有效
[root@zyl-docker redis-4.0.8]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
###使文件生效
[root@zyl-docker redis-4.0.8]# source /etc/profile
####升级检查####
[root@zyl-docker redis-4.0.8]# gcc --version
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@zyl-docker redis-4.0.8]#
[root@zyl-docker redis-4.0.8]# pwd
/usr/local/redis-4.0.8
[root@zyl-docker redis-4.0.8]#
###执行命令进行编译
[root@zyl-docker redis-4.0.8]# make MALLOC=libc
[root@zyl-docker src]# make test
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
[root@zyl-docker src]#
外网可以使用 wget http://mirror.centos.org/centos/7/os/x86_64/Packages/tcl-8.5.13-8.el7.x86_64.rpm
下载
内网需要下载后上传
####安装tcl-8.5
[root@zyl-docker ~]# rpm -ivh tcl-8.5.13-8.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tcl-1:8.5.13-8.el7 ################################# [100%]
[root@zyl-docker ~]#
####make test再次测试
[root@zyl-docker src]# make test
....................................
100 seconds - unit/obuf-limits
\o/ All tests passed without errors!
Cleanup: may take some time... OK
####安装redis
[root@zyl-docker src]# make install
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
[root@zyl-docker src]#
# 修改对应配置值
bind 0.0.0.0 # Redis默认localhost访问,修改后可远程连接
protected-mode no ##如果设置为yes,那么只允许我们在本机的回环连接,其他机器无法连接
daemonize yes #yes表示开启守护进程模式,在该模式下,redis会在后台运行。no表示当前界面将进入redis的命令行界面,exit强制退出或者关闭连接工具(putty,xshell等)都会导致redis进程退出
requirepass yourpassword #添加此项,设置redis连接密码,服务器必须设置
[root@zyl-docker src]# vi /etc/systemd/system/redis.service
###添加内容
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/redis-4.0.8/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
ExecStart 后面配置文件的路径为redis安装路径
,/usr/local/redis-4.0.8/redis.conf
为redis解压路径,读取redis.conf
[root@zyl-docker src]# systemctl daemon-reload
[root@zyl-docker src]#
####开启redis
[root@zyl-docker src]# systemctl start redis
####redis状态查看
[root@zyl-docker src]# systemctl status redis
####设置redis 开机自启
[root@zyl-docker src]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
####查看redis 进程
[root@zyl-docker src]# ps -ef | grep redis
polkitd 2182 2160 0 16:14 ? 00:00:14 redis-server *:6379
root 13633 9074 0 17:55 pts/2 00:00:00 vim /usr/local/redis-4.0.8/redis.conf
root 14914 9074 0 18:18 pts/2 00:00:00 grep --color=auto redis
[root@zyl-docker src]#
方式二、将redis的启动脚本复制一份放到/etc/init.d
在/etc目录下新建redis目录
[root@zyl-docker etc]# pwd
/etc
[root@zyl-docker etc]# mkdir redis
[root@zyl-docker etc]#
[root@zyl-docker etc]# cp /usr/local/redis-4.0.8/redis.conf /etc/redis/6379.conf
[root@zyl-docker etc]#
[root@zyl-docker etc]# cp /usr/local/redis-4.0.8/utils/redis_init_script /etc/init.d/redisd
[root@zyl-docker etc]#
[root@zyl-docker init.d]# chkconfig redisd on
service redisd does not support chkconfig
[root@zyl-docker init.d]#
###解决service redisd does not support chkconfig,编辑redisd文件,在第一行加入两行注释
[root@zyl-docker init.d] vim /etc/init.d/redisd
###启动redis
[root@zyl-docker init.d]# service redisd start
Starting Redis server...
15744:C 08 Jun 18:32:52.963 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15744:C 08 Jun 18:32:52.963 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=15744, just started
15744:C 08 Jun 18:32:52.963 # Configuration loaded
[root@zyl-docker init.d]#
###redis进程查看
[root@zyl-docker init.d]# ps -ef | grep redis
root 15745 1 0 18:32 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 15774 9074 0 18:33 pts/2 00:00:00 grep --color=auto redis
[root@zyl-docker init.d]#
###停止redis
[root@zyl-docker init.d]# service redisd stop
Stopping ...
Redis stopped
[root@zyl-docker init.d]#
###连接命令
redis-cli -h x.x.x.x -p port(配置文件中指定的端口号)
[root@zyl-docker init.d]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379>
redis安装成功后,默认安装目录为:/usr/local/bin
[root@zyl-docker bin]# ll
total 23940
-rwxr-xr-x 1 root root 12737304 Apr 23 2022 docker-compose
-rwxr-xr-x 1 root root 353488 Jun 8 17:54 redis-benchmark
-rwxr-xr-x 1 root root 3632784 Jun 8 17:54 redis-check-aof
-rwxr-xr-x 1 root root 3632784 Jun 8 17:54 redis-check-rdb
-rwxr-xr-x 1 root root 518776 Jun 8 17:54 redis-cli
lrwxrwxrwx 1 root root 12 Jun 8 17:54 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 3632784 Jun 8 17:54 redis-server
[root@zyl-docker bin]# pwd
/usr/local/bin
[root@zyl-docker bin]#
redis-benchmark:性能测试工具
redis-check-aof:修复有问题的AOF文件
redis-check-dump:修复有问题的dump.rdb文件
redis-sentinel:redis集群时使用
redis-server:redis服务器启动命令
redis-cli:redis客户端,操作入口
❓ gcc环境升级
❓ tcl升级
❓ redis编译安装,及有关目录详解
【上一篇】 |
The End 点点关注,收藏不迷路
|
【下一篇】 |