非关系型的数据库NoSQL-创新互联
NoSQL的总体介绍
成都创新互联基于成都重庆香港及美国等地区分布式IDC机房数据中心构建的电信大带宽,联通大带宽,移动大带宽,多线BGP大带宽租用,是为众多客户提供专业服务器托管报价,主机托管价格性价比高,为金融证券行业绵阳服务器托管,ai人工智能服务器托管提供bgp线路100M独享,G口带宽及机柜租用的专业成都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监听的服务器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时出现: 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数据结构
/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是一个链表结构,主要功能是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是集合,和我们数学中的集合概念相似,对集合的操作有添加删除元素,有对多个集合求交并差等操作
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类型常用命令
键值和服务器命令
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对应的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
启动出现错误 第二个启动失败
mongod -f /etc/mongod.conf
ERROR: child process failed, exited with error number 100
rm /var/lib/mongo/mongod.lock 删除 重启 就好了
MongoDB连接和用户管理
mongo
#创建用户
db.createUser({user:"admin",pwd:"123456",roles:[{role:'dbOwner',db:'userdb'}]})
#查看用户
db.system.users.find() //列出所有用户,需要切换到admin库下(use admin)
show users //查看当前库下所有的用户
#删除用户,需要切换到admin库
db.dropUser('admin')
3.3 MongoDB库和集合管理
db.version()
MongoDB副本集搭建
MongoDB副本集测试
MongoDB备份和恢复
php连接MongoDB
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:非关系型的数据库NoSQL-创新互联
分享网址:http://azwzsj.com/article/dpecsh.html