In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Today, what the editor shares with you is a detailed introduction of the memcache cache server in web. I believe most people don't know much about it. In order to make you understand better, the editor summarizes the following content for you. Let's move on.
Memcache cache server
MemCache is a free, open source, high-performance, distributed distributed memory object caching system, which is used for dynamic Web applications to reduce the load of the database. It reduces the number of times to read the database by caching data and objects in memory, thus improving the speed of website access.
Experiment:
1. Install libevent software (4 sets)
[root@localhost] # tar-zxvf libevent-2.0.21-stable.tar.gz-C / usr/src/
[root@localhost ~] # cd / usr/src/libevent-2.0.21-stabl
[root@localhost libevent-2.0.21-stable] #. / configure-prefix=/usr/
[root@localhost libevent-2.0.21-stable] # make & & make install
2. Install memcached software (2 Memcached servers)
[root@localhost] # tar-zxvf memcached-1.4.31.tar.gz-C / usr/src/
[root@localhost ~] # cd / usr/src/memcached-1.4.31/
[root@localhost memcached-1.4.31] # / configure-- enable-memcache-- with-libevent=/usr/
[root@localhost memcached-1.4.31] # make & & make install
Master cache:
[root@localhost] # memcached-d-m 1024-u root-l 192.168.1.201-p 11211
Prepare the cache:
[root@localhost] # memcached-d-m 1024-u root-l 192.168.1.202-p 11211
[root@localhost ~] # netstat-anpt | grep memcached
3. Install magent software (2 Magent servers)
[root@localhost ~] # mkdir / usr/magent
[root@localhost] # tar-zxvf magent-0.6.tar.gz-C / usr/magent/
[root@localhost ~] # cd / usr/magent/
[root@localhost magent] # vim ketama.h
Add (header add):
# ifndef SSIZE_MAX
# define SSIZE_MAX 32767
[root@localhost magent] # ln-s / usr/lib64/libm.so / usr/lib64/libm.a
[root@localhost magent] # ln-s / usr/lib64/libevent-1.4.so.2 / usr/lib64/libevent.a
You need to install libevent-1.4.so.2 when you cannot make
[root@localhost magent] # / sbin/ldconfig
[root@localhost magent] # sed-I "s#LIBS =-levent#LIBS =-levent-lm#g" Makefile
[root@localhost magent] # make
[root@localhost magent] # cp magent / usr/bin/
The master cache and slave cache have the same startup command (- l is drift IP has not yet set up the Keepalived service, do not start the Magent service for the time being)
[root@localhost] # magent-u root-n 51200-l 192.168.1.10-p 12000-s 192.168.1.201Luv 11211
-b 192.168.1.202purl 11211
[root@localhost] # magent-u root-n 51200-l 192.168.1.10-p 12000-s 192.168.1.201Luv 11211
-b 192.168.1.202purl 11211
-u: user
-n: maximum number of connections
-l:magent external monitoring IP address
-p:magent external listening port
-s:magent master cache IP address and port
-b:magent cache IP address and port
[root@localhost ~] # ps-elf | grep magent
4. Install keepalived software (2 Magent servers)
[root@localhost] # tar-zxvf keepalived-1.2.13.tar.gz-C / usr/src/
[root@localhost ~] # cd / usr/src/keepalived-1.2.13/
[root@localhost keepalived-1.2.13] # / configure-- prefix=/-- with-kerneldir=/usr/src/kernels/2.6.32-431.el6.x86_64
[root@localhost keepalived-1.2.13] # make & & make install
Configure the main cache server
[root@localhost ~] # vim / etc/keepalived/keepalived.conf
Modify:
Global_defs {
Router_id LVS_DEVEL_R1
}
Vrrp_instance VI_1 {
State MASTER
Interface eth0
Virtual_router_id 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.168.1.10
}
}
[root@localhost ~] # service keepalived restart
[root@localhost ~] # ip add show dev eth0
Configure standby cache server
[root@localhost ~] # vim / etc/keepalived/keepalived.conf
Modify:
Global_defs {
Router_id LVS_DEVEL_R2
}
Vrrp_instance VI_1 {
State BACKUP
Priority 99
.
Virtual_ipaddress {
192.168.1.10
}
-other parameters are consistent with the main cache server-
}
[root@localhost ~] # service keepalived restart
[root@localhost ~] # ip add show dev eth0
Verify:
The client ping 192.168.1.10 looks at the changes in VIP.
5. Verify:
1) use the main cache node to connect the 1200 port of the main cache to insert data
[root@localhost ~] # telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is'^]'.
Set key 33 0 5
Ggggg
STORED
Quit
Connection closed by foreign host.
2) View the inserted data
[root@localhost ~] # telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is'^]'.
Get key
VALUE key 33 5
Ggggg
END
Quit
Connection closed by foreign host.
3) connect port 11211 of the main cache node to view
[root@localhost ~] # telnet 192.168.1.201 11211
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is'^]'.
Get key
VALUE key 33 5
Ggggg
END
Quit
Connection closed by foreign host.
4) connect port 11211 of the main cache node to view
[root@localhost ~] # telnet 192.168.1.202 11211
Trying 192.168.1.200...
Connected to 192.168.1.200.
Escape character is'^]'.
Get key
VALUE key 33 5
Ggggg
END
Quit
Connection closed by foreign host.
Indicates that both the primary cache node and the standby cache node have data.
Shut down the main cache node.
1) stop the memcached process (or disconnect the network card of the primary cache node)
2) client view
[root@localhost ~] # telnet 192.168.1.10 12000
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is'^]'.
Get key
VALUE key 33 5
Ggggg
END
Summary:
Advantages of memcache: it can be multi-master or multi-slave.
The disadvantage of memcache: when the main cache node is pawned and restored, the previously cached data will be lost.
Configure the main cache server vim keepalived.conf! Configuration File for keepalivedglobal_defs {* * router_id magent-1**} vrrp_instance VI_1 {state * * MASTER** interface * * ens33** virtual_router_id 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.164.100 # Drift address} scp keepalived.conf 192.168.164.7 / Etc/keepalived/ slave server cd / etc/keepalived/vim keepalived.conf! Configuration File for keepalivedglobal_defs {* * router_id magent-2**} vrrp_instance VI_1 {state * * BACKUP** interface * * ens33** virtual_router_id 51 priority 50 advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.164.100 # Drift address}} start keepalivedsystemctl start keepalived.service master cache and backup cache The same startup command (- l is drifting IP has not yet built Keepalived service, do not start Magent service for the time being)
Magent-uroot-n 51200-l 192.168.164.100-p 12000-s 192.168.164.8 11211-b 192.168.164.9
The above is a specific introduction to the memcache cache server, the content is more comprehensive, and I also believe that there are quite a few tools that we may see or use in our daily work. Through this article, I hope you can gain more.
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.