Linux install memcached service
1. Prepare the installation files
Download the installation files for memcached and libevent
libevent-2.0.21-stable.tar.gz
memcached-server-1.4.31.tar.gz
2. Specific installation steps
1. Since memcached depends on libevent, libevent needs to be installed. Since the linux system may have libevent installed by default, execute the command:
rpm -qa|grep libevent
Check whether the system has the installation software, and if so, execute the command:
rpm -e libevent-1.4.13-4.el6.x86_64 --nodeps (due to the old version that comes with the system, ignore the dependency deletion)
3. Install libevent command:
[root@localhost mysoft]# tar -zxvf libevent-2.0.21-stable.tar.gz [root@localhost mysoft]# cd libevent-2.0.21-stable[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent[root@localhost libevent-2.0.21-stable]# make[root@localhost libevent-2.0.21-stable]# make install
So far libevent is installed;
During the installation process: configure: error : no acceptable C compiler found in $PATH error is not installed gcc, run the following command:
yum install gcc* make*
4. Install the memcached command:
[root@localhost mysoft]# tar -zxvf memcached-1.4.31.tar.gz [root@localhost memcached-1.4.31]# cd memcached-1.4.31[root@localhost memcached-1.4.31]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/[root@localhost memcached-1.4.31]# make[root@localhost memcached-1.4.31]# make install
5. libevent.so is often not found when memcached is started; it can be checked by the following command:
Enter the /usr/local/memcached/bin directory
LD_DEBUG=help
./memcached -v
LD_DEBUG=libs ./ memcached -v
Workaround:
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5
6. Start memcached
1. Open a terminal and enter the following command:
./usr/local/memcached/bin/memcached -d -m 256 -u root -l 192.168.1.1 -p 11211 -c 1024 –P /tmp/memcached .pid
7. Write a startup script
#!/bin/sh # # memcached: MemCached Daemon # # chkconfig: - 90 25 # description: MemCached Daemon # # Source function library. . /etc/rc.d/init.d/functions . /etc/sysconfig/network start() { echo -n $"Starting memcached: " daemon /usr/local/memcached/bin/memcached -d -m 256 -u root -l 10.26.240.137 -p 11211 -c 1024 -P /tmp/memcached.pid echo } stop() { echo -n $"Shutting down memcached: " killproc memcached echo } [ -f /usr/local/bin/memcached ] || exit 0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart|reload) stop start ;; condrestart) stop start ;; *) echo $"Usage: $0 {start|stop|restart|reload|condrestart}" exit 1 esac exit 0
8. Added services
[root@localhost ~]# chkconfig --add memcached
[root@localhost ~]# chkconfig --level 235 memcached on
[root@localhost ~]# chkconfig --list | grep mem
memcached 0:off 1:off 2:on 3:on 4:off 5:on 6:off
Next, you can start and stop memcached with the following commands
/etc/rc.d/init.d/memcached start ## start
/etc/rc.d/init.d/memcached stop ## stop
/etc/rc.d/init.d/memcached restart ## restart
[root@localhost ~]# /etc/rc.d/init.d/memcached restart
Shutting down memcached: [ OK ]
Starting memcached: [ OK ]
Description of startup parameters:
The -d option is to start a daemon process.
-u root indicates that the user who started memcached is root.
-m is the amount of memory allocated to Memcache in MB, the default is 64MB.
-M return error on memory exhausted (rather than removing items).
-u is the user running Memcache. If the current user is root, you need to use this parameter to specify the user.
-p is to set the TCP listening port of Memcache, preferably a port above 1024.
The -c option is the maximum number of concurrent connections to run, the default is 1024.
-P is set to save the pid file of Memcache.
-l is the listening server IP address. If there are multiple addresses, I have specified the server IP address 192.168.0.200 here.
0 Comments