Redis系列 - Linux中以yum的方式安装redis的rpm包

Redis官网提供的是tar的安装包,通常采用tar的简单方式直接可以将redis安装到直接机器上,但应用到生产环境集群等特殊场景下,还是使用rpm包安装比较好,也可以直接配置到系统服务中,修改配置其中参数,也可以避免服务重启出现配置信息丢失,还得按照原来所需场景来进行配置。对于rpm包可以直接通过rpm ivh xxx命令来安装,也可以通过yum localinstall xxx -y命令来进行安装。
redis的rpm包可以到 http://www.rpmfind.net/linux/rpm2html/search.php?query=redis&submit=Search+…&system=&arch= 进行下载,里面有各个版本的rpm包,本文以redis-3.2.3-1.el7.x86_64.rpm [ftp://195.220.108.108/linux/epel/7/x86_64/r/redis-3.2.3-1.el7.x86_64.rpm ] 为例。

- 下载rpm包:

可以本地下载,之后通过rz 命令来将本地包上传到linux服务器,也可以通过 wget ftp://195.220.108.108/linux/epel/7/x86_64/r/redis-3.2.3-1.el7.x86_64.rpm 将rpm包下载到服务器。
本人采用的第一种方式,直接将rpm包上传到/usr/local/
文件夹下。

- rpm包信息熟悉:

在安装之前,我们可以执行一些rpm命令查询相关信息,
如:
1. 查询未安装的redis包的详细信息

rpm -qf| grep redis

output :

Name : redis
Version : 3.2.3
Release : 1.el7
Architecture: x86_64
Install Date: (not installed)
Group : Unspecified
Size : 2371746
License : BSD
Signature : ——
Source RPM : redis-3.2.3-1.el7.src.rpm
Build Date : Fri 05 Aug 2016 09:24:40 PM CST
Build Host : buildvm-07.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager : Fedora Project
Vendor : Fedora Project
URL : http://redis.io
Summary : A persistent key-value database
Description :
Redis is an advanced key-value store. It is often referred to as a data
structure server since keys can contain strings, hashes, lists, sets and
sorted sets.
You can run atomic operations on these types, like appending to a string;
incrementing the value in a hash; pushing to a list; computing set
intersection, union and difference; or getting the member with highest
ranking in a sorted set.
In order to achieve its outstanding performance, Redis works with an
in-memory dataset. Depending on your use case, you can persist it either
by dumping the dataset to disk every once in a while, or by appending
each command to a log.
Redis also supports trivial-to-setup master-slave replication, with very
fast non-blocking first synchronization, auto-reconnection on net split
and so forth.
Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
limited time-to-live, and configuration settings to make Redis behave like
a cache.
You can use Redis from most programming languages also.

2.查看未安装的redis包中文件未来要安装的位置

rpm -ql redis

output :

/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
/etc/systemd/system/redis.service.d/limit.conf
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
/usr/bin/redis-cli
/usr/bin/redis-sentinel
/usr/bin/redis-server
/usr/bin/redis-shutdown
/usr/lib/systemd/system/redis-sentinel.service
/usr/lib/systemd/system/redis.service
/usr/lib/tmpfiles.d/redis.conf
/usr/share/doc/redis-3.2.3
/usr/share/doc/redis-3.2.3/00-RELEASENOTES
/usr/share/doc/redis-3.2.3/BUGS
/usr/share/doc/redis-3.2.3/CONTRIBUTING
/usr/share/doc/redis-3.2.3/MANIFESTO
/usr/share/doc/redis-3.2.3/README.md
/usr/share/licenses/redis-3.2.3
/usr/share/licenses/redis-3.2.3/COPYING
/var/lib/redis
/var/log/redis
/var/run/redis

拓展:

Linux系统文件夹含义:
1、/etc/ 存放配置文件,系统配置文件 许多网络配置文件
var - 包括系统一般运行时要改变的数据.每个系统是特定的,即不通过网络与其他计算机共享.
2、/var/lib/ 系统正常运行时要改变的文件.
3、/var/run/ 保存到下次引导前有效的关于系统的信息文件.例如, /var/run/utmp 包含当前登录的用户的信息.
4、/var/log/ 各种程序的Log文件,特别是login (/var/log/wtmp log所有到系统的登录和注销)
和syslog (/var/log/messages 里存储所有核心和系统程序信息. /var/log 里的文件经常不确定地增长,
应该定期清除.
usr ——文件系统经常很大,因为所有程序安装在这里.
5、/usr/bin/ 几乎所有用户命令.有些命令在/bin 或/usr/local/bin 中.
6、/usr/share/ 放置共享文件的地方
7、/usr/lib/ 程序或子系统的不变的数据文件,包括一些site-wide配置文件.名字lib来源于库(library);
编程的原始库存在/usr/lib 里.
8、/usr/local/ 本地安装的软件和其他文件放在这里.

RPM 相关操作:http://man.linuxde.net/rpm
1、rpm -ql redis 查找已经安装的rpm包的安装目录
2、rpm -ivh your-package.rpm 安装rpm包
3、rpm -Uvh xxx 升级一个包
4、rpm -e xxx 移走一个包
5、rpm -q < rpm package name> 查询一个包是否被安装
6、rpm -qi < rpm package name> 得到被安装的包的信息
7、rpm -ql < rpm package name> 列出该包中有哪些文件
8、rpm -qf 列出服务器上的一个文件属于哪一个RPM包
9、rpm -qa 列出所有被安装的rpm package
10、rpm -qilp < rpm package name> 列出一个未被安装进系统的RPM包文件中包含有哪些文件

3.查看未安装包redis所需要依赖的全部包信息

rpm -qRp redis-3.2.3-1.el7.x86_64.rpm

output :

/bin/awk
/bin/bash
/bin/sh
/bin/sh
/bin/sh
/bin/sh
config(redis) = 3.2.3-1.el7
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.2)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libc.so.6(GLIBC_2.6)(64bit)
libc.so.6(GLIBC_2.7)(64bit)
libdl.so.2()(64bit)
libjemalloc.so.1()(64bit)
libm.so.6()(64bit)
libm.so.6(GLIBC_2.2.5)(64bit)
libpthread.so.0()(64bit)
libpthread.so.0(GLIBC_2.2.5)(64bit)
libpthread.so.0(GLIBC_2.3.2)(64bit)
logrotate
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
shadow-utils
systemd
systemd
systemd
rpmlib(PayloadIsXz) <= 5.2-1

- 安装:

RPM安装方式:
在安装时,可以看到安装时需要包依赖;

rpm -ivh redis-3.2.3-1.el7.x86_64.rpm

yum方式安装:
先查看是否已经存在:

rpm -qa | grep redis

如果存在,将存在的卸载:(-y 代表自动选择)

yum remove xxx -y

使用yum安装本地redis的rpm包

yum localinstall redis-3.2.3-1.el7.x86_64.rpm -y

安装成功之后,可以检测一下安装好之后的目录:

rpm -ql redis #查找已经安装的rpm包的安装目录

output :

/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
/etc/systemd/system/redis.service.d/limit.conf
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
/usr/bin/redis-cli
/usr/bin/redis-sentinel
/usr/bin/redis-server
/usr/bin/redis-shutdown
/usr/lib/systemd/system/redis-sentinel.service
/usr/lib/systemd/system/redis.service
/usr/lib/tmpfiles.d/redis.conf
/usr/share/doc/redis-3.2.3
/usr/share/doc/redis-3.2.3/00-RELEASENOTES
/usr/share/doc/redis-3.2.3/BUGS
/usr/share/doc/redis-3.2.3/CONTRIBUTING
/usr/share/doc/redis-3.2.3/MANIFESTO
/usr/share/doc/redis-3.2.3/README.md
/usr/share/licenses/redis-3.2.3
/usr/share/licenses/redis-3.2.3/COPYING
/var/lib/redis
/var/log/redis
/var/run/redis

查看已安装的redis版本:

[root@aidev04 soft]# redis-cli --version
redis-cli 3.2.3
  • 启动:
systemctl start redis.service
  • 查看启用状态:
systemctl status redis.service

设置开机启动

systemctl enable redis.service

显示所有已启动的服务

systemctl list-units --type=service

你可能感兴趣的:(Redis)