Memcached服务端安装
libevent安装 cd /tmpwget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gztar -zxf libevent-1.4.14b-stable.tar.gzcd libevent-1.4.14b-stable./configure --prefix=/opt/libevent/makemake install Memcached安装 cd /tmpwget -N http://www.m
libevent安装
cd /tmp wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz tar -zxf libevent-1.4.14b-stable.tar.gz cd libevent-1.4.14b-stable ./configure --prefix=/opt/libevent/ make make install
Memcached安装
cd /tmp wget -N http://www.memcached.org/files/memcached-1.4.17.tar.gz tar -zxf memcached-1.4.17.tar.gz cd memcached-1.4.17 ./configure --prefix=/opt/memcached --enable-64bit --with-libevent=/opt/libevent make make install
编写Memcached启动脚本
vi /etc/init.d/memcached #!/bin/sh # chkconfig: - 50 50 # description: memcached # 以下要自己配置 CMD=/opt/memcached/bin/memcached MEMORY=128 USER=root HOST=master PORT=11211 CONNECTION=32 PID=/tmp/memcached.pid start() { echo -n $"memcached starting... " $CMD -d -m $MEMORY -u $USER -l $HOST -p $PORT -c $CONNECTION -P $PID echo } stop() { echo -n $"memcached shutting down... " kill `cat $PID` echo } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit 0
将memcached加入系统启项
chmod +x /etc/init.d/memcached chkconfig --add /etc/init.d/memcached chkconfig --level 35 memcached on chkconfig --level 35 iptables off
启动Memcached
/opt/memcached/bin/memcached -d -m 128 -u root -l master -p 11211 -c 32 -P /tmp/memcached.pid service memcached restart
基于上面,其他一些选项的含义
-d 指定memcached进程作为一个守护进程启动 -m <num> 指定分配给memcached使用的内存,单位是MB -u <username> 运行memcached的用户 -l <ip_addr> 监听的服务器IP地址,如果有多个地址的话,使用逗号分隔,格式可以为“IP地址:端口号”,例如:-l 指定192.168.0.184:19830,192.168.0.195:13542;端口号也可以通过-p选项指定 -p <num> Memcached监听的端口,要保证该端口号未被占用 -c <num> 设置最大运行的并发连接数,默认是1024 -R <num> 为避免客户端饿死(starvation),对连续达到的客户端请求数设置一个限额,如果超过该设置,会选择另一个连接来处理请求,默认为20 -k 设置锁定所有分页的内存,对于大缓存应用场景,谨慎使用该选项 -P 保存memcached进程的pid文件 -s <file> 指定Memcached用于监听的UNIX socket文件 -a <perms> 设置-s选项指定的UNIX socket文件的权限 -U <num> 指定监听UDP的端口,默认11211,0表示关闭 -M 当内存使用超出配置值时,禁止自动清除缓存中的数据项,此时Memcached不可以,直到内存被释放 -r 设置产生core文件大小 -f <factor> 用于计算缓存数据项的内存块大小的乘数因子,默认是1.25 -n 为缓存数据项的key、value、flag设置最小分配字节数,默认是48 -C 禁用CAS -h 显示Memcached版本和摘要信息 -v 输出警告和错误信息 -vv 打印信息比-v更详细:不仅输出警告和错误信息,也输出客户端请求和响应信息 -i 打印libevent和Memcached的licenses信息 -t <threads> 指定用来处理请求的线程数,默认为4 -D <char> 用于统计报告中Key前缀和ID之间的分隔符,默认是冒号“:” -L 尝试使用大内存分页(pages) -B <proto> 指定使用的协议,默认行为是自动协商(autonegotiate),可能使用的选项有auto、ascii、binary。 -I <size> 覆盖默认的STAB页大小,默认是1M -F 禁用flush_all命令 -o <options> 指定逗号分隔的选项,一般用于用于扩展或实验性质的选项
停止Memcached
ps -ef | grep memcached kill -9 <PID>
Java客户端 - XMemcached客户端
spring.xml
<!-- 启动参数加入 -Dxmemcached.jmx.enable=true 可启动jmx支持 --> <!-- 监控端可通过service:jmx:rmi:///jndi/rmi://host:7077/xmemcachedServer连接监控 --> <bean name="memcachedClient" class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" destroy-method="shutdown"> <!-- servers节点列表格式 主节点1:port,主节点1备份:port 主节点2:port,主节点2备份:port --> <!--可以不设置备份节点,主备节点都好分割,不同的主备分组用空格分隔 --> <property name="servers"> <value>${cache.memcacheHost}</value> </property> <!-- 权重 --> <property name="weights"> <list> <value>${cache.memcacheHostWeights1}</value> </list> </property> <!-- 开启sasl验证需要配置此部分 --> <!-- <bean name="server1" class="java.net.InetSocketAddress"> <constructor-arg> <value>host1</value> </constructor-arg> <constructor-arg> <value>port1</value> </constructor-arg> </bean> <property name="authInfoMap"> <map> <entry key-ref="server1"> <bean class="net.rubyeye.xmemcached.auth.AuthInfo" factory-method="typical"> <constructor-arg index="0"> <value>cacheuser</value> </constructor-arg> <constructor-arg index="1"> <value>123456</value> </constructor-arg> </bean> </entry> </map> </property> --> <!-- nio线程数最好是cpu核数-1 --> <property name="connectionPoolSize"> <value>${cache.memcacheConnectionPoolSize}</value> </property> <!--默认超时时间 --> <property name="opTimeout"> <value>${cache.opTimeout}</value> </property> <!-- 使用二进制保存 --> <property name="commandFactory"> <!-- <bean class="net.rubyeye.xmemcached.command.BinaryCommandFactory"></bean> --> <bean class="net.rubyeye.xmemcached.command.TextCommandFactory"></bean> </property> <!-- 分布式hash一致策略 --> <property name="sessionLocator"> <bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator"></bean> </property> <!-- 序列化转换 --> <property name="transcoder"> <bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" /> </property> <!-- buffer分配策略 --> <property name="bufferAllocator"> <bean class="net.rubyeye.xmemcached.buffer.SimpleBufferAllocator"></bean> </property> <!-- 在hash一致模式下节点失败路由到下一节点,关闭快速失败模式 --> <property name="failureMode" value="false" /> </bean>
原文地址:Memcached服务端安装, 感谢原作者分享。

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

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

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



Solution to the problem that Win11 system cannot install Chinese language pack With the launch of Windows 11 system, many users began to upgrade their operating system to experience new functions and interfaces. However, some users found that they were unable to install the Chinese language pack after upgrading, which troubled their experience. In this article, we will discuss the reasons why Win11 system cannot install the Chinese language pack and provide some solutions to help users solve this problem. Cause Analysis First, let us analyze the inability of Win11 system to

You may not be able to install guest additions to a virtual machine in OracleVirtualBox. When we click on Devices>InstallGuestAdditionsCDImage, it just throws an error as shown below: VirtualBox - Error: Unable to insert virtual disc C: Programming FilesOracleVirtualBoxVBoxGuestAdditions.iso into ubuntu machine In this post we will understand what happens when you What to do when you can't install guest additions in VirtualBox. Unable to install guest additions in VirtualBox If you can't install it in Virtua

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager
