一、前言
最近正在學習redis,但是在安裝redis的時候遇到很多坎,在此記錄一下。
硬件環境:我用 VMware Workstation Pro 12 安裝 Red Hat Enterprise Linux 7
終端工具:SecureCRT 5
軟件版本:redis-3.0.0.tar.gz
二、遇到的問題及解決
當進入解壓(tar -zxvf *)后的 redis-3.0.0,執行 make 編譯命令時,提示 gcc 未安裝。所以開始着手安裝 gcc ,通過搜索網上相關資料,
嘗試用 yum install gcc 進行安裝,但提示我未找到相關的源。如下
[root@localhost ~]# yum install gcc
已加載插件:product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
沒有已啟用的源。
后來通過該資料(地址:http://itgeeker.net/centos-7-epel-china-mirror-repository/)找到了解決辦法。
1、安裝源(上海交大源)。如下:
[root@localhost ~]# rpm -Uvh http://ftp.sjtu.edu.cn/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
獲取http://ftp.sjtu.edu.cn/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
警告:/var/tmp/rpm-tmp.wfieOF: 頭V3 RSA/SHA256 Signature, 密鑰 ID 352c64e5: NOKEY
准備中... ################################# [100%]
正在升級/安裝...
1:epel-release-7-5 ################################# [100%]
2、配置EPEL源(EPEL 是yum的一個軟件源,里面包含了許多基本源里沒有的軟件。)
#刪除自帶的文件,再新建
[root@localhost ~]# rm /etc/yum.repos.d/epel.repo
rm:是否刪除普通文件 "/etc/yum.repos.d/epel.repo"?y
[root@localhost ~]# vi /etc/yum.repos.d/epel.repo
##在新建的文件中添加以下配置信息
[epel] name=Extra Packages for Enterprise Linux 7 - $basearch baseurl=http://ftp.sjtu.edu.cn/fedora/epel/7/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - $basearch - Debug baseurl=http://ftp.sjtu.edu.cn/fedora/epel/7/$basearch/debug #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1 [epel-source] name=Extra Packages for Enterprise Linux 7 - $basearch - Source baseurl=http://ftp.sjtu.edu.cn/fedora/epel/7/SRPMS #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1
##清空自帶的文件
[root@localhost ~]# true > /etc/yum.repos.d/epel-testing.repo
[root@localhost ~]# vi /etc/yum.repos.d/epel-testing.repo
#在該文件中復制以下內容
[epel-testing] name=Extra Packages for Enterprise Linux 7 - Testing - $basearch baseurl=http://ftp.sjtu.edu.cn/fedora/epel/testing/7/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-epel7&arch=$basearch failovermethod=priority enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-testing-debuginfo] name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Debug baseurl=http://ftp.sjtu.edu.cn/fedora/epel/testing/7/$basearch/debug #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1 [epel-testing-source] name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Source baseurl=http://ftp.sjtu.edu.cn/fedora/epel/testing/7/SRPMS #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1
以上的操作,就已經替換好上海交大源的文件。
(1)檢查源是否已添加
[root@localhost ~]# yum repolist
(2)運行命令生成緩存(yum makecache就是把服務器的包信息下載到本地電腦緩存起來)
[root@localhost ~]# yum clean all && yum makecache
3、通過博文(地址: http://blog.chinaunix.net/uid-20729583-id-2972852.html)的啟發,配置CentOS
(1)配置yum更新源
#創建/etc/yum.repos.d/CentOS-Base.repo文件,定義yum更新源,這里使用的是上海交大的CentOS更新源
[root@linux-a ~]# vi /etc/yum.repos.d/CentOS-Base.repo
#在新建的文件中添加以下配置信息
[base] name=CentOS-7-Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever7&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://ftp.sjtu.edu.cn/centos/7/os/$basearch/ gpgcheck=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7 #released updates [update] name=CentOS-7-Updates #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates baseurl=http://ftp.sjtu.edu.cn/centos/7/updates/$basearch/ gpgcheck=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7 #packages used/produced in the build but not released [addons] name=CentOS-7-Addons #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons #baseurl=http://ftp.sjtu.edu.cn/centos/7/addons/$basearch/
baseurl=http://ftp.sjtu.edu.cn/centos/7/os/$basearch/ gpgcheck=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7 #additional packages that may be useful [extras] name=CentOS-7-Extras #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras baseurl=http://ftp.sjtu.edu.cn/centos/7/extras/$basearch/ gpgcheck=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-7-Plus #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=centosplus baseurl=http://ftp.sjtu.edu.cn/centos/7/centosplus/$basearch/ gpgcheck=0 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7 #contrib - packages by Centos Users [contrib] name=CentOS-7-Contrib #mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=contrib baseurl=http://ftp.sjtu.edu.cn/centos/7/contrib/$basearch/ gpgcheck=0 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos7
(2)導入key配置yum
[root@localhost ~]# rpm --import http://ftp.sjtu.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
注意:
<1>如果有高版本的linux,比如linux8,只要將CentOS-Base.repo和key中的版本號替換成8即可;
<2>如果遇到 http://mirrors.sohu.com/centos/7/addons/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found 錯誤,
可以根據給出的鏈接 baseurl=http://ftp.sjtu.edu.cn/centos/7/addons/$basearch/ 排查,找到 repomd.xml 正確的路徑。經查知,正確路徑是:
baseurl=http://ftp.sjtu.edu.cn/centos/7/os/$basearch/
綜上操作,已完成yum的配置安裝,然后通過yum進行安裝gcc。
4、安裝gcc
[root@localhost ~]# yum install gcc
5、安裝redis
#在 redis-3.0.0目錄下執行make命令
[root@localhost redis-3.0.0]# make
#進入src目錄
[root@localhost redis-3.0.0]# cd src
[root@localhost src]# make install
至此,redis才安裝成功。