CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
CentOS 5.4下的Memcache安装步骤分享,想要配置Linux+Nginx+PHP+Memcached运行环境的朋友可以参考下
一、源码包准备
服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-v1.4.4 。
下载:http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,
libevent的最新版本是libevent-1.4.13-stable。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/
下载:http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
准备Memcached的PHP扩展的源码安装包:
官网:http://pecl.php.net/get/memcache-2.2.5.tgz
Linux指令下载:
代码如下:
wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz wget http://pecl.php.net/get/memcache-2.2.5.tgz
二、安装与配置
1、先安装libevent
代码如下:
tar zxvf libevent-1.4.13-stable.tar.gz cd libevent-1.4.13-stable ./configure --prefix=/usr make make install
2、测试libevent是否安装成功
代码如下:
ls -al /usr/lib | grep libevent libevent-1.1a.so.1 libevent-1.1a.so.1.0.2 libevent-1.4.so.2 libevent-1.4.so.2.1.3 libevent.a libevent_core-1.4.so.2 libevent_core-1.4.so.2.1.3 libevent_core.a libevent_core.la libevent_core.so libevent_extra-1.4.so.2 libevent_extra-1.4.so.2.1.3 libevent_extra.a libevent_extra.la libevent_extra.so libevent.la libevent.so
版本不同,可能文件列表不同。
3、安装memcached,同时需要安装中指定libevent的安装位置
代码如下:
tar zxvf memcached-1.4.4.tar.gz cd memcached-1.4.4 ./configure –with-libevent=/usr make && make install
安装完成后会把memcached 自动放到 /usr/local/bin/memcached
4、测试是否成功安装memcached
代码如下:
ls -al /usr/local/bin/mem* -rwxr-xr-x 1 root root 201869 12-14 21:44 /usr/local/bin/memcached
5、安装Memcache的PHP扩展
①安装PHP的memcache扩展
代码如下:
tar vxzf memcache-2.2.5.tgz cd memcache-2.2.5 /usr/local/webserver/php/bin/phpize ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir make make install
②上述安装完后会有类似这样的提示:
Installing shared extensions: /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
③把php.ini中的extension_dir = “./”修改为
代码如下:
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
④添加一行来载入memcache扩展:extension=memcache.so
三、memcached的基本设置
1.启动Memcache的服务器端:
代码如下:
memcached -d -m 10 -u root -l 202.207.177.177 -p 11211 -c 256 -P /tmp/memcached.pid
参数说明:
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址202.207.177.177,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,
2.如果要结束Memcache进程,执行:
代码如下:
kill `cat /tmp/memcached.pid`
也可以启动多个守护进程,不过端口不能重复。
3.检查Memcached是否启动
代码如下:
netstat -ant
tcp 0 0 202.207.177.177:11211 0.0.0.0:* LIST
11211端口已经打开,说明Memcached已正常启动。
4.重启CentOS
代码如下:
reboot
四、Memcache环境测试
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始你的Memcache的征途吧!
代码如下:
<?php $mem = new Memcache; $mem->connect("202.207.177.177", 11211); $mem->set('key', 'This is a test!', 0, 60); $val = $mem->get('key'); echo $val; ?>
著名的PHPCMS同样支持Memcached扩展:
代码如下:
<?php //MemCache服务器配置 //define('MEMCACHE_HOST', 'localhost'); //MemCache服务器主机 //define('MEMCACHE_PORT', 11211); //MemCache服务器端口 //define('MEMCACHE_TIMEOUT', 1); //S,MemCache服务器连接超时 class cache { var $memcache; function __construct() { $this->memcache = &new Memcache; $this->memcache->pconnect(MEMCACHE_HOST, MEMCACHE_PORT, MEMCACHE_TIMEOUT); } function cache() { $this->__construct(); } function get($name) { return $this->memcache->get($name); } function set($name, $value, $ttl = 0) { return $this->memcache->set($name, $value, 0, $ttl); } function rm($name) { return $this->memcache->delete($name); } function clear() { return $this->memcache->flush(); } } ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

The Installation, Configuration and Optimization Guide for HDFS File System under CentOS System This article will guide you how to install, configure and optimize Hadoop Distributed File System (HDFS) on CentOS System. HDFS installation and configuration Java environment installation: First, make sure that the appropriate Java environment is installed. Edit /etc/profile file, add the following, and replace /usr/lib/java-1.8.0/jdk1.8.0_144 with your actual Java installation path: exportJAVA_HOME=/usr/lib/java-1.8.0/jdk1.8.0_144exportPATH=$J

When configuring Hadoop Distributed File System (HDFS) on CentOS, the following key configuration files need to be modified: core-site.xml: fs.defaultFS: Specifies the default file system address of HDFS, such as hdfs://localhost:9000. hadoop.tmp.dir: Specifies the storage directory for Hadoop temporary files. hadoop.proxyuser.root.hosts and hadoop.proxyuser.ro

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab
