NoSQL的總體介紹
成都創(chuàng)新互聯(lián)基于成都重慶香港及美國等地區(qū)分布式IDC機房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管報價,主機托管價格性價比高,為金融證券行業(yè)綿陽服務(wù)器托管,ai人工智能服務(wù)器托管提供bgp線路100M獨享,G口帶寬及機柜租用的專業(yè)成都idc公司。http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=8660&highlight=NoSQL
memcached介紹
1.3 memcached安裝
http://www.apelearn.com/bbs/thread-9285-1-1.html
yum install -y epel-release
rpm -qa epel-release
yum install -y livevent memcached libmemcached
/etc/init.d/memcached start
netstat -lnp
ps aux |grep memcached
vi /etc/init.d/memcached
cat /etc/sysconfig/memcached
-l監(jiān)聽的服務(wù)器ip
memcached-tool 127.0.0.1:11211 stats
memstat --servers=127.0.0.1:11211
1.4 Memcached基本操作
telnet 127.0.0.1 11211
set key3 123 200 3
123
replace key3 123 210 4
1234
get key3
php連接memcached
cd /usr/local/src/
wget http://www.lishiming.net/data/p_w_upload/forum/memcache-2.2.3.tgz
tar zxf memcache-2.2.3.tgz
php 下載 裝了不需要裝 沒裝重新從mysql 裝起來
http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror
cd memcache-2.2.3
/usr/local/php/bin/phpize
運行/usr/local/webserver/php/bin/phpize時出現(xiàn): Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. 解決方法 # yum install m4 # yum install autoconf
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
vim /usr/local/php/etc/php.ini
cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so /usr/local/php/ext
ls !$
vim /usr/local/php/etc/php.ini
extension="memcache.so" 添加
/usr/local/php/bin/php -m
wget www.apelearn.com/study_v2/.memcache.txt
/usr/local/php/bin/php test.php
Memcached共享Session
1.7 Redis介紹和安裝
http://www.apelearn.com/bbs/thread-9286-1-1.html
cd /usr/local/src
wget https://codeload.github.com/antirez/redis/tar.gz/2.8.21
mv 2.8.21 redis-2.8.21.tar.gz
tar zxvf redis-2.8.21.tar.gz
yum install -y epel-rele
yum install -y jemalloc-devel
make
make PREFIX=/usr/local/redis install
mkdir /usr/local/redis/etc
wget http://www.apelearn.com/study_v2/.redis_conf -O /usr/local/redis/etc/redis.conf 2>/dev/null
cat /usr/local/redis/etc/redis.conf
wget http://www.apelearn.com/study_v2/.redis_init -O /usr/local/redis/etc/redis.conf 2 >/dev/null
useradd -s /sbin/nologin redis
mkdir /usr/local/redis/var
chmod 777 /usr/local/redis/var/
vi /etc/init.d/redis
添加啟動腳本
chmod 755 /etc/init.d/redis
chkconfig --add redis
service redis start
Redis數(shù)據(jù)結(jié)構(gòu)
/usr/local/redis/bin/redis-cli
alias redis-cli='/usr/local/redis/bin/redis-cli'
vi .bshre
cp /etc/skel/.bashrc .bashre 沒有 就拷貝
#.bashre
#User specific allases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias redis-cli='/usr/local/redis/bin/redis-cli'
# Source global definitions
if [-f /etc/bashrc ]; then
. /etc/bashrc
fi
redis-cli
set key1 aminglinux
OK
127.0.0.1:6379> get key1
"aminglinux"
127.0.0.1:6379> mset key1 aminglinux key2 hello key3 love
OK
127.0.0.1:6379> mget key1 key2 key3
1) "aminglinux"
2) "hello"
3) "love"
redis-cli get key1
whereis redis 查看文件路徑 安裝地址
list是一個鏈表結(jié)構(gòu),主要功能是push、pop、獲取一個范圍的所有值等等。操作中key理解為鏈表的名字。
lrange list1 0 -1
1) "123 456"
2) "aaa"
127.0.0.1:6379> lpop list1
"123 456"
127.0.0.1:6379> rpush list1 aaa
(integer) 2
127.0.0.1:6379> lrange list1 0 -1
1) "aaa"
2) "aaa"
-set
set是集合,和我們數(shù)學(xué)中的集合概念相似,對集合的操作有添加刪除元素,有對多個集合求交并差等操作
zadd myset2 12 "abc"
(integer) 1
127.0.0.1:6379> zadd myset2 12 "abc 123"
(integer) 1
127.0.0.1:6379> zadd myset2 12 "123-aaa"
(integer) 1
127.0.0.1:6379> zrange myset2 0 -1 正序
zrevrange myset2 0 -1 倒序
hset hash3 name aaa
(integer) 1
127.0.0.1:6379> hset hash3 age 10
(integer) 1
127.0.0.1:6379> set hash3 sex nan
(error) ERR syntax error
127.0.0.1:6379> hset hash3 sex nan
(integer) 1
127.0.0.1:6379> hgettall hash3
(error) ERR unknown command 'hgettall'
127.0.0.1:6379> hgetall hash3
1) "name"
2) "aaa"
3) "age"
4) "10"
5) "sex"
6) "nan"
hget hash3 age
1.9 Redis持久化
2.0 Redis配置講解(上)
Redis配置講解(下)
Redis主從配置
2.3 string類型常用命令
hash類型常用命令
source .bashrc
echo $PATH
vi /etc/profile
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
2.5 list類型常用命令
set類型常用命令
zset類型常用命令
鍵值和服務(wù)器命令
2.9 php使用Redis存儲
cd /usr/local/src
wget https://codeload.github.com/phpredis/phpredis/zip/develop
mv develop phpredis.zip
yum install -y unzip
unzip phpredis.zip
cd phpredis-develop/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
vi /usr/local/php/etc/php.ini
最后添加一行
extension = redis.so
vi /usr/local/apache2/conf/httpd.conf
去掉 servername 前的 #
lphp.ini中加入
session.save_handler = "redis"
session.save_path = "tcp://127.0.0.1:6379"
或者apache虛擬主機加入
php_valuesession.save_handler " redis"
php_valuesession.save_path " tcp://127.0.0.1:6379"
或者php-fpm.conf對應(yīng)的pool中加入
php_value[session.save_handler] = redis
php_value[session.save_path] = " tcp://127.0.0.1:6379
3.0 MongoDB介紹
3.1 MongoDB安裝
http://www.apelearn.com/bbs/thread-9287-1-1.html
vim /etc/yum.repos.d/mongodb-org-3.0.repo
加入:
[mongodb-org-3.0]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1
yum install -y mongodb-org
ls /etc/init.d/mongod
ls /etc/mongod.conf
ls /var/log/mongodb/
ls /var/lib/mongo/
vim /etc/mongod.conf
/etc/init.d/mongod start
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
vim /etc/security/limits.con
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
service mongod start
啟動出現(xiàn)錯誤 第二個啟動失敗
mongod -f /etc/mongod.conf
ERROR: child process failed, exited with error number 100
rm /var/lib/mongo/mongod.lock 刪除 重啟 就好了
MongoDB連接和用戶管理
mongo
#創(chuàng)建用戶
db.createUser({user:"admin",pwd:"123456",roles:[{role:'dbOwner',db:'userdb'}]})
#查看用戶
db.system.users.find() //列出所有用戶,需要切換到admin庫下(use admin)
show users //查看當(dāng)前庫下所有的用戶
#刪除用戶,需要切換到admin庫
db.dropUser('admin')
3.3 MongoDB庫和集合管理
db.version()
MongoDB副本集搭建
MongoDB副本集測試
MongoDB備份和恢復(fù)
php連接MongoDB
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。