1. 程式人生 > >Redhat/CentOS下yum完美配置方案(順帶yum安裝memcached)

Redhat/CentOS下yum完美配置方案(順帶yum安裝memcached)

看到好多筒子們yum安裝memcached不成功,不幸的是,我也遇到了,由於各種原因,花了七八個小時才搞定。

看罈子裡好多筒子都有貼處理經驗,貌似不是很詳細徹底,我索性總結下,希望大家少走彎路。

條條大道通羅馬,但是最順暢的只有一條。。。

我的系統版本為:rhel5.3 32

如果你用的是Redhat,或者是CentOS,那你可能會碰到以下兩種情況導致你yum安裝memcached失敗:

  1. [[email protected] ~]# yum install memcached
  2. Loaded plugins: rhnplugin, security
  3. This system is not registered with RHN.
  4. RHN support will be disabled.
  5. Setting up Install Process
  6. No package memcached available.
  7. Nothing to do
複製程式碼 或者:

  1. [[email protected] ~]# yum install memcached
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Setting up Install Process
  5. No package memcached available.
  6. Nothing to do
複製程式碼

CentOS不註冊的話,yum是用不了,Redhat即使註冊了,貌似yum還是用不了。不知道rhel官方yum源是不是要另外收費的?哪位筒子給我掃下盲。。

可以嘗試一下以下方法:

如果是CentOS,或者遇到第二個錯誤,可以直接跳到步驟8,如果是Redhat,或者遇到第一個錯誤,需要按著順序一步一步來。其他系統,不確定。

步驟1-7就是將Redhat中的yum改為CentOS的yum。


1
、先檢視下系統當前yum服務的相關的包:

  1. [[email protected] ~]# rpm -qa|grep yum
  2. yum-updatesd-0.9-2.el5
  3. yum-metadata-parser-1.1.2-2.el5
  4. yum-3.2.19-18.el5
  5. yum-security-1.1.16-13.el5
  6. yum-rhn-plugin-0.5.3-30.el5
複製程式碼


2
、解除安裝這些包:

  1. [[email protected] ~]# rpm -qa|grep yum|xargs rpm -e --nodeps
複製程式碼


3
、下載新的yum包:

  1. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-3.2.22-39.el5.centos.noarch.rpm
  2. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
  3. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
複製程式碼

注意:有可能會碰到版本更改導致找到不到源,可以進到官網上確認下:

  1. http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/
複製程式碼

如果過是64位系統,則i386要改為x86_64,貌似,這個沒什麼好說的,你懂的。。

log
如下:

  1. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-3.2.22-39.el5.centos.noarch.rpm
  2. --16:03:37--  http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-3.2.22-39.el5.centos.noarch.rpm
  3. Resolving centos.ustc.edu.cn... 202.141.160.110, 2001:da8:d800:95::110
  4. Connecting to centos.ustc.edu.cn|202.141.160.110|:80... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 1034902 (1011K) [application/x-redhat-package-manager]
  7. Saving to: `yum-3.2.22-39.el5.centos.noarch.rpm'
  8. 100%[====================================================================================>] 1,034,902   29.0K/s   in 34s   
  9. 16:04:28 (29.4 KB/s) - `yum-3.2.22-39.el5.centos.noarch.rpm' saved [1034902/1034902]
  10. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
  11. --16:06:17--  http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
  12. Resolving centos.ustc.edu.cn... 202.141.160.110, 2001:da8:d800:95::110
  13. Connecting to centos.ustc.edu.cn|202.141.160.110|:80... connected.
  14. HTTP request sent, awaiting response... 200 OK
  15. Length: 21033 (21K) [application/x-redhat-package-manager]
  16. Saving to: `yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm'
  17. 100%[====================================================================================>] 21,033      29.9K/s   in 0.7s   
  18. 16:06:48 (29.9 KB/s) - `yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm' saved [21033/21033]
  19. [[email protected] ~]# wget http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
  20. --16:07:35--  http://centos.ustc.edu.cn/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
  21. Resolving centos.ustc.edu.cn... 202.141.160.110, 2001:da8:d800:95::110
  22. Connecting to centos.ustc.edu.cn|202.141.160.110|:80... connected.
  23. HTTP request sent, awaiting response... 200 OK
  24. Length: 26053 (25K) [application/x-redhat-package-manager]
  25. Saving to: `yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm'
  26. 100%[====================================================================================>] 26,053      71.3K/s   in 0.4s   
  27. 16:07:51 (71.3 KB/s) - `yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm' saved [26053/26053]
  28. [[email protected] ~]#
複製程式碼 如上,就表示下載OK了。。


4
、安裝下載的yum包:

  1. [[email protected] ~]# rpm -ivh yum-*
  2. warning: yum-3.2.22-39.el5.centos.noarch.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
  3. Preparing...                ########################################### [100%]
  4.    1:yum-metadata-parser    ########################################### [ 33%]
  5.    2:yum-fastestmirror      ########################################### [ 67%]
  6.    3:yum                    ########################################### [100%]
  7. [[email protected] ~]#
複製程式碼


5
、下載yum配置源:下載到/etc/yum.repos.d/目錄下:

  1. wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo
複製程式碼

詳細操作:

  1. [[email protected] ~]# cd /etc/yum.repos.d/
  2. [[email protected] yum.repos.d]# ll
  3. total 8
  4. -rw-r--r-- 1 root root 254 Dec 16  2008 rhel-debuginfo.repo
  5. [[email protected] yum.repos.d]# mv rhel-debuginfo.repo rhel-debuginfo.repo.bak
  6. [[email protected] yum.repos.d]# wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo
  7. --16:37:58--  http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo
  8. Resolving docs.linuxtone.org... 119.57.20.28
  9. Connecting to docs.linuxtone.org|119.57.20.28|:80... connected.
  10. HTTP request sent, awaiting response... 200 OK
  11. Length: 1426 (1.4K) [application/octet-stream]
  12. Saving to: `CentOS-Base.repo'
  13. 100%[====================================================================================>] 1,426       --.-K/s   in 0s     
  14. 16:38:25 (552 MB/s) - `CentOS-Base.repo' saved [1426/1426]
  15. [[email protected] yum.repos.d]# ll
  16. total 12
  17. -rw-r--r-- 1 root root 1426 May 24  2009 CentOS-Base.repo
  18. -rw-r--r-- 1 root root  254 Dec 16  2008 rhel-debuginfo.repo.bak
複製程式碼

6、執行yum update更新:

PS:不確定這一步,是不是必須的,但是,既然一次性搞,就索性更新一把吧,但是前提是要你網速跟得上,有700M的包要下載。

如果你的寬頻提供商是 中國毛線通訊 ,請慎重!除下載外,安裝也挺久。下載我花了半個小時,安裝花了將近一個小時,懶得等的,可以跳過這一步試試。

一共下載了595個包,更新了1170項。

期間有兩次提示你選擇y/N,輸入y回車即可。

log太多了,只貼個命令:

  1. [[email protected] ~]# yum update
複製程式碼

7、執行yum makecache生成快取:

  1. [[email protected] ~]# yum makecache
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. addons                                                                                                | 1.9 kB     00:00     
  5. addons/other_db                                                                                       |  552 B     00:00     
  6. base                                                                                                  | 1.1 kB     00:00     
  7. base/other                                                                                            |  10 MB     00:39     
  8. base/group                                                                                            | 1.1 MB     00:15     
  9. extras                                                                                                | 2.1 kB     00:00     
  10. extras/other_db                                                                                       | 448 kB     00:05     
  11. extras/group                                                                                          | 9.7 kB     00:00     
  12. update                                                                                                | 1.9 kB     00:00     
  13. update/other_db                                                                                       |  22 MB     01:58     
  14. base                                                                                                               2725/2725
  15. Metadata Cache Created
複製程式碼

8、測試下yum,yum安裝memcached:

  1. [[email protected] ~]# yum search mysql
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. ====================================================== Matched: mysql =======================================================
  5. mod_auth_mysql.i386 : Basic authentication for the Apache web server using a MySQL database.
  6. qt-MySQL.i386 : MySQL drivers for Qt's SQL classes.
  7. MySQL-python.i386 : An interface to MySQL
  8. apr-util-mysql.i386 : APR utility library MySQL DBD driver
  9. bytefx-data-mysql.i386 : MySQL database connectivity for Mono
  10. freeradius-mysql.i386 : MySQL bindings for freeradius
  11. freeradius2-mysql.i386 : MySQL support for freeradius
  12. libdbi-dbd-mysql.i386 : MySQL plugin for libdbi
  13. mysql.i386 : MySQL client programs and shared libraries
  14. mysql-bench.i386 : MySQL benchmark scripts and data
  15. mysql-connector-odbc.i386 : ODBC driver for MySQL
  16. mysql-connector-odbc64.i386 : ODBC driver for MySQL
  17. mysql-devel.i386 : Files for development of MySQL applications
  18. mysql-server.i386 : The MySQL server and related files
  19. mysql-test.i386 : The test suite distributed with MySQL
  20. pdns-backend-mysql.i386 : MySQL backend for pdns
  21. perl-DBD-MySQL.i386 : A MySQL interface for perl
  22. php-mysql.i386 : A module for PHP applications that use MySQL databases.
  23. php-pdo.i386 : A database access abstraction module for PHP applications
  24. php-pear-MDB2-Driver-mysql.noarch : MySQL MDB2 driver
  25. php53-mysql.i386 : A module for PHP applications that use MySQL databases
  26. php53-pdo.i386 : A database access abstraction module for PHP applications
  27. qt4-mysql.i386 : MySQL drivers for Qt's SQL classes
  28. rsyslog.i386 : Enhanced system logging and kernel message trapping daemon
  29. rsyslog-mysql.i386 : MySQL support for rsyslog
  30. unixODBC.i386 : A complete ODBC driver manager for Linux
  31. unixODBC64.i386 : A complete ODBC driver manager for Linux
  32. [[email protected] ~]# yum search memcached
  33. Loaded plugins: fastestmirror
  34. Loading mirror speeds from cached hostfile
  35. ==================================================== Matched: memcached =====================================================
  36. php-pecl-memcache.i386 : Extension to work with the Memcached caching daemon
複製程式碼

可以看到,yum是配置好了,但是貌似找不memchaced,可以再確認下:

  1. [[email protected] ~]# yum install memcached
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Setting up Install Process
  5. No package memcached available.
  6. Nothing to do
複製程式碼 memcached就是安裝不了。

這是因為缺少了擴充套件包 EPEL(Extra Packages for Enterprise Linux),可以用 yum repolist 命令檢查下。

解決方法很簡單,再安裝一個包,

  1. [[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
  2. Retrieving http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
  3. warning: /var/tmp/rpm-xfer.DFnB18: Header V3 DSA signature: NOKEY, key ID 217521f6
  4. Preparing...                ########################################### [100%]
  5.    1:epel-release           ########################################### [100%]
複製程式碼 我的系統版本5,如果是6的話,執行這一句:

  1. rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
複製程式碼
  1. [[email protected] ~]# yum repolist
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.ustc.edu.cn
  5. repo id repo name status
  6. addons CentOS-5 - Addons 0
  7. base CentOS-5 - Base 2,725
  8. epel Extra Packages for Enterprise Linux 5 - i386 5,873
  9. extras CentOS-5 - Extras 286
  10. update CentOS-5 - Updates 993
  11. repolist: 9,877
複製程式碼 出現 epel Extra Packages for Enterprise Linux 5 - i386 5,873 即表示epel安裝成功。

再次安裝memcached:

  1. [[email protected] ~]# yum install memcached
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirrors.ustc.edu.cn
  5. epel                                                                                                  | 3.7 kB     00:00     
  6. epel/primary_db                                                                                       | 3.1 MB     00:03     
  7. Setting up Install Process
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package memcached.i386 0:1.4.5-1.el5 set to be updated
  11. --> Finished Dependency Resolution
  12. Dependencies Resolved
  13. =============================================================================================================================
  14. Package                        Arch                      Version                            Repository                 Size
  15. =============================================================================================================================
  16. Installing:
  17. memcached                      i386                      1.4.5-1.el5                        epel                       71 k
  18. Transaction Summary
  19. =============================================================================================================================
  20. Install       1 Package(s)
  21. Upgrade       0 Package(s)
  22. Total download size: 71 k
  23. Is this ok [y/N]: y
  24. Downloading Packages:
  25. memcached-1.4.5-1.el5.i386.rpm                                                                        |  71 kB     00:02     
  26. warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6
  27. epel/gpgkey                                                                                           | 1.7 kB     00:00     
  28. Importing GPG key 0x217521F6 "Fedora EPEL <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
  29. Is this ok [y/N]: y
  30. Running rpm_check_debug
  31. Running Transaction Test
  32. Finished Transaction Test
  33. Transaction Test Succeeded
  34. Running Transaction
  35.   Installing     : memcached                                                                                             1/1
  36. Installed:
  37.   memcached.i386 0:1.4.5-1.el5                                                                                               
  38. Complete!
複製程式碼
9、測試下memcached的使用:
1)、啟動服務:
  1. [[email protected] ~]# /etc/rc.d/init.d/memcached start
  2. Starting memcached:                                        [  OK  ]
複製程式碼 啟動是OK的,可以再確認下程序是否啟動:
  1. [[email protected] ~]# pstree
  2. ...
  3. ├─memcached───5*[{memcached}]
  4. ...
複製程式碼 看到memcached服務已經啟動了,也可以通過ps aux|grep命令確認:
  1. [[email protected] ~]# ps aux|grep memcached
  2. 101      24352  0.0  0.0  54356   684 ?        Ssl  11:49   0:00 memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached/memcached.pid
  3. root     24457  0.0  0.0   4020   712 pts/3    S+   11:52   0:00 grep memcached
複製程式碼 2)、連線並測試memcached:
  1. [[email protected] ~]# telnet 127.0.0.1 11211
  2. Trying 127.0.0.1...
  3. Connected to localhost.localdomain (127.0.0.1).
  4. Escape character is '^]'.
  5. set test 0 0 4
  6. tttt
  7. STORED
  8. get test
  9. VALUE test 0 4
  10. tttt
  11. END
複製程式碼 memcached執行正常。


至此,yum配置成功,yum安裝memcached成功。

From:http://f.dataguru.cn/forum.php?mod=viewthread&tid=44212&fromuid=4771