首页 > 代码库 > 非root安装Memcached

非root安装Memcached

1,     安装依赖包

确保服务器中已经安装了Memcached的依赖包。

[root@localhost~]#yum-y install  
--skip-broken gcc gcc-c++autoconf automake zlib zlib-devel 
 pcre-developenssl-devel libevent libevent-devel.x86_64


 

 

2,     创建Memcached的安装用户

[root@localhost~]# groupadd dfhapp
[root@localhost~]# useradd  -d /home/dfhapp -g dfhappdfhapp
[root@localhost~]# passwd dfhapp
更改用户 nginx 的密码。
新的密码:
无效的密码:过于简单化/系统化
无效的密码:过于简单
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。


 

3,     下载源码包

#不可把源码包放在/root目录下
[root@localhost/]# mkdir -p /soft
[root@localhost/]# cd soft/
[root@localhostsoft]#wget http://www.memcached.org/files/memcached-1.4.10.tar.gz
[root@localhostsoft]# ll
总用量 308
-rw-r--r--.1 root root 311926 5月  20 01:21 memcached-1.4.10.tar.gz
#解压
[root@localhostsoft]# tar -zxvf memcached-1.4.10.tar.gz 
#赋权
[root@localhostsoft]# mkdir -p /usr/local/memcached
[root@localhostsoft]# chown -R dfhapp:dfhapp   /usr/local/memcached
[root@localhostsoft]# chown -R dfhapp:dfhapp  /soft/memcached-1.4.10


4,     切换dfhapp用户进行安装

#切换用户
[root@localhost~]# su dfhapp
#安装
[dfhapp@localhostmemcached-1.4.10]$ ./configure --prefix=/usr/local/memcached
[dfhapp@localhostmemcached-1.4.10]$ make && make test
[dfhapp@localhostmemcached-1.4.10]$ make install


 

 

5,     dfhapp用户启动Memcached

[dfhapp@localhostmemcached-1.4.10]$ cd /usr/local/memcached/
[dfhapp@localhostmemcached]$ ll
总用量 12
drwxr-xr-x.2 dfhapp dfhapp 4096 6月  15 22:58 bin
drwxr-xr-x.3 dfhapp dfhapp 4096 1月   6 09:30 include
drwxr-xr-x.3 dfhapp dfhapp 4096 1月   6 09:30 share
[dfhapp@localhostmemcached]$ cd bin/
[dfhapp@localhostbin]$ ll
总用量 280
-rwxr-xr-x.1 dfhapp dfhapp 286459 6月  15 22:58 memcached
#启动
[dfhapp@localhostbin]$ ./memcached -d -m 512 -p 11211 -c 256 -P /var/run/memcached.pid


 

 

6,     测试Memcached是否安装成功

[dfhapp@localhostbin]$ telnet 127.0.0.1 11211
Trying127.0.0.1...
Connectedto 127.0.0.1.
Escapecharacter is ‘^]‘.
 
ERROR
 
 
ERROR
settest 8 8 8
12345678
STORED
 
stats
STATpid 8751
STATuptime 54
STATtime 1402844424
STATversion 1.4.10
STATlibevent 1.4.13-stable
STATpointer_size 64
STATrusage_user 0.000000
STATrusage_system 0.044993
STATcurr_connections 10
STATtotal_connections 11
STATconnection_structures 11
STATreserved_fds 20
STATcmd_get 1
STATcmd_set 1
STATcmd_flush 0
STATcmd_touch 0
STATget_hits 0
STATget_misses 1
STATdelete_misses 0
STATdelete_hits 0
STATincr_misses 0
STATincr_hits 0
STATdecr_misses 0
STATdecr_hits 0
STATcas_misses 0
STATcas_hits 0
STATcas_badval 0
STATtouch_hits 0
STATtouch_misses 0
STATauth_cmds 0
STATauth_errors 0
STATbytes_read 68
STATbytes_written 83
STATlimit_maxbytes 536870912
STATaccepting_conns 1
STATlisten_disabled_num 0
STATthreads 4
STATconn_yields 0
STAThash_power_level 16
STAThash_bytes 524288
STAThash_is_expanding 0
STATexpired_unfetched 0
STATevicted_unfetched 0
STATbytes 0
STATcurr_items 0
STATtotal_items 1
STATevictions 0
STATreclaimed 0
END


 

 

7,     制作Memcached启动脚本

[dfhapp@localhost root]$ cd /home/dfhserver/
[dfhapp@localhost ~]$ vim memcached.sh 
 
/usr/local/memcached/bin/memcached -d -m 512 -p11211 -c 256 -P /var/run/memcached.pid
[dfhapp@localhost ~]$ chmod +x memcached.sh


 

 

8,     dfhapp开机启动Memcached

[root@localhost~]# vim /etc/rc.d/rc.local
 
#!/bin/sh
#
#This script will be executed *after* all the other init scripts.
#You can put your own initialization stuff in here if you don‘t
#want to do the full Sys V style init stuff.
 
touch/var/lock/subsys/local
                
su –  dfhapp -c /home/dfhserver/memcached.sh


 

9,     测试是否成功

如果条件允许,最好重启服务器验证一下。

[root@localhost~]# shutdown -r now


重启后。

[root@localhost~]# ps -ef |grep memcached
501       1832     1  017:27 ?        00:00:00/usr/local/memcached/bin/memcached -d -m 512 -p 11211 -c 256 -P/var/run/memcached.pid
root      2522 2499  0 17:29 pts/1    00:00:00 grep memcached
[root@localhost~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTPUser:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:Systemmessage bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxduser:/:/sbin/nologin
vcsa:x:69:69:virtualconsole memory owner:/dev:/sbin/nologin
rpc:x:32:32:RpcbindDaemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:AvahiIPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPCService User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HALdaemon:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:"Saslauthduser":/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
pulse:x:497:496:PulseAudioSystem Daemon:/var/run/pulse:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
mzsx:x:500:500:mzsx:/home/mzsx:/bin/bash
dfhapp:x:501:501::/home/ dfhapp:/bin/bash


 


本文出自 “梦朝思夕” 博客,请务必保留此出处http://qiangmzsx.blog.51cto.com/2052549/1413984