CentOS 7 編譯安裝 memcached

一直以來都被yum養壞了
這次自己從memcached官網下載最新版來玩玩

版本是 memcached v1.4.21  (2014-10-12 release)

因為是新裝好的CentOS 7,先來更新yum
#yum update

相依元件


安裝libevent
#yum install libevent

安裝memcached


下載memcached到/tmp,解開
#cd /tmp
#wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
#tar -zxvf memcached-1.4.21.tar.gz
#cd memcached-1.4.21
編譯安裝
#./configure
#make
#make install
預設位置會被丟到 /usr/local/bin
[root@localhost bin]# ll | grep memcached
-rwxr-xr-x. 1 root root 406508 Dec  1 20:23 memcached
[root@localhost bin]# pwd
/usr/local/bin
複製包裝裡面寫好的Script出來,觀察他
#cp /tmp/memcached-1.4.21/scripts/start-memcached /usr/local/bin/start-memcached
#cat /usr/local/bin/start-memcached
發現裡面的位置怪怪的,而且還少一個memcached.conf
這個conf檔也可以不用寫,從memcached可以直接執行
只要帶參數就好了,詳細的參數用memcached -h 可以看到

不過為了方便,我還是補齊這個檔案
#touch /etc/memcached.conf
#vi /etc/memcached.conf
複製別人寫好的conf
# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.
-d

# Log memcached's output to /var/log/memcached
logfile /var/log/memcached.log

# Be verbose
# -v

# Be even more verbose (print client commands as well)
# -vv

# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m 64

# Default connection port is 11211
-p 11211
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u memcache

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l 127.0.0.1

# Limit the number of simultaneous incoming connections. The daemon default is 1024
# -c 1024

# Lock down all paged memory. Consult with the README and homepage before you do this
# -k

# Return error when memory is exhausted (rather than removing items)
-M

# Maximize core file limit
# -r
然後把start-memcached的內容修改一下
my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
my $memcached = "/usr/local/bin/memcached";
這兩行改到正確的位置上
執行!檢查!
#./usr/local/bin/start-memcached 
#netstat -napto
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2371/master          off (0.00/0/0)
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      4814/memcached       off (0.00/0/0)
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1409/sshd            off (0.00/0/0)
tcp        0     52 192.168.25.131:22       192.168.25.1:49982      ESTABLISHED 2470/sshd: wei [pri  on (0.35/0/0)
tcp6       0      0 ::1:25                  :::*                    LISTEN      2371/master          off (0.00/0/0)
tcp6       0      0 :::22                   :::*                    LISTEN      1409/sshd            off (0.00/0/0)
很好 11211 port被memcached吃住了
打完收工!

留言