zoukankan      html  css  js  c++  java
  • memcached 学习笔记 5

     memcached installed on linux

    使用的操作系统是centos6.5 (有桌面)

    1 上传libebent和memcache到/usr/local/src

    1 [root@jt ~]# cd /usr/local/src
    2 [root@jt src]# ls
    3 libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz

    2 安装libebent

    解压

    1 [root@jt src]# tar -zvxf libevent-2.0.20-stable.tar.gz 
    2 libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz
    3 [root@jt src]# cd libevent-2.0.20-stable
    4 [root@jt libevent-2.0.20-stable]#

    编译安装

     1 [root@jt libevent-2.0.20-stable]# ./configure --prefix=/usr
     2 checking for a BSD-compatible install... /usr/bin/install -c
     3 checking whether build environment is sane... yes
     4 checking for a thread-safe mkdir -p... /bin/mkdir -p
     5 checking for gawk... gawk
     6 checking whether make sets $(MAKE)... yes
     7 checking build system type... x86_64-unknown-linux-gnu
     8 checking host system type... x86_64-unknown-linux-gnu
     9 checking for gcc... no
    10 checking for cc... no
    11 checking for cl.exe... no
    12 configure: error: in `/usr/local/src/libevent-2.0.20-stable':
    13 configure: error: no acceptable C compiler found in $PATH
    14 See `config.log' for more details

    缺少gcc库 安装

    1 [root@jt libevent-2.0.20-stable]#  yum -y install gcc
    2 [root@jt libevent-2.0.20-stable]#  yum -y install gcc-c++

    再次编译安装

    1 [root@jt libevent-2.0.20-stable]# ./configure --prefix=/usr
    2 [root@jt libevent-2.0.20-stable]# make
    3 [root@jt libevent-2.0.20-stable]# make install

    验证

     1 [root@jt libevent-2.0.20-stable]#  ls -al /usr/lib | grep libevent
     2 lrwxrwxrwx.  1 root root      21 Sep  8 12:35 libevent-2.0.so.5 -> libevent-2.0.so.5.1.8
     3 -rwxr-xr-x.  1 root root  968506 Sep  8 12:35 libevent-2.0.so.5.1.8
     4 -rw-r--r--.  1 root root 1571554 Sep  8 12:35 libevent.a
     5 lrwxrwxrwx.  1 root root      26 Sep  8 12:35 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.8
     6 -rwxr-xr-x.  1 root root  585209 Sep  8 12:35 libevent_core-2.0.so.5.1.8
     7 -rw-r--r--.  1 root root  978394 Sep  8 12:35 libevent_core.a
     8 -rwxr-xr-x.  1 root root     968 Sep  8 12:35 libevent_core.la
     9 lrwxrwxrwx.  1 root root      26 Sep  8 12:35 libevent_core.so -> libevent_core-2.0.so.5.1.8
    10 lrwxrwxrwx.  1 root root      27 Sep  8 12:35 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.8
    11 -rwxr-xr-x.  1 root root  404796 Sep  8 12:35 libevent_extra-2.0.so.5.1.8
    12 -rw-r--r--.  1 root root  593232 Sep  8 12:35 libevent_extra.a
    13 -rwxr-xr-x.  1 root root     975 Sep  8 12:35 libevent_extra.la
    14 lrwxrwxrwx.  1 root root      27 Sep  8 12:35 libevent_extra.so -> libevent_extra-2.0.so.5.1.8
    15 -rwxr-xr-x.  1 root root     933 Sep  8 12:35 libevent.la
    16 lrwxrwxrwx.  1 root root      30 Sep  8 12:35 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.8
    17 -rwxr-xr-x.  1 root root   18478 Sep  8 12:35 libevent_pthreads-2.0.so.5.1.8
    18 -rw-r--r--.  1 root root   18678 Sep  8 12:35 libevent_pthreads.a
    19 -rwxr-xr-x.  1 root root     996 Sep  8 12:35 libevent_pthreads.la
    20 lrwxrwxrwx.  1 root root      30 Sep  8 12:35 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.8
    21 lrwxrwxrwx.  1 root root      21 Sep  8 12:35 libevent.so -> libevent-2.0.so.5.1.8
    22 [root@jt libevent-2.0.20-stable]#

    安装成功

    3 安装memcached

    解压

    1 [root@jt libevent-2.0.20-stable]# cd /usr/local/src
    2 [root@jt src]# ls
    3 libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10.tar.gz
    4 [root@jt src]# tar -zvxf memcached-1.4.10.tar.gz 
    5 libevent-2.0.20-stable libevent-2.0.20-stable.tar.gz memcached-1.4.10 memcached-1.4.10.tar.gz

    编译安装

    1 [root@jt src]# cd memcached-1.4.10
    2 [root@jt memcached-1.4.10]# ./configure --with-libevent=/usr --enable-threads
    3 [root@jt memcached-1.4.10]# make
    4 [root@jt memcached-1.4.10]# make install

    验证:

    1 [root@jt memcached-1.4.10]# ls -al /usr/local/bin/mem*
    2 -rwxr-xr-x. 1 root root 287883 Sep  8 12:38 /usr/local/bin/memcached

    查看memcached的命令帮助

     1 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -h
     2 memcached 1.4.10
     3 -p <num>      TCP port number to listen on (default: 11211)
     4 -U <num>      UDP port number to listen on (default: 11211, 0 is off)
     5 -s <file>     UNIX socket path to listen on (disables network support)
     6 -a <mask>     access mask for UNIX socket, in octal (default: 0700)
     7 -l <addr>     interface to listen on (default: INADDR_ANY, all addresses)
     8               <addr> may be specified as host:port. If you don't specify
     9               a port number, the value you specified with -p or -U is
    10               used. You may specify multiple addresses separated by comma
    11               or by using -l multiple times
    12 -d            run as a daemon
    13 -r            maximize core file limit
    14 -u <username> assume identity of <username> (only when run as root)
    15 -m <num>      max memory to use for items in megabytes (default: 64 MB)
    16 -M            return error on memory exhausted (rather than removing items)
    17 -c <num>      max simultaneous connections (default: 1024)
    18 -k            lock down all paged memory.  Note that there is a
    19               limit on how much memory you may lock.  Trying to
    20               allocate more than that would fail, so be sure you
    21               set the limit correctly for the user you started
    22               the daemon with (not for -u <username> user;
    23               under sh this is done with 'ulimit -S -l NUM_KB').
    24 -v            verbose (print errors/warnings while in event loop)
    25 -vv           very verbose (also print client commands/reponses)
    26 -vvv          extremely verbose (also print internal state transitions)
    27 -h            print this help and exit
    28 -i            print memcached and libevent license
    29 -P <file>     save PID in <file>, only used with -d option
    30 -f <factor>   chunk size growth factor (default: 1.25)
    31 -n <bytes>    minimum space allocated for key+value+flags (default: 48)
    32 -L            Try to use large memory pages (if available). Increasing
    33               the memory page size could reduce the number of TLB misses
    34               and improve the performance. In order to get large pages
    35               from the OS, memcached will allocate the total item-cache
    36               in one large chunk.
    37 -D <char>     Use <char> as the delimiter between key prefixes and IDs.
    38               This is used for per-prefix stats reporting. The default is
    39               ":" (colon). If this option is specified, stats collection
    40               is turned on automatically; if not, then it may be turned on
    41               by sending the "stats detail on" command to the server.
    42 -t <num>      number of threads to use (default: 4)
    43               如果有此项,说明已经支持了线程,就可以在启动的时候使用 -t 选项来启动多线程
    44 -R            Maximum number of requests per event, limits the number of
    45               requests process for a given connection to prevent 
    46               starvation (default: 20)
    47 -C            Disable use of CAS
    48 -b            Set the backlog queue limit (default: 1024)
    49 -B            Binding protocol - one of ascii, binary, or auto (default)
    50 -I            Override the size of each slab page. Adjusts max item size
    51               (default: 1mb, min: 1k, max: 128m)
    52 -o            Comma separated list of extended or experimental options
    53               - (EXPERIMENTAL) maxconns_fast: immediately close new
    54                 connections if over maxconns limit
    55               - hashpower: An integer multiplier for how large the hash
    56                 table should be. Can be grown at runtime if not big enough.
    57                 Set this based on "STAT hash_power_level" before a 
    58                 restart.
    59 [root@jt memcached-1.4.10]# 

    启动memcached服务并查看该进程

    1 [root@jt memcached-1.4.10]# /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root
    2 [root@jt memcached-1.4.10]# ps aux | grep memcached
    3  root      9186  0.0  0.1 326888  1060 ?        Ssl  12:44   0:00 /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root

    ok 安装成功

    停止Memcache进程:kill `cat /tmp/memcached.pid`
    # kill `cat /tmp/memcached.pid`

    启动Memcache的服务器端:
    # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid
    -d选项是启动一个守护进程,
    -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
    -u是运行Memcache的用户,我这里是root,
    -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
    -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
    -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
    -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,
    也可以启动多个守护进程,不过端口不能重复。

    ./usr/local/memcached/bin/memcached -d -m 256 -u root -p 11211 -c 1024 –P /tmp/memcached.pid

    启动参数说明:
    -d 选项是启动一个守护进程。
    -u root 表示启动memcached的用户为root。
    -m 是分配给Memcache使用的内存数量,单位是MB,默认64MB。
    -M return error on memory exhausted (rather than removing items)。
    -u 是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。
    -p 是设置Memcache的TCP监听的端口,最好是1024以上的端口。
    -c 选项是最大运行的并发连接数,默认是1024。
    -P 是设置保存Memcache的pid文件。


    常见问题:

    1.如果启动Memcached服务的时候遇到了

    /usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory;

    解决方案:

    [root@localhost bin]# LD_DEBUG=libs memcached -v
    [root@localhost bin]# ln -s /usr/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
    [root@localhost bin]# /usr/local/bin/memcached -d -m 100 -u root -p 12000 -c 1000 -P /tmp/memcached.pid
    [root@localhost bin]# ps -aux
    可以看到启动的Memcached服务了.


    2.把Memcached服务加载到Linux的启动项中.万一机器断电系统重启.那么Memcached就会自动启动了.

    假如启动Memcache的服务器端的命令为:
    # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid容来自17jquery

    想开机自动启动的话,只需在/etc/rc.d/rc.local中加入一行,下面命令
    /usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u apache -c 256
    上面有些东西可以参考一下:即,ip不指定时,默认是本机,用户:最好选择是:apache 或 deamon
    这样,也就是属于哪个用户的服务,由哪个用户启动。

  • 相关阅读:
    CentOS7.0安装Nginx 1.7.4
    Java If ... Else
    Java 布尔运算
    Java Math
    Java 运算符
    Java 数据类型
    Java 变量
    Java 注释
    Java 基本语法
    Java 简介
  • 原文地址:https://www.cnblogs.com/wihainan/p/4792695.html
Copyright © 2011-2022 走看看