In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In the current Internet tide, NoSQL is a household name. As an important member of NoSQL, Redis makes us a necessary way to the architecture road. As an operation and maintenance engineer, it must be mastered!
Now that it is mentioned that the Redis database is non-relational data, you need to master the Redis database. Then the basic concepts of relational database and non-relational database must be understood.
First, the basic concepts of relational database and non-relational database:
According to its structure, database can be divided into relational database and other databases, and these other databases are collectively referred to as non-relational databases.
1. Relational database
Relational database is a structured database, which is based on relational model and is generally record-oriented. It deals with the data in the database with the help of mathematical concepts and methods such as set algebra. Relational model refers to two-dimensional table model, so a relational database is a data organization composed of two-dimensional tables and their relations. In the real world, all kinds of relationships between entities can be represented by relational models. SQL (structured query language) statement is a language based on relational database, which is used to perform the retrieval and operation of data in relational database.
The mainstream relational databases include Oracle, MySQL, SQL Server, Microsoft Access, DB2 and so on.
two。 Non-relational database
NoSQL: it means "not just SQL", which is the general name of non-relational database. The mainstream NoSQL databases are Redis, MongDB, Hbase, CouhDB and so on. These databases, their storage methods, storage structures and usage scenarios are all completely different. So we think of it as a collection of non-relational databases, rather than a general term like relational databases. To put it simply: databases other than mainstream relational databases can become non-relational databases. NoSQL database is considered as the next generation database product because of its advantages such as non-relational, distributed, open source and horizontal expansion.
3. Background of non-relational databases:
Relational database has been born for a long time, and we have been using it all the time, there is no problem, in the face of such a situation, why can we still produce non-relational database?
With the rise of Web 2.0 websites, relational databases have exposed many problems that are difficult to solve when dealing with Web 2.0 websites, especially Web 2.0 sites with massive data and high concurrency of SNS (social networking services). The main problems are the three high questions:
1) High concurrent read and write requirements for database
Web 2.0 websites generate dynamic pages and provide dynamic information in real time based on the personalized information of users. Therefore, the static technology of dynamic pages can not be used, so the concurrent load of the database is very high, generally reaching more than 10000 read and write requests per second. Relational database can barely support tens of thousands of query requests. When there are tens of thousands of write data requests, the hard disk Iswap O can no longer bear it. For ordinary BBS sites, there are often high concurrent write data requests. For example: revelations stars, etc., there will be a lot of comments. As a result, the website is likely to be paralyzed due to excessive traffic.
2) efficient storage of massive data in access requirements
Similar to large social networking sites, such as Facebook, Friendfeed and so on. Large-scale dynamic user information is generated every day. For example, Facebook generates 250 million pieces of user dynamic information a month. For a relational database, the SQL query is executed in a table with 250 million records. The efficiency is very low.
3) requirements for high scalability and availability of databases
In the Web architecture, the database is the most difficult to scale out. When the number of users and visits of the application system is increasing day by day, there is no way for the database to expand its performance and load capacity by adding hardware and server nodes like the Web server. Especially for some websites that need to provide servers 24 hours a day, the upgrade and expansion of the database are often accompanied by downtime maintenance and data migration, and its workload is very huge.
Both relational database and non-relational database have their own characteristics and application scenarios. The close combination of the two will bring new ideas to the database development of Web 2.0. Let relational databases focus on relationships, while non-relational databases focus on storage.
Through the above, you can roughly understand some basic concepts of non-relational, and then further understand-- Redis database.
II. Brief introduction of Redis Database basic 1.Redis Server
Redis is an open source, written in C language, supports the network, memory-based and persistent log-type, key-value (key-value pair) database, is an indispensable part of the current distributed architecture.
The Redis server program is a single-process model, that is, multiple Redis processes can be started on one server at the same time, while the actual processing speed of Redis completely depends on the execution efficiency of the main process. If only one Redis process is running on the server, the server's processing capacity will decrease to a certain extent when multiple clients access it at the same time. If multiple Redis processes are started on the same server, Redis will not only improve the concurrent processing capacity, but also cause great pressure on the server's CPU. In other words, in the actual production environment, you need to decide how many Redis processes to start according to the actual needs. If you have higher requirements for high concurrency, you may consider starting multiple processes on the same server. If CPU resources are tight, you can use a single process.
Redis has the following significant advantages:
It has extremely high reading and writing speed, and the maximum data reading speed can reach 110000 / s; the data writing speed can reach 81000 / s; it supports rich data types, including not only simple key-value data types, but also data types such as Strings, Lists, Hashes, Sets and Ordered Sets; it supports data persistence, and the data in memory can be saved on the hard disk and can be loaded and used again when rebooting. Atomicity, all Redis operations are atomic; supports data backup, and data backup in master-salve mode
As a database running in memory, caching is one of the more common application scenarios of Redis database. In addition, the common application scenarios of Redis include the operation of obtaining N pieces of data, ranking application, counter application, storage relationship, implementation analysis system, log recording and so on.
2.Redis database deployment
The installation of Redis database is relatively simple compared with other services. You can download the corresponding software package through the official website, or you can use the link of the network disk released by yourself: https://pan.baidu.com/s/1bOhIr3yJmSVUpjTdv_x3Kw
Extraction code: zp79
Upload to the Linux server for decompression and installation!
Usually, when you compile and install the source code in a Linux system, you need to execute. / configure to check and configure the environment. Thus generate the Makefile file, then execute the make & & make install command to compile and install, and the Redis source package directly provides the Makefile file, so after decompressing the package, you can directly enter the decompressed package directory and execute the make & & make install command to compile and install! As follows:
[root@localhost] # tar zxf redis-3.2.9.tar.gz-C / usr/src [root@localhost ~] # cd / usr/src/redis-3.2.9/ [root@localhost redis-3.2.9] # make & & make install
Install the redis service in the manner described above, and the default installation location is / usr/src/redis-3.2.9/src
During the installation process, if you want to install to the specified directory, it is best to enter the appropriate directory first, and then perform the appropriate operation! You can also use the following command:
[root@localhost redis-3.2.9] # make & & make PREFIX=/usr/local/ install// is installed to the / usr/local directory
Make install only installs binaries into the system without startup scripts and configuration files. An install_server.sh script file is provided by default in the package. Through this script file, you can set up the relevant configuration files required by the Redis service. When the script is finished, the Redis service is started, and the default listening port is 6379. The specific commands are as follows:
[root@localhost redis-3.2.9] # cd / usr/src/redis-3.2.9/utils/ [root@localhost utils] #. / install_server.sh / / enter the specified directory Run the script Welcome to the redis service installerThis script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379] / / set the port number Selecting default: 6379Please select the redis config file name [/ etc/redis/6379.conf] / / set the default configuration file Selected default-/ etc/redis/6379. ConfPlease select the redis log file name [/ var/log/redis_6379.log] / / set the log file Selected default-/ var/log/redis_6379.logPlease select the data directory for this instance [/ var/lib/redis/6379] / / set the data directory Selected default-/ var/lib/redis/6379Please select the redis executable path [/ usr/local/bin/redis-server] / / the command is stored at Selected config:Port: 6379Config file: / etc/redis/6379.confLog file: / var/log/redis_6379.logData dir: / var/lib/redis/6379Executable: / usr/local/bin/redis-serverCli Executable: / usr/local/bin/redis-cli / / is this the client command Is this ok? Then press ENTER to go on or Ctrl-C to abort. / / confirm the information and enter! Copied / tmp/6379.conf = > / etc/init.d/redis_6379Installing service...Successfully added to chkconfigsuccessful added to runlevels 345 starting Redis server...Installation fulfilling account account / the above information can be selected by default. [root@localhost ~] # netstat-anpt | grep redistcp 0 0127.0.0.1 anpt 6379 0.0.0.0 LISTEN 6396/redis-server 1 / / confirm that the listening port is 6379
After the installation is completed (the server has been started by default), you can use Redis's service control script to control the Redis service, as follows:
[root@localhost] # / etc/init.d/redis_6379 statusRedis is running (6396) [root@localhost] # / etc/init.d/redis_6379 stop [root@localhost] # / etc/init.d/redis_6379 restart3. Configuration parameters
The main configuration file of Redis is / etc/redis/6379.conf. By default, the configuration file can meet the requirements. Of course, you can also modify the configuration file according to the actual situation. The configuration file has a general content:
[root@localhost] # vim / etc/redis/6379.conf... / / omit part of the content bind 127.0.0.1 192.168.1.1 / / listener host address (preferably add your own IP address) port 6379 / / listener side Port daemonize yes / / start the daemon pidfile / var/run/redis_6379.pid / / specify the PID file loglevel notice / / Log level logfile / var/log/redis_6379.log / / specify the log file / / the configuration file of the redis service can work directly without modifying anything! / / restart the service after modifying the configuration file, this is common sense, don't be careless! [root@localhost ~] # / etc/init.d/redis_6379 restart
The parameters that can be referenced for optimizing Redis services are:
3. Redis service command tool
Redis software provides multiple command tools. When Redis is installed, the included software tools will be installed into the system at the same time and can be used directly in the system.
The role of the Redis service command tool:
Redis-server: a tool to start Redis services; redis-benchmark: to test the efficiency of Redis running on the native machine; redis-check-aof: to repair AOF persistence files; redis-check-rdb: to repair RDB persistence files; redis-cli:Redis command tool
This blog post mainly introduces the use of redis-cli and redis-benchmark command tools.
1.redis-cli command line tool
Redis database system is also a typical application of client / server architecture. Special client software is needed to access Redis database. The client software of the Redis service is an illegal operation on the redis-cli command line that comes with it. Use redis-cli to connect to the specified database, and after a successful connection, you will enter the database operating environment with the prompt "remote host IP address: Port number >". Users can enter a variety of operation statements to manage the database. For example:
[root@localhost ~] # redis-cli / / Connect to the local Redis database 127.0.0.1 Redis 6379 > ping / / check whether the Redis service is in startup status PONG
In the database connection operation, the client (provided that the redis command tool is supported) can specify the Redis database on the remote host through the option (there must be a real IP address in the Redis server configuration file). In the experimental environment, I forcibly shut down the firewall of the Redis server. In the actual environment, the corresponding port must be opened. The format of the command is as follows:
[root@localhost ~] # redis-cli-h 192.168.1.1-p 6379192.168.1.1Redis 6379 > info / / Log in successfully. Use "info" to view the details of the Redis server / / "- h" to specify the remote host, "- p" to specify the port number of the Redis service, and "- a" to specify the password of the redis database (omitted if there is no password)
In the database operating environment, you can use the help command to get the appropriate help for the command.
There are three ways to get command help:
Help @: get the list of commands in help: get help for a command help: get a list of possible topics for help
The specific operation methods are as follows:
[root@localhost ~] # redis-cli 127.0.0.1 help 6379 > help @ list / / View all commands related to the list data type. / / there are too many contents, so 127.0.0.1 help set 6379 > help set / / View the command format of the set command and help SET key value [EX seconds] [PX milliseconds] [NX | XX] summary: Set the string value of a key since: 1.0.0 group: string2. Redis-benchmark testing tool
Redis-benchmark is the official Redis performance testing tool, which can effectively test the performance of Redis services. The common options are shown in the figure:
According to the above options, you can test the performance of a Redis server. The command format is as follows:
[root@localhost] # redis-benchmark-h 192.168.1.1-p 6379-c 100-n 10000... / / omit part = MSET (10 keys) = 10000 requests completed in 0.26 seconds 100 parallel clients 3 bytes payload keep alive: 116.44% del K1 (integer) 1127.0.0.1 requests completed in 6379 > get K1 (nil) / / after deletion, the data corresponding to the K1 key will disappear. 4) type
Use the type command to get the value type corresponding to key, for example:
127.0.0.1 6379 > type k2string// string type 5) rename
The rename command renames an existing key in the format "rename source key destination key". When you use the rename command for a rename operation, it is renamed regardless of whether the destination key exists or not, and the value of the source key overrides the value of the destination key. In the process of practical use, it is recommended to use the exists command to check whether the target key exists, and then decide whether to execute the rename command to avoid overwriting important data. For example:
127.0.0.1 rename 6379 > get K2 "1qq" 127.0.0.1 get 6379 > get K3 "1q" 127.0.0.1 get 6379 > rename K2 k3OK127.0.0.1:6379 > get K3 "1qq" 6) renamenx
The syntax format and function of the renamenx command is the same as that of the rename command, except that renaming using the renamex command is yes, and renaming is not performed if the target key exists. For example:
127.0.0.1 keys 6379 > integer 1) "K11" 127.0.1 VR 6379 > renamenx K3 K11 (integer) 0 beat / return value is 0, indicating failure 7) dbsize
The purpose of the dbsize command is to view the number of key in the current database, for example:
127.0.1 6379 > dbsize (integer) 52. Common commands for multiple databases 1) switching between multiple databases
Redis supports multiple databases, with 16 databases by default, and the database name is represented by the number 0-15. Switch the database, as follows:
127.0.0.1 select 1OK127.0.0.1:6379 6379 > select 0OK127.0.0.1:6379 [1] > select 0OK127.0.0.1:6379 > / use the select command to switch. If there is nothing after the port number, it means database 0. 2) move data between multiple databases.
The multiple repositories of Redis are relatively independent to some extent. For example:
127.0.0.1 select 1OK127.0.0.1:6379 6379 > set Q1 1OK127.0.0.1:6379 > select 1OK127.0.0.1:6379 [1] > get Q1 (nil)
The Redis database provides a "move" command that can move data from multiple databases. For example:
127.0.0.1 move Q1 (integer) 1127.0.1 select 1OK127.0.0.1:6379 [1] > get Q1 "1" / / move the data of "Q1" in database 0 to database 1) clear the data in database 3)
The deletion of the entire database of the Redis database is mainly divided into two parts:
Emptying the data in the current database can be achieved using the "flushdb" command, and emptying all the database data can be achieved using the "flushall" command.
However, data emptying is dangerous and is generally not recommended in a production environment.
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.