溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS 7.x安裝部署Memcached服務(wù)器的詳細(xì)方法

發(fā)布時間:2020-08-19 19:05:08 來源:腳本之家 閱讀:205 作者:osyunwei 欄目:服務(wù)器

操作系統(tǒng):CentOS 7.x 64位

實現(xiàn)目的:安裝部署Memcached服務(wù)器

一、防火墻設(shè)置

CentOS 7.x默認(rèn)使用的是firewall作為防火墻,這里改為iptables防火墻。

1、關(guān)閉firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機(jī)啟動

2、安裝iptables防火墻

yum install iptables-services #安裝

vi /etc/sysconfig/iptables #編輯防火墻配置文件

# 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]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 11211 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重啟防火墻使配置生效

systemctl enable iptables.service #設(shè)置防火墻開機(jī)啟動

/usr/libexec/iptables/iptables.init restart #重啟防火墻

二、關(guān)閉SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注釋掉

#SELINUXTYPE=targeted #注釋掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

三 、系統(tǒng)約定

軟件源代碼包存放位置:/usr/local/src

源碼包編譯安裝位置:/usr/local/軟件名字

四、下載軟件包

1、下載libevent

http://ftp.lfs-matrix.net/pub/blfs/conglomeration/libevent/libevent-2.0.22-stable.tar.gz

2、下載memcached

http://memcached.org/files/memcached-1.4.34.tar.gz

五、安裝編譯工具包

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

六、安裝配置memcached

1、安裝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、安裝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、測試Memcached

groupadd memcached #創(chuàng)建組

useradd -g memcached memcached -s /bin/false #創(chuàng)建賬號

ln -s /usr/local/memcached/bin/memcached /usr/local/bin/memcached #添加軟連接

啟動Memcache的服務(wù)器端的命令為:

/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

或者

/usr/local/memcached/bin/memcached -d -m 4096 -u memcached -l 192.168.4.6 -p 11211 -c 1024

參數(shù)說明:

-d選項是啟動一個守護(hù)進(jìn)程,

-m是分配給Memcache使用的內(nèi)存數(shù)量,單位是MB,這里是4096MB

-u是運(yùn)行Memcache的用戶,比如root或者memcached

-l是監(jiān)聽的服務(wù)器IP地址,這里指定服務(wù)器的IP地址192.168.4.6,不設(shè)置默認(rèn)監(jiān)聽服務(wù)器所有IP地址

-p是設(shè)置Memcache監(jiān)聽的端口,默認(rèn)為11211

-c選項是最大運(yùn)行的并發(fā)連接數(shù),默認(rèn)是1024

-P是設(shè)置保存Memcache的pid文件,/usr/local/memcached/memcached.pid

開機(jī)自啟動,在/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

也可以使用下面的命令:

/usr/local/memcached/bin/memcached -d -m 4096 -p 11211 -u memcached

ip不指定時,默認(rèn)監(jiān)聽本地所有ip地址,用戶最好選擇是非root用戶,例如memcached

關(guān)閉Memcached服務(wù)

cat /usr/local/memcached/memcached.pid #查看進(jìn)程

kill 22856 #結(jié)束進(jìn)程

或者

killall memcached #結(jié)束服務(wù)

系統(tǒng)運(yùn)維 www.osyunwei.com 溫馨提醒:qihang01原創(chuàng)內(nèi)容©版權(quán)所有,轉(zhuǎn)載請注明出處及原文鏈接

4、設(shè)置Memcached開機(jī)啟動

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! #保存退出

chmod 775 /etc/rc.d/init.d/memcached #賦予文件執(zhí)行權(quán)限

chkconfig memcached on #設(shè)置開機(jī)啟動

/etc/rc.d/init.d/memcached start #啟動

至此,Linux下Memcached服務(wù)器部署完成。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI