Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Learning and Practice     - WEB-based Android Remote Tools Python implementation (Programming)

- EXP-00091: Exporting questionable statistics Processing Method (Database)

- Android memory optimization of the memory cache (Linux)

- To use Linux to create a secure managed gateway (Linux)

- Android imitation UC browser scroll up and down functions (Programming)

- Use small network command to check whether PC Security (Linux)

- Android thread mechanism --AsyncTask (Programming)

- Partition contrast manifestations under Windows and Linux (Linux)

- Apache2.4.7 make an error [exports.lo] Error 1 Solution (Server)

- Linux under DB2SQL1024N A database connection does not exist. SQLS (Database)

- Detailed usage history command (Linux)

- Oracle Listener can not start (TNS-12555, TNS-12560, TNS-00525) (Database)

- Redis logging system (Database)

- Cobbler Add custom YUM source (Linux)

- Vim Common Command Summary (Linux)

- Android Service Lifecycle and usage (Programming)

- Du and df show disk space usage inconsistent Causes and Treatment (Linux)

- Elaborate .NET Multithreading: Thread Pool (Programming)

- Installed in the desktop version of Ubuntu Unity Tweak Tool (Linux)

- Ubuntu 15.04 using the Eclipse 4.4, Java 8 and WTP (Linux)

 
         
  Learning and Practice
     
  Add Date : 2018-11-21      
         
         
         
  Because the recent project will use redis, before the project will be used memcached, so redis carried out some research, here to do a more detailed order for sharing!

First, redis introduced

Redis is a high-performance key-value database. Redis the emergence of a large extent to compensate for the lack of such keyvalue memcached storage, in some cases can play a very good complementary role in the relational database. It is similar to memcached, but the data can be persistent, and support the data types are very rich. There are strings, linked lists, collections, and ordered sets. Support in the server-side calculation of the collection, and pay and complement (difference), also supports a variety of sorting functions. So Redis can also be seen as a data structure server.

All Redis data is stored in memory, and then from time to time asynchronously saved to disk (this is called "semi-persistent mode"); can also be changed every time the data is written to an append only file ( Aof) inside (this is called "full persistence mode"). It provides Python, Ruby, Erlang, PHP client, easy to use. The problem is that this project is still very new and may not be stable enough, and there are no practical examples of some large system applications. In addition, the lack of mc batch get is a relatively large problem, always get a lot of access to the network with the cost is not the same.

Performance test results:

SET operation 110,000 times per second, GET operations 81,000 times per second.

Second, redis installation
2.1, linux installation
  2.1.1, download the installation package
  Wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz

  (I currently the latest version is 2.6.14, you can go to https://code.google.com/p/redis/downloads/list view the latest version)

1 [root @ localhost 4setup] # wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz

  2.1.2, installation and deployment
123 [root @ localhost 4setup] # tar xzf redis-2.6.14.tar.gz
[Root @ localhost 4setup] # cd redis-2.6.14
[Root @ localhost redis-2.6.14] # make

  2.1.3, start the service
  In the src directory, run redis-server. If you do not specify the conf file, then the default configuration to start, if you specify the conf file, then press the conf file configuration start:
1 ./redis-server ../etc/redis.conf

  The default port for the Redis server is 6379.
  2.1.4, the client connection
  In the src directory, run redis-cli. For example, connect the machine redis, the following command:
1 ./redis-cli -h 127.0.0.1 -p 6379

  2.1.5, View the running status
  If you set the "daemonize no" in the conf file, the running status information will be printed directly in the terminal;
  If "daemonize yes" is set, it will run as a daemon in the background, and the log output location will be set by the logfile in conf, for example: logfile /usr/local/redis/var/redis.log
  2.1.6, stop redis instance
1 ./redis-cli shutdown

The author's simple set-up is:
Daemonize yes
Pidfile /usr/local/redis/var/redis.pid
Port 6379
Timeout 300
Loglevel debug
Logfile /usr/local/redis/var/redis.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump.rdb
Dir / usr / local / redis / var /
Appendonly no
Appendfsync always

2.2, Windows installation
Windows on the installation, configuration and Linux similar, or even simpler

Third, compared with memcached
  Memcache and redis are memory-based database, the data stored in memory, direct access through tcp, memcached advantage is fast, concurrency is high, the disadvantage is the limited data types, query function is not strong, generally used for caching. In our team project, the beginning is memcached, and later replaced by redis.
Compared to memcached:
1, redis persistent mechanism, you can regularly data in the persistent memory to the hard disk.
2, redis with binlog function, you can write all the operations log, when redis failure, according to binlog data recovery.
3, redis support virtual memory, you can limit the size of memory usage, when the data exceeds the threshold, then similar to the LRU algorithm to the memory of the least commonly used data is saved to the hard disk page file.
4, redis native support for more data types, the use of a larger imagination.
5, in front of a friend mentioned by the consistency of the hash, used in redis sharding, the general needs of the load is very high when the level of expansion. We have not used this feature, the general project, stand-alone enough to support concurrency. Redis 3.0 will launch the cluster, more powerful.

I. Introduction

Redis master / slave data replication can be a master-slave or a main and more from the way, Redis in the master non-blocking mode, that is in the slave implementation of data synchronization, master is acceptable to the client's request, Does not affect the synchronization of data consistency, but in the slave side is blocking mode, slave master data in the synchronization, and can not respond to client queries.

Redis master / slave mode, master data read and write services, and slave only read services.

Features:

1.master can have multiple slaves;

2. In addition to a number of slave connected to the same master, slave can also connect other slave formation of graphics structure;

3. Master-slave replication does not block master. That is, when one or more slave master synchronization with the master for the first time, the master can continue to handle the request sent by the client;

On the contrary slave in the initial data synchronization will be blocked when the request can not handle client;

4. Master-slave replication can be used to improve the scalability of the system, we can use a number of slaves devoted to client read request,

Such as sort operation can be used to deal with the slave. Can also be used to do simple data redundancy;

5. You can disable data persistence in master by simply commenting out all save configurations in the master configuration file and then configuring data persistence only on the slave.

Second, the configuration process:
Redis master / slave configuration is in the redis directory of the slave host redis.conf configuration file to add "slaveof master_ip master_port", such as:

Slaveof 127.0.0.1 6379

For example: We configure our slave to: redis-slave.conf
Daemonize yes
Pidfile redis-slave.pid
Port 6380
Timeout 300
Loglevel verbose
Logfile stdout
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump-slave.rdb
Dir / usr / local / redis / var /
Slaveof 127.0.0.1 6379
Appendonly no
Appendfsync everysec

Start slave:
./redis-server redis-slave.conf

Third, the configuration example:

I have two machines, a Linux machine A (ip: 172.16.205.186), a Windows machine B (ip: 192.168.30.86). A machine configuration of a 6379 port master, 6380 port slave1; B machines were allocated 6380 and 6381 of the slave2 and slave3.

A Linux machine configuration is as follows:
[Root @ DEV etc] # ls
Redis.conf redis-slave1.conf
[Root @ DEV etc] # cat redis.conf
Daemonize yes
Pidfile /usr/local/redis/var/redis.pid
Port 6379
Timeout 300
Loglevel debug
Logfile /usr/local/redis/var/redis.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump.rdb
Dir / usr / local / redis / var /
Appendonly no
Appendfsync always
[Root @ DEV etc] # cat redis-slave1.conf
Daemonize yes
Pidfile redis-slave.pid
Port 6380
Timeout 300
Loglevel verbose
Logfile stdout
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump-slave.rdb
Dir / usr / local / redis / var /
Slaveof 127.0.0.1 6379
Appendonly no
Appendfsync everysec

B Windows machines are configured as follows:

Slave2:
Daemonize yes
Pidfile redis-slave2.pid
Port 6380
Timeout 300
Loglevel verbose
Logfile stdout2
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump-slave2.rdb
Dir ./
Slaveof 172.16.205.186 6379
Appendonly no

Slave3:
Daemonize yes
Pidfile redis-slave3.pid
Port 6381
Timeout 300
Loglevel verbose
Logfile stdout3
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression yes
Dbfilename dump - slave3.rdb
Dir ./
Slaveof 172.16.205.186 6379
Appendonly no

This achieved a linux master a slave, windows two slave, and three slave with a master. Of course, you can also slave as another master slave, only in the conf file "slaveof < ip> < port>" modified for the corresponding slave information on the line.
     
         
         
         
  More:      
 
- Installation Android IDE development tools, Android Studio 1.5 under Ubuntu (Linux)
- Linux System Getting Started Learning: In RedHat Linux driver compiled Ixgbe (Linux)
- Oracle 11g em start newspaper site's security certificate has a solution to the problem (Database)
- Getting Started with Linux system to learn: how to use tcpdump to capture TCP SYN, ACK and FIN packets (Linux)
- RHEL5.8 physical opportunities to Read-only file system (Linux)
- CentOS replaces update source and Linux kernel compilation summary (Linux)
- Compiling source code Nginx module installation subs_filter (Server)
- ARM Linux system call (Linux)
- Linux disk quota-related instruction (Linux)
- MyCAT log analysis (Database)
- How to clear the DNS query cache under Linux / Unix / Mac (Linux)
- CentOS 7.1 install NTFS-3G (Linux)
- Python Multithreaded Programming (Programming)
- Java open source monitoring platform Zorka basic use (Linux)
- J2EE Example of Filter (Programming)
- Expert advice: Do not use the computer security IE browser (Linux)
- Add a custom encryption algorithm in OpenSSL (Linux)
- Zabbix Agent (Server)
- 11.2.04 Oracle RAC directory crfclust.bdb file is too large, Bug 20186278 (Database)
- Spring Data MongoDB combat (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.