Home php教程 php手册 Linux下Memcache服务器端的安装

Linux下Memcache服务器端的安装

May 25, 2016 pm 04:39 PM
memcache

服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.3.0.

下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz

另外,memcache用到了libevent这个库用于socket的处理,所以还需要安装libevent,libevent的最新版本是libevent-1.3。(如果你的系统已经安装了libevent,可以不用安装)

官网:http://www.monkey.org/~provos/libevent/

下载:http://www.monkey.org/~provos/libevent-1.3.tar.gz

用wget指令直接下载这两个东西.下载回源文件后。

1.先安装libevent。这个东西在配置时需要指定一个安装路径,即./configure -prefix=/usr;然后make;然后make install;

2.再安装memcached,只是需要在配置时需要指定libevent的安装路径即./configure -with-libevent=/usr;然后make;然后make install;

这样就完成了linux下memcache服务器端的安装,详细的方法如下:

1.分别把memcached和libevent下载回来,放到 /tmp 目录下:

# cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
Copy after login

2.先安装libevent:

# tar zxvf libevent-1.2.tar.gz
# cd libevent-1.2
# ./configure -prefix=/usr
# make
# make install
Copy after login

注:在这里执行的时候出现错误:

1,no acceptable c compiler found in $path

由于centos默认没有安装gcc,使用yum安装

#yum install gcc* make*

3.测试libevent是否安装成功:

# ls -al /usr/lib | grep libevent 
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3 
-rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3 
-rw-r-r- 1 root root 454156 11?? 12 17:38 libevent.a 
-rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la 
lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
Copy after login

还不错,都安装上了.

4.安装memcached,同时需要安装中指定libevent的安装位置:

# cd /tmp 
# tar zxvf memcached-1.2.0.tar.gz 
# cd memcached-1.2.0 
# ./configure -with-libevent=/usr 
# make 
# make install
Copy after login

如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径.

注:安装的时候出现错误:

1 linux警告:检测到时钟错误,您的创建可能是不完整的.

解决方法:

修改当前时间:

[root]#date -s '2010/11/5 8:01:00 '

将当前系统时间写入cmos中去

#clock -w

)

安装完成后会把memcached放到 /usr/local/bin/memcached.

5.测试是否成功安装memcached:

# ls -al /usr/local/bin/mem*

-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached

-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug

安装memcache的php扩展

1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。

2.安装php的memcache扩展

tar vxzf memcache-2.2.1.tgz 
cd memcache-2.2.1 
/usr/local/php/bin/phpize 
./configure -enable-memcache -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir 
make 
make install
Copy after login

注:

1 phpize没有找到

解决方法:

centos是默认没有安装php-devel的

yum install php-devel

2 make: *** [memcache.lo] error 1

没有安装zlib

yum install zlib-devel

3 配置的命令改为:./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir 其中enable和with前面是两个--

3.上述安装完后会有类似这样的提示:

installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/

4.把php.ini中的extension_dir = "./"修改为

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/"

5.添加一行来载入memcache扩展:extension=memcache.so

memcached的基本设置:

1.启动memcache的服务器端:

# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -p /tmp/memcached.pid

-d选项是启动一个守护进程,

-m是分配给memcache使用的内存数量,单位是mb,我这里是10mb,

-u是运行memcache的用户,我这里是root,

-l是监听的服务器ip地址,如果有多个地址的话,我这里指定了服务器的ip地址192.168.0.200,

-p是设置memcache监听的端口,我这里设置了12000,最好是1024以上的端口,

-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,

-p是设置保存memcache的pid文件,我这里是保存在 /tmp/memcached.pid,

注:

1.出现错误:/usr/local/bin/memcached: error while loading shared libraries: libevent-1.3.so.1: cannot open shared object file: no such file or directory

直接设置链接

#ln -s /usr/local/libevent/lib/libevent-1.3.so.1 /lib64/libevent-1.3.so.1

2.如果要结束memcache进程,执行:

# kill `cat /tmp/memcached.pid`

也可以启动多个守护进程,不过端口不能重复.

3.重启apache,service httpd restart

memcache环境测试:

运行下面的php文件,如果有输出this is a test!,就表示环境搭建成功,开始领略memcache的魅力把.

<?php 
$mem = new memcache; 
$mem->connect("192.168.0.200 ", 12000); 
$mem->set(&#39;key&#39;, &#39;this is a test!&#39;, 0, 60); 
$val = $mem->get(&#39;key&#39;); 
 
echo $val;
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Memcache in PHP development? How to use Memcache in PHP development? Nov 07, 2023 pm 12:49 PM

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

How to use Memcache for efficient data reading and writing operations in PHP development? How to use Memcache for efficient data reading and writing operations in PHP development? Nov 07, 2023 pm 03:48 PM

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

How to use Memcache for efficient data writing and querying in PHP development? How to use Memcache for efficient data writing and querying in PHP development? Nov 07, 2023 pm 01:36 PM

How to use Memcache for efficient data writing and querying in PHP development? With the continuous development of Internet applications, the requirements for system performance are getting higher and higher. In PHP development, in order to improve system performance and response speed, we often use various caching technologies. One of the commonly used caching technologies is Memcache. Memcache is a high-performance distributed memory object caching system that can be used to cache database query results, page fragments, session data, etc. By storing data in memory

Utilizing Memcache caching technology to improve the concurrent processing capabilities of PHP applications Utilizing Memcache caching technology to improve the concurrent processing capabilities of PHP applications May 18, 2023 am 08:12 AM

With the rapid development of the Internet, more and more applications need to face a large number of concurrent requests. How to improve the concurrent processing capabilities of applications has become a problem that developers need to solve. Among them, using Memcache caching technology for concurrency optimization has become a relatively popular solution. Memcache is an efficient caching technology suitable for large-scale web applications, databases and distributed systems. Its characteristic is to store data in memory to achieve high-speed read and write operations. During the data access process of web applications,

Practice and thinking on optimizing data interaction with Memcache caching technology in PHP Practice and thinking on optimizing data interaction with Memcache caching technology in PHP May 17, 2023 pm 09:51 PM

The practice and thinking of Memcache caching technology to optimize data interaction in PHP In modern Web applications, data interaction is a very important issue. It is not efficient enough and will limit the scalability and performance of Web applications. In order to speed up data interaction, our usual approach is to optimize the design of the database, improve the performance of the hardware and increase the server capacity. However, these methods all have a common limitation: they increase the cost of the system. In recent years, Memcache technology has made progress in solving this problem.

How to use Memcache for distributed caching in PHP development? How to use Memcache for distributed caching in PHP development? Nov 07, 2023 pm 03:04 PM

As web applications become increasingly complex, performance has become a critical issue. In many applications, database queries are one of the most time-consuming operations. In order to avoid frequently reading data from the database, a caching system can be used to store frequently read data in memory for quick access. In PHP development, using Memcached for distributed caching is an extremely common practice. In this article we will introduce how to use Memcached for distributed caching. What is Memca

Application and practice of Memcache caching technology in PHP projects Application and practice of Memcache caching technology in PHP projects May 17, 2023 pm 02:10 PM

Memcache is an open source, distributed caching technology. It greatly improves the speed of data access by storing data in memory, thus improving the performance and responsiveness of the website. In PHP projects, Memcache caching technology is also widely used and has achieved good results. This article will deeply explore the application and practice of Memcache caching technology in PHP projects. 1. Principles and advantages of Memcache Memcache is a memory caching technology that can store data

How to use Memcache to optimize data storage operations in your PHP application? How to use Memcache to optimize data storage operations in your PHP application? Nov 08, 2023 pm 09:06 PM

How to use Memcache to optimize data storage operations in your PHP application? In web application development, data storage is a crucial link. In PHP applications, Memcache, as a memory cache system, can effectively improve the efficiency of data storage and reading operations. This article will introduce how to use Memcache to optimize data storage operations in PHP applications, and attach specific code examples. Step 1: Install the Memcache extension First, you need to install Me in your PHP environment

See all articles