Detailed methods for CentOS 7.x installation and deployment of Memcached server
Operating system: CentOS 7.x 64 bit
Achieve purpose: install and deploy Memcached server
I. Firewall settings
CentOS 7.x uses firewall as the firewall by default, which is changed to iptables firewall here.
1. Close firewall:
Systemctl stop firewalld.service # stop firewall
Systemctl disable firewalld.service # prevents firewall from booting
2. Install iptables firewall
Yum install iptables-services # installation
Vi / etc/sysconfig/iptables # Editing Firewall profile
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
* filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-An INPUT-m state-- state RELATED,ESTABLISHED-j ACCEPT
-An INPUT-p icmp-j ACCEPT
-An INPUT-I lo-j ACCEPT
-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 22-j ACCEPT
-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 11211-j ACCEPT
-An INPUT-j REJECT-- reject-with icmp-host-prohibited
-A FORWARD-j REJECT-- reject-with icmp-host-prohibited
COMMIT
: wq! # Save exit
Systemctl restart iptables.service # finally restart the firewall to make the configuration effective
Systemctl enable iptables.service # set the firewall to boot
/ usr/libexec/iptables/iptables.init restart # restart the firewall
2. Close SELINUX
Vi / etc/selinux/config
# SELINUX=enforcing # comment out
# SELINUXTYPE=targeted # comment out
SELINUX=disabled # increased
: wq! # Save exit
Setenforce 0 # makes the configuration effective immediately
III. System agreement
Software source code package location: / usr/local/src
Source package compilation installation location: / usr/local/ software name
Download the software package
1. Download libevent
Http://ftp.lfs-matrix.net/pub/blfs/conglomeration/libevent/libevent-2.0.22-stable.tar.gz
2. Download memcached
Http://memcached.org/files/memcached-1.4.34.tar.gz
Fifth, install the compilation kit
Yum install-y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib * nasm nasm* wget zlib-devel
6. Install and configure memcached
1. Install libevent
Cd / usr/local/src
Tar zxvf libevent-2.0.22-stable.tar.gz
Cd libevent-2.0.22-stable
. / configure-- prefix=/usr/local/libevent
Make
Make install
2. Install memcached
Cd / usr/local/src
Tar zxvf memcached-1.4.34.tar.gz
Cd memcached-1.4.34
. / configure-- enable-sasl-- prefix=/usr/local/memcached-with-libevent=/usr/local/libevent
Make
Make install
3. Test Memcached
Groupadd memcached # create a group
Useradd-g memcached memcached-s / bin/false # create an account
Ln-s / usr/local/memcached/bin/memcached / usr/local/bin/memcached # add soft connection
The command on the server side that starts Memcache is:
/ usr/local/memcached/bin/memcached-d-m 4096-u root-l 192.168.4.6-p 11211-c 1024-P / usr/local/memcached/memcached.pid
Or
/ usr/local/memcached/bin/memcached-d-m 4096-u memcached-l 192.168.4.6-p 11211-c 1024
Parameter description:
The-d option is to start a daemon
-m is the amount of memory allocated to Memcache, in MB, here is 4096MB
-u is the user running Memcache, such as root or memcached
-l is the IP address of the listening server. The IP address of the server is specified here, and all IP addresses of the default listening server are not set.
-p is the port on which Memcache snooping is set. Default is 11211.
The-c option is the maximum number of concurrent connections running. The default is 1024.
-P is the pid file set to save Memcache, / usr/local/memcached/memcached.pid
Boot automatically, add a line in / etc/rc.d/rc.local
/ usr/local/memcached/bin/memcached-d-m 4096-u root-l 192.168.4.6-p 11211-c 1024-P / usr/local/memcached/memcached.pid
You can also use the following command:
/ usr/local/memcached/bin/memcached-d-m 4096-p 11211-u memcached
When ip is not specified, all local ip addresses are listened to by default. Users had better choose non-root users, such as memcached.
Turn off the Memcached service
Cat / usr/local/memcached/memcached.pid # View process
Kill 22856 # end the process
Or
Killall memcached # end of service
System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content ©all rights reserved, reprint please indicate the source and the original link
4. Set Memcached to boot.
Vi / etc/rc.d/init.d/memcached
#! / bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig:-90 25
# description: MemCached Daemon
#
# Source function library.
. / etc/rc.d/init.d/functions
. / etc/sysconfig/network
MEMCACHED= "/ usr/local/memcached/bin/memcached"
Start ()
{
Echo-n $"Starting memcached:"
Daemon $MEMCACHED-u memcached-d-m 4096-p 11211-c 1024
Echo
}
Stop ()
{
Echo-n $"Shutting down memcached:"
Killproc memcached
Echo
}
[- f $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
: wq! # Save exit
Chmod 775 / etc/rc.d/init.d/memcached # gives file execution permissions
Chkconfig memcached on # set boot up
/ etc/rc.d/init.d/memcached start # launch
At this point, the deployment of Memcached server under Linux is complete.