Redis安装步骤
-
下载地址:
https://redis.io/(英文网站)
http://redis.cn/(中文网站)
-
在redis下载网站,复制下载地址,然后再linux中通过wget下载
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
-
解压
tar -xf redis-6.0.6.tar.gz
-
进入解压后的目录
cd redis-6.0.6
-
安装
make
如果安装失败,检查是否安装gcc,或者gcc版本是否过低
查看gcc版本
gcc -v
未安装的话安装gcc
yum install gcc
版本过低的话升级gcc
gcc -v #查看gcc版本 yum -y install centos-release-scl # 升级到9.1版本 yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
清除之前make产生的垃圾文件
make distclean
升级完了gcc版本后,再重新make,就不会报错了,执行完成后会提示安装成功
-
配置环境变量
执行安装路径
make install PREFIX=/usr/djh/redis-6.0.6
配置环境变量
vi /etc/profile
export REDIS_HOME=/usr/djh/redis-6.0.6 export PATH=$PATH:${REDIS_HOME}/bin
-
刷新profile文件
source /etc/profile
-
执行utis目录下的 install_server.sh
./install_server.sh
如果提示错误信息:
[root@VM-0-6-centos utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
那么编辑install_server.sh文件
vi ./install_server.sh
注释掉下面这段代码,然后重新执行install_server.sh
#bail if this system is managed by systemd #_pid_1_exe="$(readlink -f /proc/1/exe)" #if [ "${_pid_1_exe##*/}" = systemd ] #then # echo "This systems seems to use systemd." # echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!" # exit 1 #fi
-
重新执行 ./install_server.sh(可以执行一次或多次)
./install_server.sh
一个物理机中可以有多个redis实例,通过port区分
-
提示信息,直接默认
Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/djh/redis-6.0.6/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/djh/redis-6.0.6/bin/redis-server Cli Executable : /usr/djh/redis-6.0.6/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
-
默认已经启动了redis,查看redis状态
[root@iZuf6dr78if7es8xuck0tyZ utils]# cd /etc/init.d/ [root@iZuf6dr78if7es8xuck0tyZ init.d]# ll 总用量 44 -rw-r--r-- 1 root root 18281 5月 22 2020 functions -rwxr-xr-x 1 root root 4569 5月 22 2020 netconsole -rwxr-xr-x 1 root root 7928 5月 22 2020 network -rw-r--r-- 1 root root 1160 2月 3 2021 README -rwxr-xr-x 1 root root 1712 3月 7 15:40 redis_6379 [root@iZuf6dr78if7es8xuck0tyZ init.d]# service redis_6379 status cat: /var/run/redis_6379.pid: No such file or directory Redis is running (16924)
此时redis成系统服务,可以通过 service redis_6379 start/stop/status控制redis服务