First, NoSQL introduction
1, NoSQL (NoSQL =not only sql), meaning that "not only SQL", is a new database revolutionary movement, it was suggested in the early days, the trend of development to 2009 has become increasingly high.
2, NoSQL, refers to the database of the non relational type . With the rise of internet web2.0 Web sites, traditional relational databases are dealing with web2.0 websites, especially the hyper-scale and high concurrency SNS type of web2.0 pure Dynamic Web site has appeared to be powerless, exposing a lot of difficult to overcome problems, but the relational database is because of its own characteristics have been very rapid development.
3, NoSQL is in the form of Key-value storage, and traditional relational database is not the same, does not necessarily follow the traditional database of some basic requirements, such as:SQL standard (add to check), Acid Properties (Atomic (atomicity), Consistency (consistency), isolation (isolation), persistence (durability), table structure , and so on, such databases have the following characteristics: non-relational, distributed, open source, horizontally scalable.
4, the commonly used key value pairs:
Javascript:json
Java:hashmap
5, NoSQL characteristics
1 processing Ultra large amount of data
2 running on a cheap PC server cluster
3 Crushing the performance bottleneck
6, NoSQL applicable scene
1 high concurrent reading and writing of data
2 efficient storage and access to massive data
3 High scalability and high availability of data
Ii. introduction of Redis
1, Redis is an open source of the use of ANSI C language writing, support network, can be based on memory can also be persistent log-type, high-performance Key-value database, and provide a variety of language APIs.
2, similar to memcached, it supports a relatively greater number of stored value types, including string (String), list (linked list), set (set), Zset (sorted set-ordered set), and hash (hash type)
3, as with memcached, in order to ensure efficiency, the data is cached in memory . The difference is that Redis will periodically write the updated data into the disk or write the modification operation to the appended record file , and then realize the master-slave (Master-Slave) synchronization on this basis.
4. These data types support Push/pop, Add/remove and intersection sets, and the difference sets and richer operations, and these operations are atomic. On this basis, Redis supports a variety of different ways of ordering.
5. Redis Deployment Plan
1 The world's largest redis users are Sina Weibo
2 Application direct access to Redis database
3 The application accesses the Redis database directly and accesses MySQL only if Redis access fails.
6, Redis applicable occasions
1 to take the latest n data operations, such as: Take the latest 500 article
2 list application, take TOPN operation
3 need to accurately set the expiration time of the application
4) Counter Application
5 Uniq operation, get all the data weight values for a period of time
6) Real-time system, anti-spam system
7 Pub/sub construction of real-time messaging systems, such as: Publish and subscribe
8 Build the queue system, such as: Stack/queue
9) Caching
7, installation and deployment of Redis
Steps:
1) Download: wget http://download.redis.io/releases/redis-2.8.5.tar.gz
2) compiling the source program
Øtar ZXVF redis-2.8.5.tar.gz
ØCD redis-2.8.5
Ømake
ØCD SRC
Ømake Install
3) Moving files for easy management
Øsudo mkdir-p/usr/local/redis/bin
Øsudo mkdir-p/usr/local/redis/etc
Øsudo mv/home/lizhanhong/javatools/redis-2.8.5/redis.conf/usr/local/redis/etc
Øcd/home/lizhanhong/javatools/redis-2.8.5/src
Øsudo mv mkreleasehdr.sh Redis-benchmark redis-check-aofredis-check-dump redis-cli redis-server/usr/local/redis/bin/
4) Start Redis service
Ø/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf
The default connection port for the Øredis server is 6379
The default connection port for the Ømysql server is 3306
The default connection port for the ØMONGODB server is 27017
5) Client Connection
/usr/local/redis/bin/redis-cli
6) Stop Redis instance
Ø method One:/usr/local/redis/bin/redis-cli shutdown
Ø method Two: Pkill redis-server
Ø method Three: Kill-p process number
Ø View port: NETSTAT-TUNPL |grep 6379
Ø Open the Redis service when the system starts:
Add in/etc/rc.local
/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf |
7) Background Boot configuration
Modify the configuration file redis.conf inside the daemonize value is yes
8, the Redis configuration
Daemonize whether the later process runs, the default is no Pidfile If the process is running later, you need to specify a PID, the default is/var/run/redis.pid Bind binding host IP, default value is 127.0.0.1 (note) Port listening ports, defaults to 6379 Timeout timeout, defaults to 300 (sec) LogLevel logging level, with 4 optional values, Debug,verbose (default), notice,warning LogFile logging method, default value is stdout Databases number of available databases, default is 16, default database is 0 Save indicates how many times the update operation has been synchronized to the data file for how long. This can be a combination of conditions, such as the default configuration file settings, set three conditions. Save 900 1 900 seconds (15 minutes) at least 1 keys are changed Save 300 10 300 seconds (5 minutes) at least 300 keys are changed Save 60 10000 60 seconds at least 10,000 keys have been changed Rdbcompression whether to compress data when it is stored to the local database, by default Yes Dbfilename the local database filename, the default value is Dump.rdb Dir The local database holds the path, and the default value is./ Slaveof the IP and port of the primary service when the native is from service (note) Masterauth Set the connection password for the primary service when this computer is from service (note) Requirepass Connection Password (note) MaxClients Maximum number of client connections, default unrestricted (note) MaxMemory set the maximum memory, the maximum memory settings, Redis will first attempt to clear the expired or expiring key, when this method is processed, the maximum memory settings, will no longer write operations. Comments AppendOnly whether logging after each update operation may result in loss of data for a period of time if the power is not turned on. Because the Redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. The default value is no Appendfilename Update log file name, default value is appendonly.aof (note) Appendfsync Update log conditions, there are 3 optional values. No means that the operating system synchronizes the data cache to disk, and always indicates that Fsync () is manually invoked after each update operation to write the data to disk, Everysec is synchronized every second (the default). Vm-enabled whether to use virtual memory, the default value is no Vm-swap-file virtual memory file path, default value is/tmp/redis.swap, not multiple Redis instance sharing Vm-max-memory stores all data larger than vm-max-memory into virtual memory, regardless of how small the vm-max-memory settings are, all index data is stored in memory (the index data for the Redis is the keys), that is to say, When Vm-max-memory is set to 0, all of the value is in the disk. The default value is 0. |