欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

搭建 CentOS 6 服务器(7) - Memcached、Redis、MongoDB

程序员文章站 2022-03-03 22:55:07
...
(一)Memcached 1.4.21

(1)安装libevent
# cd /usr/local/src
# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
# tar xvfz libevent-1.4.13-stable.tar.gz
# cd libevent-1.4.13-stable
# ./configure --prefix=/usr/local/libevent
# make
# make install 
# echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
# ldconfig


(2)安装memcached
# cd /usr/local/src
# wget http://memcached.org/files/memcached-1.4.21.tar.gz
# tar -zxvf memcached-1.4.21.tar.gz
# cd memcached-1.4.21
# ./configure --with-libevent=/usr/local/libevent/
# make
# make install 


(3)设置memcached
# useradd -M memcached
# cp /usr/local/src/memcached-1.4.21/scripts/memcached.sysv /etc/rc.d/init.d/memcached
# vi /etc/rc.d/init.d/memcached
  USER=memcached
  # chown $USER /var/run/memcached
  # daemon memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P 

/var/run/memcached/memcached.pid $OPTIONS
  daemon --pidfile /var/run/memcached/memcached.pid /usr/local/bin/memcached -d -p $PORT -u $USER  

-m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
# mkdir /var/run/memcached
# chown memcached /var/run/memcached
# chkconfig --add memcached
# chkconfig --level 345 memcached on
# chkconfig --list memcached


(4)环境确认
# /etc/rc.d/init.d/memcached start
# telnet localhost 11211
  stats
  set mykey 0 900 4 
  ning
  STORED
  get mykey
  VALUE mykey 0 4
  ning
  END
  quit
# /etc/rc.d/init.d/memcached stop

引用
1)存储数据 set <key> <flags> <exptime> <bytes> [noreply]\r\n<value>\r\n
set key 0 900 8 (最后有一个空格)
data_key
STORED

2)获取数据 get <key>\r\n 或者 gets <key1> <key2>\r\n
get key
VALUE key 0 8
data_key
END

gets key1 key2
VALUE key1 0 9 16520
data_key1
VALUE key2 0 9 16521
data_key2
END

3)删除数据 delete <key> [<time>] [noreply]\r\n
delete key2
DELETED

4)其他
没有直接的命令来列举Memcached的所有keys,通过以下步骤可以获取Keys:

①stats items
>stats items
STAT items:3:number 1
STAT items:3:age 498
STAT items:22:number 1
STAT items:22:age 498
END

STAT items:<slabid>:<stat> <value>\r\n
items后的数字是slab id,number后的数字表示该slab下有几个Key。

②stats cachedump <slabid> <limit>
获取每个slab id的cache dump就能看到ITEM了。

>stats cachedump 3 100
ITEM hello [16 b; 1419815687 s]
END

ITEM <key> [<size> b; <time> s]\r\n
ITEM就是所有的Keys。

Memcached的telnet命令详细
可视化的管理工具:phpMemcachedAdmin

(二)Redis 2.8.17

(1)安装Redis
# cd /usr/local/src
# wget http://download.redis.io/releases/redis-2.8.17.tar.gz
# tar xzvf redis-2.8.17.tar.gz
# cd redis-2.8.17
# make


(2)设置Redis
# mkdir /etc/redis
# cp /usr/local/src/redis-2.8.17/redis.conf /etc/redis
# vi /etc/redis/redis.conf
  maxmemory 1GB
  slaveof 192.168.133.139 6379
# vim /etc/sysctl.conf
  vm.overcommit_memory = 1
# sysctl vm.overcommit_memory=1
# echo 1 > /proc/sys/vm/overcommit_memory  


(3)启动设置
# cd /usr/local/src
# wget --no-check-certificate https://raw.github.com/saxenap/install-redis-amazon-linux-

centos/master/redis-server
# mv redis-server /etc/init.d
# chmod 755 /etc/init.d/redis-server
# chkconfig --add redis-server
# chkconfig --level 345 redis-server on
# chkconfig --list redis-server


(4)环境确认
# service redis-server start
# redis-cli
  redis> set foo bar
  OK
  redis> get foo
  "bar"
  redis> exit
# service redis-server stop


可视化的管理工具:phpRedisAdmin

(三)MongoDB 2.6.5

(1)追加Repository
# vi /etc/yum.repos.d/mongodb.repo
  [mongodb]
  name=MongoDB Repository
  baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
  #baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
  gpgcheck=0
  enabled=1


(2)安装
# yum install -y mongodb-org


(3)启动设置
# chkconfig mongod on


(4)环境确认
# service mongod start
# mongod -version
# mongo
  > use test
  switched to db test
  > db.fish.insert({name: "rensanning"})
  WriteResult({ "nInserted" : 1 })
  > db.fish.find()
  { "_id" : ObjectId("545c8076dd75c0a6975ec7b0"), "name" : "rensanning" }
  > db.dropDatabase()
  { "dropped" : "test", "ok" : 1 }
  > show dbs
  admin  (empty)
  local  0.078GB
  > exit
  bye
# service mongod stop


MongoDB 3
安装
# vi /etc/yum.repos.d/mongodb-org.repo
  [mongodb-org-3.2]
  name=MongoDB Repository
  baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
  gpgcheck=1
  enabled=1
  gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc


启动提示警告
引用
** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.

# vi /etc/security/limits.conf
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000

引用
** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
**        We suggest setting it to 'never'
** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
**        We suggest setting it to 'never'

# vi  /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then  # mongodb
   echo never > /sys/kernel/mm/transparent_hugepage/enabled   # mongodb
fi                                                            # mongodb
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then   # mongodb
   echo never > /sys/kernel/mm/transparent_hugepage/defrag    # mongodb
fi                                                            # mongodb
# chmod +x /etc/rc.d/rc.local
# shutdown -r now


修改绑定IP

# vi /etc/mongod.conf

引用
#  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.
  bindIp: 0.0.0.0


可视化的管理工具:RockMongo

搭建 CentOS 6 服务器(7) - Memcached、Redis、MongoDB
            
    
    博客分类: Linux
  • 搭建 CentOS 6 服务器(7) - Memcached、Redis、MongoDB
            
    
    博客分类: Linux
  • 大小: 43.7 KB