Hi 你好,欢迎访问!登录
当前位置:首页 - 自动化运维 - 正文 忍人所不忍,能人所不能。

Linux自动化工具之SatlStack_安装memcached及扩展memcahce

2020-03-16自动化运维90root233°c
A+ A-

memcahced是一个高性能的分布式内存对象缓存系统, 用于动态web应用以减轻数据库负载. 它通过在内存中缓存数据和对象来减少读取数据库的次数. 从而提高动态数据库驱动网站的访问速度

解决session问题,一般有三种解决方案:

    1. session保持

    2. session复制

    3. session共享

1. 创建memcache所需目录结构

[[email protected]_210 ~]# cd /data/etc/salt/
[[email protected]_210 salt]# mkdir memcache/libevent/files -p
[[email protected]_210 salt]# mkdir memcache/memcached/files -p
[[email protected]_210 salt]# mkdir memcache/php-memcache/files -p
[[email protected]_210 salt]# mkdir memcache/user
[[email protected]_210 salt]# tree memcache/
memcache/
|-- init.sls
|-- libevent
|   |-- files
|   |   `-- libevent-2.0.22-stable.tar.gz
|   `-- install.sls
|-- memcached
|   |-- files
|   |   `-- memcached-1.4.31.tar.gz
|   |-- install.sls
|   `-- service.sls
|-- php-memcache
|   |-- files
|   |   `-- memcache-2.2.7.tgz
|   `-- install.sls
`-- user
    `-- create_90root.sls
[[email protected]_210 salt]# # cd memcache/
[[email protected]_210 memcache]# cat init.sls
include:
  - memcache.memcached.service
  - memcache.php-memcache.install
[[email protected]_210 memcache]# cat ../top.sls
base:
  '*':
    - memcache.init

2. 创建memcached监听用户

[[email protected]_210 ~]# cd /data/etc/salt/memcache/user/
[[email protected]_210 user]# cat create_90root.sls
90root-user-group:
  group.present:
    - name: 90root
    - gid: 1000
  user.present:
    - name: 90root              ->username
    - fullname: 90root          ->用户全名
    - shell: /sbin/nologin      ->shell环境
    - uid: 1000                 ->user uid
    - gid: 1000                 ->user gid
    - createhome: True          ->不创建用户家目录

3. Libevent安装及配置

[[email protected]_210 ~]# cd /data/etc/salt/memcache/libevent/files
[[email protected]_210 files]# wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
[[email protected]_210 files]# cd /data/etc/salt/memcache/libevent/
[[email protected]_210 libevent]# vim install.sls
libevent-source:
  file.managed:
    - name: /usr/local/src/libevent-2.0.22-stable.tar.gz
    - unless: test -e /usr/local/src/libevent-2.0.22-stable.tar.gz
    - source: salt://memcache/libevent/files/libevent-2.0.22-stable.tar.gz
    - user: root
    - group: root
    - mode: 644
libevent-extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf libevent-2.0.22-stable.tar.gz && chown -R root:root libevent-2.0.22-stable
    - unless: test -d /usr/local/src/libevent-2.0.22-stable
    - require:
      - file: libevent-source
libevent-compile:
  cmd.run:
    - name: cd /usr/local/src/libevent-2.0.22-stable && ./configure --prefix=/usr/local/libevent && make && make install
    - unless: test -d /usr/local/libevent
    - require:
      - cmd: libevent-extrace

4. Memcached配置

[[email protected]_210 ~]# cd /data/etc/salt/memcache/memcached/files/
[[email protected]_210 files]# wget http://www.memcached.org/files/memcached-1.4.31.tar.gz
[[email protected]_210 files]# vim ../install.sls
include:
  - memcache.libevent.install
memcached-source:
  file.managed:
    - name: /usr/local/src/memcached-1.4.31.tar.gz
    - unless: test -e /usr/local/src/memcached-1.4.31.tar.gz
    - source: salt://memcache/memcached/files/memcached-1.4.31.tar.gz
    - user: root
    - group: root
    - mode: 644
memcached-extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf memcached-1.4.31.tar.gz && chown -R root:root memcached-1.4.31
    - unless: test -d /usr/local/src/memcached-1.4.31
    - require:
      - file: memcached-source
memcached-install:
  cmd.run:
    - name: cd /usr/local/src/memcached-1.4.31 && ./configure --prefix=/usr/local/memcached --enable-64bit --with-libevent=/usr/local/libevent && make && make install
    - unless: test -d /usr/local/memcached
    - require:
      - cmd: memcached-extrace

5. 启动Memcached服务

[[email protected]_210 ~]# cd /data/etc/salt/memcache/memcached/
[[email protected]_210 memcached]# vim service.sls
include:
  - memcache.memcached.install
  - memcache.user.create_90root
  - memcache.libevent.install
memcached-service:
  cmd.run:
    - name: /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -c 8096 -u 90root
    - unless: netstat -anpt | grep 11211
    - require:
      - cmd: memcached-install
      - user: 90root-user-group

6. 安装php memcache扩展

[[email protected]_210 ~]# cd /data/etc/salt/memcache/php-memcache/files
[[email protected]_210 files]# wget http://pecl.php.net/get/memcache-2.2.7.tgz
[[email protected]_210 php-memcache]# cat install.sls
memcache_plugin:
  file.managed:
    - name: /usr/local/src/memcache-2.2.7.tgz
    - source: salt://memcache/php-memcache/files/memcache-2.2.7.tgz
    - user: root
    - group: root
memcache_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf memcache-2.2.7.tgz && chown -R root:root memcache-2.2.7
    - unless:
      - file: memcache_plugin
memcache_compile:
  cmd.run:
    - names:
      - cd /usr/local/src/memcache-2.2.7 && /usr/local/php-fpm/bin/phpize && ./configure --enable-memcache --with-php-config=/usr/local/php-fpm/bin/php-config && make && make install
    - unless: test -f /usr/local/php-fpm/lib/php/extensions/*/memcache.so
    - require:
      - cmd: memcache_extrace
/usr/local/php-fpm/etc/php.ini:
  file.append:          -> 往上面文件追加memcache.so
    - text:
      - extension=memcache.so
[[email protected]_210 php-memcache]# ll files/
total 36
-rw-r--r-- 1 root root 36459 Mar 30  2015 memcache-2.2.7.tgz

7. 先测试,后安装memcached

[[email protected]_210 salt]# salt 'docker_211' state.highstate test=True

Linux自动化工具之SatlStack 安装memcached及扩展memcahce SaltStack Linux 自动化运维 第1张

[[email protected]_210 salt]# salt 'docker_211' state.highstate
[[email protected]_210 memcached]# salt 'docker_211' cmd.run 'netstat -anpt|grep 11211'
docker_211:
    tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      15351/memcached
    tcp        0      0 :::11211                    :::*                        LISTEN      15351/memcached
  移步手机端
Linux自动化工具之SatlStack_安装memcached及扩展memcahce

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录