主頁 > 資料庫 > Memcached雙主模型之repcached

Memcached雙主模型之repcached

2020-09-10 06:29:47 資料庫

  在前邊的tomcat session server msm的那篇博客我們用memcached做tomcat session服務器,默認官方memcached是不支持主從同步的,為了解決memcached的高可用,我們是在客戶端實作雙寫和調度,把一份session 多次寫入后端的session服務器上,這樣使得多臺memcached服務器之間的資料有了冗余備份,即便集群中某一臺memcached宕機以后,也不會丟失session;在用戶訪問上,我們在客戶端上實作把調度自動切換到沒有宕機的memcached上,這樣又保證了線上業務的正常使用;memcached 它沒有redis那種持久化的特點,它的資料上保存到記憶體中,一旦服務器掉電,或者重啟服務都會導致資料丟失;

  memcached單機部署

  一、使用yum安裝memcached

  查看memcached包簡介資訊

[root@slave01 ~]# yum info memcached
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
Name        : memcached
Arch        : x86_64
Version     : 1.4.15
Release     : 10.el7_3.1
Size        : 85 k
Repo        : base/7/x86_64
Summary     : High Performance, Distributed Memory Object Cache
URL         : http://www.memcached.org/
License     : BSD
Description : memcached is a high-performance, distributed memory object caching
            : system, generic in nature, but intended for use in speeding up dynamic
            : web applications by alleviating database load.

[root@slave01 ~]# 

  提示:base倉庫收錄memcached的版本是1.4.15;

  安裝memcached

[root@slave01 ~]# yum install -y memcached
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                       | 3.6 kB  00:00:00     
docker-ce-stable                                                                                           | 3.5 kB  00:00:00     
epel                                                                                                       | 4.7 kB  00:00:00     
extras                                                                                                     | 2.9 kB  00:00:00     
mariadb                                                                                                    | 2.9 kB  00:00:00     
updates                                                                                                    | 2.9 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                                          | 206 kB  00:00:00     
(2/4): updates/7/x86_64/primary_db                                                                         | 3.8 MB  00:00:00     
(3/4): epel/x86_64/primary_db                                                                              | 6.9 MB  00:00:01     
(4/4): epel/x86_64/updateinfo                                                                              | 1.0 MB  00:00:05     
Resolving Dependencies
--> Running transaction check
---> Package memcached.x86_64 0:1.4.15-10.el7_3.1 will be installed
--> Processing Dependency: libevent-2.0.so.5()(64bit) for package: memcached-1.4.15-10.el7_3.1.x86_64
--> Running transaction check
---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                       Arch                       Version                                  Repository                Size
==================================================================================================================================
Installing:
 memcached                     x86_64                     1.4.15-10.el7_3.1                        base                      85 k
Installing for dependencies:
 libevent                      x86_64                     2.0.21-4.el7                             base                     214 k

Transaction Summary
==================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 299 k
Installed size: 901 k
Downloading packages:
(1/2): libevent-2.0.21-4.el7.x86_64.rpm                                                                    | 214 kB  00:00:00     
(2/2): memcached-1.4.15-10.el7_3.1.x86_64.rpm                                                              |  85 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                             782 kB/s | 299 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libevent-2.0.21-4.el7.x86_64                                                                                   1/2 
  Installing : memcached-1.4.15-10.el7_3.1.x86_64                                                                             2/2 
  Verifying  : memcached-1.4.15-10.el7_3.1.x86_64                                                                             1/2 
  Verifying  : libevent-2.0.21-4.el7.x86_64                                                                                   2/2 

Installed:
  memcached.x86_64 0:1.4.15-10.el7_3.1                                                                                            

Dependency Installed:
  libevent.x86_64 0:2.0.21-4.el7                                                                                                  

Complete!
[root@slave01 ~]#

  提示:從上面的安裝資訊可以看到memcached依賴libevent這個包,原因是Memcache借助了作業系統的 libevent 工具做高效的讀寫,libevent 是個程式庫,它將 Linux 的 epoll、BSD 類作業系統的 kqueue 等事件處理功能封裝成統一的介面,即使對服務器的連接數增加,也能發揮高性能,memcached使用這個libevent庫,因此能在 Linux、BSD、Solaris 等作業系統上發揮其高性能;

  查看memcached程式環境

[root@slave01 ~]# rpm -ql memcached
/etc/sysconfig/memcached
/usr/bin/memcached
/usr/bin/memcached-tool
/usr/lib/systemd/system/memcached.service
/usr/share/doc/memcached-1.4.15
/usr/share/doc/memcached-1.4.15/AUTHORS
/usr/share/doc/memcached-1.4.15/CONTRIBUTORS
/usr/share/doc/memcached-1.4.15/COPYING
/usr/share/doc/memcached-1.4.15/ChangeLog
/usr/share/doc/memcached-1.4.15/NEWS
/usr/share/doc/memcached-1.4.15/README.md
/usr/share/doc/memcached-1.4.15/protocol.txt
/usr/share/doc/memcached-1.4.15/readme.txt
/usr/share/doc/memcached-1.4.15/threads.txt
/usr/share/man/man1/memcached-tool.1.gz
/usr/share/man/man1/memcached.1.gz
[root@slave01 ~]# 

  提示:/etc/sysconfig/memcached這個檔案是memcached的組態檔,/usr/bin/memcached是可執行程式;/usr/lib/systemd/system/memcached.service是memcached的unit file檔案;

  查看組態檔

[root@slave01 ~]# cat /etc/sysconfig/memcached 
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
[root@slave01 ~]# 

  提示:PORT用于指定memcached的監聽埠,默認是11211,USER用于指定啟動memcached的用戶,默認是memcached,MAXCONN用于指定最大連接數,默認1024.CACHESIZE用于指定最大記憶體,默認是64M,OPTIONS用于指定其他選項的;

  查看memcached幫助

[root@slave01 ~]# memcached -h
memcached 1.4.15
-p <num>      TCP port number to listen on (default: 11211)
-U <num>      UDP port number to listen on (default: 11211, 0 is off)
-s <file>     UNIX socket path to listen on (disables network support)
-a <mask>     access mask for UNIX socket, in octal (default: 0700)
-l <addr>     interface to listen on (default: INADDR_ANY, all addresses)
              <addr> may be specified as host:port. If you don't specify
              a port number, the value you specified with -p or -U is
              used. You may specify multiple addresses separated by comma
              or by using -l multiple times
-d            run as a daemon
-r            maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num>      max memory to use for items in megabytes (default: 64 MB)
-M            return error on memory exhausted (rather than removing items)
-c <num>      max simultaneous connections (default: 1024)
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u <username> user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            verbose (print errors/warnings while in event loop)
-vv           very verbose (also print client commands/reponses)
-vvv          extremely verbose (also print internal state transitions)
-h            print this help and exit
-i            print memcached and libevent license
-P <file>     save PID in <file>, only used with -d option
-f <factor>   chunk size growth factor (default: 1.25)
-n <bytes>    minimum space allocated for key+value+flags (default: 48)
-L            Try to use large memory pages (if available). Increasing
              the memory page size could reduce the number of TLB misses
              and improve the performance. In order to get large pages
              from the OS, memcached will allocate the total item-cache
              in one large chunk.
-D <char>     Use <char> as the delimiter between key prefixes and IDs.
              This is used for per-prefix stats reporting. The default is
              ":" (colon). If this option is specified, stats collection
              is turned on automatically; if not, then it may be turned on
              by sending the "stats detail on" command to the server.
-t <num>      number of threads to use (default: 4)
-R            Maximum number of requests per event, limits the number of
              requests process for a given connection to prevent 
              starvation (default: 20)
-C            Disable use of CAS
-b <num>      Set the backlog queue limit (default: 1024)
-B            Binding protocol - one of ascii, binary, or auto (default)
-I            Override the size of each slab page. Adjusts max item size
              (default: 1mb, min: 1k, max: 128m)
-S            Turn on Sasl authentication
-o            Comma separated list of extended or experimental options
              - (EXPERIMENTAL) maxconns_fast: immediately close new
                connections if over maxconns limit
              - hashpower: An integer multiplier for how large the hash
                table should be. Can be grown at runtime if not big enough.
                Set this based on "STAT hash_power_level" before a 
                restart.
[root@slave01 ~]# 

  提示:-P用于指定監聽TCP埠,默認11211;-U用于指定監聽UDP埠,默認也是11211,如果指定是0表示關閉UDP監聽;-s用于指定unix socket檔案;-a用于指定unix socket檔案的權限,默認是0700的權限;-l用于指定監聽的ip地址資訊,默認是監聽本機所有可用地址;-d 用于指定memcached運行為守護行程;-r用于限定core file的大小;-u用于指定運行memcached的用戶名稱;-m用于指定分配給memcached使用的記憶體,單位是MB;-M用于指定記憶體耗盡時回傳錯誤,而不是洗掉;-c指定最大連接數,默認數1024;-k用于指定鎖定所有分頁記憶體,-v -vv -vvv 列印詳細資訊,v的數量越多,表示列印的資訊就越詳細;-h列印幫助資訊;-i列印memcached和libevent的license資訊;-p用于指定pid檔案;-f用于指定chunk 增長因子,默認數1.25;-n用于指定為快取資料項的key、value、flag設定最小分配位元組數,默認是48;-L用于指定嘗試使用大記憶體分頁;-D用于指定統計報告中Key前綴和ID之間的分隔符,默認是冒號“:”;-t用于指定處理執行緒的數量,默認數4;-R用于指定對連續達到的客戶端請求數設定一個限額,如果超過該設定,會選擇另一個連接來處理請求,默認為20;-C用于指定關閉CAS;-b用戶指定backlog佇列長度,默認是1024;-B用于指定使用的協議,默認行為是自動協商(autonegotiate),可能使用的選項有auto、ascii、binary,-I用于指定覆寫默認的STAB頁大小,默認是1M;-S用于指定打開Sasl身份驗證;-o用于指定號分隔的選項,一般用于用于擴展或實驗性質的選項;

  啟動memecached

  提示:啟動memcached可以把啟動的選項寫到組態檔,然后使用systemctl方式啟動,也可以直接在命令列使用memcached命令指定選項啟動;

  到此,單機memcached就安裝啟動完成;

  二、memcached編譯安裝

  安裝編譯環境

root@slave01 ~]# yum groupinstall "development tools" -y 
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
--> Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
---> Package bison.x86_64 0:3.0.4-2.el7 will be installed
---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be installed
……省略部分內容……
Installed:
  autoconf.noarch 0:2.69-11.el7                           automake.noarch 0:1.13.4-3.el7            
  bison.x86_64 0:3.0.4-2.el7                              byacc.x86_64 0:1.9.20130304-3.el7         
  cscope.x86_64 0:15.8-10.el7                             ctags.x86_64 0:5.8-13.el7                 
  diffstat.x86_64 0:1.57-4.el7                            doxygen.x86_64 1:1.8.5-4.el7              
  elfutils.x86_64 0:0.176-4.el7                           flex.x86_64 0:2.5.37-6.el7                
  gcc.x86_64 0:4.8.5-39.el7                               gcc-c++.x86_64 0:4.8.5-39.el7             
  gcc-gfortran.x86_64 0:4.8.5-39.el7                      git.x86_64 0:1.8.3.1-23.el7_8             
  indent.x86_64 0:2.2.11-13.el7                           intltool.noarch 0:0.50.2-7.el7            
  libtool.x86_64 0:2.4.2-22.el7_3                         patch.x86_64 0:2.7.1-12.el7_7             
  patchutils.x86_64 0:0.3.3-4.el7                         rcs.x86_64 0:5.9.0-7.el7                  
  redhat-rpm-config.noarch 0:9.1.0-88.el7.centos          rpm-build.x86_64 0:4.11.3-43.el7          
  rpm-sign.x86_64 0:4.11.3-43.el7                         subversion.x86_64 0:1.7.14-14.el7         
  swig.x86_64 0:2.0.10-5.el7                              systemtap.x86_64 0:4.0-11.el7             

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7                        apr-util.x86_64 0:1.5.2-6.el7                      
  boost-date-time.x86_64 0:1.53.0-28.el7          boost-system.x86_64 0:1.53.0-28.el7                
  boost-thread.x86_64 0:1.53.0-28.el7             bzip2.x86_64 0:1.0.6-13.el7                        
  cpp.x86_64 0:4.8.5-39.el7                       dwz.x86_64 0:0.11-3.el7                            
  dyninst.x86_64 0:9.3.1-3.el7                    efivar-libs.x86_64 0:36-12.el7                     
  emacs-filesystem.noarch 1:24.3-23.el7           gdb.x86_64 0:7.6.1-119.el7                         
  gettext-common-devel.noarch 0:0.19.8.1-3.el7    gettext-devel.x86_64 0:0.19.8.1-3.el7              
  glibc-devel.x86_64 0:2.17-307.el7.1             glibc-headers.x86_64 0:2.17-307.el7.1              
  gnutls.x86_64 0:3.3.29-9.el7_6                  kernel-debug-devel.x86_64 0:3.10.0-1127.18.2.el7   
  kernel-headers.x86_64 0:3.10.0-1127.18.2.el7    libdwarf.x86_64 0:20130207-4.el7                   
  libgfortran.x86_64 0:4.8.5-39.el7               libmodman.x86_64 0:2.0.1-8.el7                     
  libmpc.x86_64 0:1.0.1-3.el7                     libproxy.x86_64 0:0.4.11-11.el7                    
  libquadmath.x86_64 0:4.8.5-39.el7               libquadmath-devel.x86_64 0:4.8.5-39.el7            
  libstdc++-devel.x86_64 0:4.8.5-39.el7           m4.x86_64 0:1.4.16-10.el7                          
  mokutil.x86_64 0:15-8.el7                       mpfr.x86_64 0:3.1.1-4.el7                          
  neon.x86_64 0:0.30.0-4.el7                      nettle.x86_64 0:2.7.1-8.el7                        
  pakchois.x86_64 0:0.4-10.el7                    perl-Error.noarch 1:0.17020-2.el7                  
  perl-Git.noarch 0:1.8.3.1-23.el7_8              perl-TermReadKey.x86_64 0:2.30-20.el7              
  perl-Test-Harness.noarch 0:3.28-3.el7           perl-Thread-Queue.noarch 0:3.02-2.el7              
  perl-XML-Parser.x86_64 0:2.41-10.el7            perl-srpm-macros.noarch 0:1-8.el7                  
  python-srpm-macros.noarch 0:3-32.el7            subversion-libs.x86_64 0:1.7.14-14.el7             
  systemtap-client.x86_64 0:4.0-11.el7            systemtap-devel.x86_64 0:4.0-11.el7                
  systemtap-runtime.x86_64 0:4.0-11.el7           trousers.x86_64 0:0.3.14-2.el7                     
  unzip.x86_64 0:6.0-21.el7                       zip.x86_64 0:3.0-11.el7                            

Complete!
[root@slave01 ~]# 

  安裝依賴包

[root@slave01 ~]# yum install -y libevent-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package libevent-devel.x86_64 0:2.0.21-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
 Package                     Arch                Version                     Repository         Size
=====================================================================================================
Installing:
 libevent-devel              x86_64              2.0.21-4.el7                base               85 k

Transaction Summary
=====================================================================================================
Install  1 Package

Total download size: 85 k
Installed size: 357 k
Downloading packages:
libevent-devel-2.0.21-4.el7.x86_64.rpm                                        |  85 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libevent-devel-2.0.21-4.el7.x86_64                                                1/1 
  Verifying  : libevent-devel-2.0.21-4.el7.x86_64                                                1/1 

Installed:
  libevent-devel.x86_64 0:2.0.21-4.el7                                                               

Complete!
[root@slave01 ~]# 

  下載原始碼檔案

[root@slave01 ~]# wget  http://memcached.org/files/memcached-1.6.6.tar.gz
--2020-08-11 10:35:25--  http://memcached.org/files/memcached-1.6.6.tar.gz
Resolving memcached.org (memcached.org)... 107.170.231.145
Connecting to memcached.org (memcached.org)|107.170.231.145|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 543661 (531K) [application/octet-stream]
Saving to: ‘memcached-1.6.6.tar.gz’

100%[===========================================================>] 543,661     19.9KB/s   in 17s    

2020-08-11 10:35:43 (30.5 KB/s) - ‘memcached-1.6.6.tar.gz’ saved [543661/543661]

[root@slave01 ~]# ls
memcached-1.6.6.tar.gz
[root@slave01 ~]# 

  解壓原始碼包,檢查編譯環境

[root@slave01 ~]# tar xf memcached-1.6.6.tar.gz 
[root@slave01 ~]# cd memcached-1.6.6/
[root@slave01 memcached-1.6.6]# ls
aclocal.m4    COPYING         itoa_ljust.h        NEWS                      stats_prefix.c
assoc.c       crawler.c       jenkins_hash.c      openbsd_priv.c            stats_prefix.h
assoc.h       crawler.h       jenkins_hash.h      protocol_binary.h         storage.c
authfile.c    crc32c.c        LICENSE.bipbuffer   README.md                 storage.h
authfile.h    crc32c.h        linux_priv.c        restart.c                 t
AUTHORS       daemon.c        logger.c            restart.h                 testapp.c
bipbuffer.c   depcomp         logger.h            sasl_defs.c               thread.c
bipbuffer.h   doc             m4                  sasl_defs.h               timedrun.c
cache.c       extstore.c      Makefile.am         scripts                   tls.c
cache.h       extstore.h      Makefile.in         sizes.c                   tls.h
ChangeLog     freebsd_priv.c  memcached.c         slab_automove.c           trace.h
compile       hash.c          memcached_dtrace.d  slab_automove_extstore.c  util.c
config.guess  hash.h          memcached.h         slab_automove_extstore.h  util.h
config.h.in   install-sh      memcached.spec      slab_automove.h           version.m4
config.sub    items.c         missing             slabs.c
configure     items.h         murmur3_hash.c      slabs.h
configure.ac  itoa_ljust.c    murmur3_hash.h      solaris_priv.c
[root@slave01 memcached-1.6.6]# ./configure --prefix=/usr/locat/memcached
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
……省略部分內容……
checking for xsltproc... /usr/bin/xsltproc
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@slave01 memcached-1.6.6]#

  編譯安裝memcached

[root@slave01 memcached-1.6.6]# make
make  all-recursive
make[1]: Entering directory `/root/memcached-1.6.6'
Making all in doc
make[2]: Entering directory `/root/memcached-1.6.6/doc'
make  all-am
make[3]: Entering directory `/root/memcached-1.6.6/doc'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/root/memcached-1.6.6/doc'
make[2]: Leaving directory `/root/memcached-1.6.6/doc'
make[2]: Entering directory `/root/memcached-1.6.6'
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -pthread -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f 'memcached.c' || echo './'`memcached.c
mv -f .deps/memcached-memcached.Tpo .deps/memcached-memcached.Po
gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -pthread -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT memcached-hash.o -MD -MP -MF .deps/memcached-hash.Tpo -c -o memcached-hash.o `test -f 'hash.c' || echo './'`hash.c
mv -f .deps/memcached-hash.Tpo .deps/memcached-hash.Po
……省略部分內容……
gcc -std=gnu99 -DHAVE_CONFIG_H -I.     -g -O2 -pthread -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -MT timedrun.o -MD -MP -MF .deps/timedrun.Tpo -c -o timedrun.o timedrun.c
mv -f .deps/timedrun.Tpo .deps/timedrun.Po
gcc -std=gnu99  -g -O2 -pthread -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls   -o timedrun timedrun.o  -levent 
make[2]: Leaving directory `/root/memcached-1.6.6'
make[1]: Leaving directory `/root/memcached-1.6.6'
[root@slave01 memcached-1.6.6]# make install
make  install-recursive
make[1]: Entering directory `/root/memcached-1.6.6'
Making install in doc
make[2]: Entering directory `/root/memcached-1.6.6/doc'
make  install-am
make[3]: Entering directory `/root/memcached-1.6.6/doc'
make[4]: Entering directory `/root/memcached-1.6.6/doc'
make[4]: Nothing to be done for `install-exec-am'.
 /usr/bin/mkdir -p '/usr/locat/memcached/share/man/man1'
 /usr/bin/install -c -m 644 memcached.1 '/usr/locat/memcached/share/man/man1'
make[4]: Leaving directory `/root/memcached-1.6.6/doc'
make[3]: Leaving directory `/root/memcached-1.6.6/doc'
make[2]: Leaving directory `/root/memcached-1.6.6/doc'
make[2]: Entering directory `/root/memcached-1.6.6'
make[3]: Entering directory `/root/memcached-1.6.6'
 /usr/bin/mkdir -p '/usr/locat/memcached/bin'
  /usr/bin/install -c memcached '/usr/locat/memcached/bin'
 /usr/bin/mkdir -p '/usr/locat/memcached/include/memcached'
 /usr/bin/install -c -m 644 protocol_binary.h '/usr/locat/memcached/include/memcached'
make[3]: Leaving directory `/root/memcached-1.6.6'
make[2]: Leaving directory `/root/memcached-1.6.6'
make[1]: Leaving directory `/root/memcached-1.6.6'
[root@slave01 memcached-1.6.6]# ll /usr/locat/memcached/
total 0
drwxr-xr-x 2 root root 23 Aug 11 10:39 bin
drwxr-xr-x 3 root root 23 Aug 11 10:39 include
drwxr-xr-x 3 root root 17 Aug 11 10:39 share
[root@slave01 memcached-1.6.6]# 

  啟動memcached

  到此memcached的編譯安裝就完成了

  三、使用python連接memcached寫入資料

[root@slave01 ~]# cat test.py 
import memcache
m = memcache.Client(['127.0.0.1:11211'], debug=True)
for i in range(100):
    m.set("key%d" % i,"v%d" % i)
#    ret = m.get('key%d' % i)
#    print ret
[root@slave01 ~]#

  提示:以上腳本主要作用是連接到memcache后回圈寫入100個key;

  運行腳本,然后查看memcached上是否存盤的有我們寫入的key資料?

[root@slave01 ~]# python test.py
[root@slave01 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
get key1
VALUE key1 0 2
v1
END
get k12
END
get key12
VALUE key12 0 3
v12
END
quit
Connection closed by foreign host.
[root@slave01 ~]# 

  提示:可以看到運行腳本以后,連接到memcached里是可以取出我們寫入到key對應的資料;

  部署 repcached   實驗環境說明  
名稱 IP地址
master01 192.168.16.196 11211
master02 192.168.16.197

11211

                             在master01上編譯安裝repcached
[root@master01 ~]# ls
memcached-1.2.8-repcached-2.2.tar.gz
[root@master01 ~]# tar xf memcached-1.2.8-repcached-2.2.tar.gz 
[root@master01 ~]# ls
memcached-1.2.8-repcached-2.2  memcached-1.2.8-repcached-2.2.tar.gz
[root@master01 ~]# cd memcached-1.2.8-repcached-2.2/
[root@master01 memcached-1.2.8-repcached-2.2]# ./configure --prefix=/usr/local/repcached --enable-replication
checking build system type... Invalid configuration `x86_64-unknown-linux-': machine `x86_64-unknown-linux' not recognized
configure: error: /bin/sh ./config.sub x86_64-unknown-linux- failed
[root@master01 memcached-1.2.8-repcached-2.2]# 

  提示:遇到以上錯誤,上因為沒有安裝gcc編譯導致的,通常在Linux上做編譯操作,我們需要先安裝好編譯環境;

  安裝編譯環境

[root@master01 memcached-1.2.8-repcached-2.2]# yum groupinstall "development tools" -y 

  再次檢查編譯環境

[root@master01 memcached-1.2.8-repcached-2.2]# ./configure --prefix=/usr/local/repcached --enable-replication
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for libevent directory... configure: error: libevent is required.  You can get it from http://www.monkey.org/~provos/libevent/

      If it's already installed, specify its path using --with-libevent=/dir/

[root@master01 memcached-1.2.8-repcached-2.2]# 

  提示:上述錯誤是沒有檢查到libevent,解決辦法安裝依賴包libevent-devel包

  安裝依賴包

[root@master01 memcached-1.2.8-repcached-2.2]# yum install libevent-devel -y

  再次檢查編譯環境

[root@master01 memcached-1.2.8-repcached-2.2]# ./configure --prefix=/usr/local/repcached --enable-replication
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for libevent directory... (system)
checking for library containing socket... none required
checking for library containing gethostbyname... none required
checking for library containing mallinfo... none required
checking for daemon... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for an ANSI C-conforming const... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking for struct mallinfo.arena... yes
checking for socklen_t... yes
checking for endianness... little
checking for mlockall... yes
checking for getpagesizes... no
checking for memcntl... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@master01 memcached-1.2.8-repcached-2.2]# 

  提示:--enable-replication選項表示開啟復制功能;檢查編譯環境沒有問題后,就可以執行編譯和安裝了;

  編譯安裝

[root@master01 memcached-1.2.8-repcached-2.2]# make && make install 
make  all-recursive
make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
Making all in doc
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f 'memcached.c' || echo './'`memcached.c
memcached.c: In function ‘add_iov’:
memcached.c:696:30: error: ‘IOV_MAX’ undeclared (first use in this function)
         if (m->msg_iovlen == IOV_MAX ||
                              ^
memcached.c:696:30: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [memcached-memcached.o] Error 1
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
make: *** [all] Error 2
[root@master01 memcached-1.2.8-repcached-2.2]# 

  提示:這個錯誤是memcached.c中的宏定義問題,處理辦法就是把memcached.c中的#if defined(__FreeBSD__) || defined(__APPLE__) 和#endif注釋掉即可如下所示

  提示:修改了上面的memcached.c 以后,再次編譯就沒有問題了

  再次編譯

[root@master01 memcached-1.2.8-repcached-2.2]# make && make install
make  all-recursive
make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
Making all in doc
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f 'memcached.c' || echo './'`memcached.c
mv -f .deps/memcached-memcached.Tpo .deps/memcached-memcached.Po
gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-slabs.o -MD -MP -MF .deps/memcached-slabs.Tpo -c -o memcached-slabs.o `test -f 'slabs.c' || echo './'`slabs.c
mv -f .deps/memcached-slabs.Tpo .deps/memcached-slabs.Po
……省略部分內容……
mv -f .deps/replication.Tpo .deps/replication.Po
gcc  -g -O2   -o memcached-debug memcached.o slabs.o items.o assoc.o thread.o stats.o replication.o  -levent
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
Making install in doc
make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/repcached/share/man/man1" || /usr/bin/mkdir -p "/usr/local/repcached/share/man/man1"
 /usr/bin/install -c -m 644 './memcached.1' '/usr/local/repcached/share/man/man1/memcached.1'
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2/doc'
make[1]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
make[2]: Entering directory `/root/memcached-1.2.8-repcached-2.2'
test -z "/usr/local/repcached/bin" || /usr/bin/mkdir -p "/usr/local/repcached/bin"
  /usr/bin/install -c 'memcached' '/usr/local/repcached/bin/memcached'
  /usr/bin/install -c 'memcached-debug' '/usr/local/repcached/bin/memcached-debug'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
make[1]: Leaving directory `/root/memcached-1.2.8-repcached-2.2'
[root@master01 memcached-1.2.8-repcached-2.2]#  ll /usr/local/repcached/
total 0
drwxr-xr-x 2 root root 46 Aug 10 23:26 bin
drwxr-xr-x 3 root root 17 Aug 10 23:26 share
[root@master01 memcached-1.2.8-repcached-2.2]# ll /usr/local/repcached/bin/
total 472
-rwxr-xr-x 1 root root 233096 Aug 10 23:26 memcached
-rwxr-xr-x 1 root root 248008 Aug 10 23:26 memcached-debug
[root@master01 memcached-1.2.8-repcached-2.2]# 

  提示:可以看到對應目錄下已經有二進制檔案生成,到此repcached就編譯安裝好了;

  驗證repcached/bin/memcached是否可執行?

[root@master01 ~]# /usr/local/repcached/bin/memcached -h
memcached 1.2.8
repcached 2.2
-p <num>      TCP port number to listen on (default: 11211)
-U <num>      UDP port number to listen on (default: 11211, 0 is off)
-s <file>     unix socket path to listen on (disables network support)
-a <mask>     access mask for unix socket, in octal (default 0700)
-l <ip_addr>  interface to listen on, default is INDRR_ANY
-d            run as a daemon
-r            maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num>      max memory to use for items in megabytes, default is 64 MB
-M            return error on memory exhausted (rather than removing items)
-c <num>      max simultaneous connections, default is 1024
-k            lock down all paged memory.  Note that there is a
              limit on how much memory you may lock.  Trying to
              allocate more than that would fail, so be sure you
              set the limit correctly for the user you started
              the daemon with (not for -u <username> user;
              under sh this is done with 'ulimit -S -l NUM_KB').
-v            verbose (print errors/warnings while in event loop)
-vv           very verbose (also print client commands/reponses)
-h            print this help and exit
-i            print memcached and libevent license
-P <file>     save PID in <file>, only used with -d option
-f <factor>   chunk size growth factor, default 1.25
-n <bytes>    minimum space allocated for key+value+flags, default 48
-R            Maximum number of requests per event
              limits the number of requests process for a given con nection
              to prevent starvation.  default 20
-b            Set the backlog queue limit (default 1024)
-x <ip_addr>  hostname or IP address of peer repcached
-X <num>      TCP port number for replication (default: 11212)
[root@master01 ~]# 

  提示:可以看到在memcached的幫助選項中多了一個-x和-X的選項,其中-x用于指定去那個地址上的memcached同步資料,-X用來指定本地那個埠來接收同步資料;

  啟動memcached

  提示:通過 repcached 安裝的 memcached 命令啟動 memcache 服務并實作 memcache 主備結構,其中-x 為對方即主 memcache 的 IP,-X 為本地啟動的用資料同步的埠;

  在master02上編譯安裝repcached的程序同master01上一樣的;如果你不想那么麻煩的再去編譯可以把master01上編譯好的二進制檔案拷到master02上執行也是可以的

  從master01上拷貝二進制檔案到master02上

[root@master01 ~]# scp -r /usr/local/repcached/ master02:/usr/local/
memcached.1                                                          100% 4290     1.9MB/s   00:00    
memcached                                                            100%  228KB   4.9MB/s   00:00    
memcached-debug                                                      100%  242KB   4.9MB/s   00:00    
[root@master01 ~]#

  在master02上啟動memcached

[root@master02 ~]# /usr/local/repcached/bin/memcached -d -m 2048 -p 11211 -u root -c 2048 -x 192.168.16.196 -X 52113
/usr/local/repcached/bin/memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
[root@master02 ~]#

  提示:上述報錯主要原因上沒有安裝libevent-devel,所以在執行memcached時加載共享動態庫檔案找不到,解決辦法安裝libevent-devel即可

  在master02上安裝依賴包libevent-devel

[root@master02 ~]# yum install -y libevent-devel

  再次啟動memcached

  提示:在master02上指定master01上的用于復制監聽埠,如果master02連接上master01,那么在master02和master01上就不會在監聽我們手動指定的用于復制的埠;如果你在master02上還能夠看到手動指定的復制埠,說明master01和master02沒有建立連接;

  驗證:往master01上寫入資料看看是否能夠同步到master02上呢?

  提示:可以看到在master01上寫資料,在master02上是能夠正常讀取到的;

  驗證在master02上寫資料,master01上是否可讀取呢?

  提示:可以看到在master02上寫資料,也能夠及時的同步到master01上;到此基于repcached雙主模型的memcached就搭建好了,我們不管往那個master上寫入資料,它都會立刻同步資料到對方到memcached中去;

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/1124.html

標籤:NoSQL

上一篇:【趙強老師】Redis的RDB持久化

下一篇:Redis 基礎操作

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more