In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about how to install and configure linux memcache. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Basic principles:
When the ① client accesses the application for the first time, it fetches the data from the database (rdbms) and returns it to the client; it also saves the extracted data to the memcached.
When ② accesses the second time, because the data has been cached, there is no need to query the database and fetch it directly from the memcached.
Unlike rdbms, which is a file-based database that is ultimately saved on disk as a file, memcached is a key:value relational database that is stored in memory. The read and write speed of memory is much faster than that of disk, the former is 10 times the power of the latter.
Memcached is event handling based on libevent. Libevent is a library that encapsulates event handling functions such as epoll of linux and kqueue of BSD operating system into a unified interface. The performance of o (1) can be achieved even if the number of connections to the server increases. Memcached uses this libevent library, so it can perform its high performance on linux, bsd, solaris, and other operating systems. Event handling is not covered in detail here, but can be found in dan kegel's the c10k problem.
Compile and install memcached
1. Since memcached is based on libevent, you need to install libevent,libevent-devel
# yum install libevent libevent-devel-y
2. Download and decompress memcached-1.4.6.tar.gz
The official website of memcached is:
# tar-xvzf memcached-1.4.6.tar.gz
3. Compile and install memcached-1.4.6
# cd memcached-1.4.6
#. / configure-prefix=/etc/memcached
# make
# make install
4. Configure environment variables (this step can be ignored.)
Enter the user host directory, edit .bash _ profile, and add a new directory to the system environment variable ld_library_path, which needs to be added as follows:
# vi .bash _ profile
Memcached_home=/etc/memcached
Export ld_library_path=$ld_library_path:$memcached_home/lib
Refresh the user environment variable: # source .bash _ profile
5. Write a script to start and stop memcached service
# cd / etc/init.d
Vi memcached, the script is as follows:
#! / bin/sh # # startup script for the server of memcached # # processname: memcached # pidfile: / etc/memcached/memcached.pid # logfile: / etc/memcached/memcached_log.txt # memcached_home: / etc/memcached # chkconfig: 35 21 79 # description: start and stop memcached service # source function library. / etc/rc.d/init.d/functions retval=0 prog= "memcached" basedir=/etc/memcached cmd=$ {basedir} / bin/memcached pidfile= "$basedir/$ {prog} .pid" # logfile= "$basedir/memcached_log.txt" ipaddr= "192.168.1.200" # bind the listening ip address port= "11211" # Service port username= "root" # user identity of running program max_memory=64 # default: 64m | maximum memory usage max_simul_conn=1024 # default: 1024 | maximum number of simultaneous connections # maxcon=51200 # growth_factor=1.3 # default: 1.25 | Block size growth factor # thread_num=6 # default: 4 # verbose= "- vv" # View startup details # bind_protocol=binary # ascii Binary, or auto (default) start () {echo-n $"starting service: $prog" $cmd-d-m $max_memory-u $username-l $ipaddr-p $port-c $max_simul_conn-p $pidfile retval=$? Echo [$retval-eq 0] & & touch / var/lock/subsys/$prog} stop () {echo-n $"stopping service: $prog" run_user= `whoami`pidlist= `ps-ef | grep $run_user | grep memcached | grep-v grep | awk'{print ($2)} '`for Pid in $pidlist do # echo "pid=$pid" kill-9$ pid if [$?-ne 0] Then return 1 fi done retval=$? Echo [$retval-eq 0] & & rm-f / var/lock/subsys/$prog} # see how we were called. Case "$1" in start) start;; stop) stop;; # reload) # reload # Restart) stop start;; # condrestart) # if [- f / var/lock/subsys/$prog] Then # stop # start # fi #;; status) status memcached *) echo "usage: $0 {start | stop | restart | status}" exit 1 esac exit $retval
6. Grant executive authority
# chmod + x memcached
7. Set memcached to start with the system
# chkconfig-add memcached
# chkconfig-- level 35 memcached on
Start memcached
# service memcached start
/ / when starting, the following command is actually called to start memcached as a daemon
/ etc/memcached/bin/memcached-d-m 64-u root-l 192.168.1.201\
-p 11211-c 1024-p / etc/memcached/memcached.pid
Check to see if memcached is started
# ps-ef | grep memcached
Install the php extension for memcache
1. Select the memcache version you want to download.
two。 Install the memcache extension for php
Tar vxzf memcache-2.2.5.tgz
Cd memcache-2.2.5
/ usr/local/php/bin/phpize
. / configure-- enable-memcache-- with-php-config=/usr/local/php/bin/php-config-- with-zlib-dir
Make
Make install
3. There will be a prompt similar to this after the above installation:
Installing shared extensions: / usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
4. Change extension_dir = ". /" in php.ini to
Extension_dir = "/ usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
5. Add a line to load the memcache extension: extension=memcache.so
Then restart php, which can be viewed on the phpinfo test page.
These are all the contents of the article "how to install and configure linux memcache". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.