In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis is a high-performance distributed in-memory database that supports data persistence (data in memory can be saved to the hard disk), list, hash, set, zset data types, and master-salve mode (master-slave).
Deploy redis services
1. Download the redis source code package, compile and install the source code
Tar zxf redis-4.0.8.tar.gz
Cd redis-4.0.8
Make
Make install
2. Initialization configuration (redis service port number, master configuration file, database directory, pid file, startup program)
. / utils/install_server.sh # initialization
3. Start and stop the service (/ etc/init.d/redis_6379 this file comes with a script after installing redis, which can be used to start and stop the service or view the service status)
/ etc/init.d/redis_6379 start
/ etc/init.d/redis_6379 stop
/ etc/init.d/redis_6379 status
Redis services are started and stopped by scripts. When you change the address port password in the configuration file, you need to modify these parameters in the / etc/init.d/redis_6379 script, because this script also uses the default parameters of redis to start or stop.
Redis basic command
Redis-cli # Connect to the redis service
Note: redis-cli does not write any parameters. By default, the local loop return address 127.0.0.1 is used to connect with the default port 6379. If you modify the listening address and port in the configuration file, you need to connect to the redis service with the corresponding parameters. For example, if we modify redis to allow other users to log in remotely using port 6352, modify bind 192.168.4.52 and port 6352 in the configuration file and use redis-cli-h 192.168.4.52-p 6352 to log in. If you use a password, you need to add the-an option followed by the password.
Ping # Test whether the connection is successful (return pong indicates success)
Set name lisi # Storage name is lisi
Get name # get the value of name
Select 2 # switches to 2 libraries (redis has 16 libraries by default)
Keys * # print all variables
Keys a? # print the specified table quantity (? Represents a character)
EXISTS name # tests whether name exists (there is display 1, there is no display 0)
Ttl name # check the lifetime of name (that is, how long the validity period is)
Type name # View the type of name
Move name 2 # move name to library 2
Expire name 10 # sets the validity time of name to 10 seconds
Del name # remove the name variable
Flushall # Delete all variables
Save # saves the stored data to the hard disk
Shutdown # shut down the redis service
Configuration file parsing
/ etc/redis/6379.conf
Prot 6379 # listening port
Bind 127.0.0.1 # listens to the ip address. If you need to log in remotely, you need to change it to the ip address of the local network card. You cannot use the local loopback address. If multiple addresses are separated by spaces,
Total number of tcp connections allowed by tcp-backlog 511 # redis (number of established connections + number of connections in progress)
Timeout 0 # connection timeout (0 means never timeout, timeout 30 means 30 seconds to start)
Tcp-keepalive 300 # long connection time (check if the connection is still there every 300 seconds)
Daemonize yes # daemon runs (that is, it runs in memory all the time, no runs in memory only when it is connected)
Number of databases 16 # databases
Logfile / var/log/redis_6379.log # pid file
Maxclients 10000 # redis service can handle the number of concurrent connections
Dir / var/lib/redis/6379 # database directory (redis data files are saved in this directory, named dump.rdb)
Requirepass 123456 # set the password to connect to the redis service (not set by default, because redis stores data in memory, it is built on linux, this service is controlled through a firewall, it is not responsible for security)
Memory clearing policy
-volatile-lru is the least used recently (for key with expiration time set)
-allkeys-lru removes the least used key
-volatile-random is randomly removed from an expired key.
-allkeys-random randomly removes key
-volatile-ttl (minor TTL) removes the most recently expired key
-noeviction does not delete the error of writing all over the Times
Options default settin
-maxmemory / / maximum memory (default unit is bytes)
-the policy in maxmemory-policy [noeviction] / / defines the policy used [] can be modified.
-maxmemory-samples 5 / / the number of template data selected (for lru and ttl strategies) the more accurate the general election, the greater the consumption of cpu
Deploy LNMP+Redis
1. Set up LNMP
A, source code compilation nginx
B, and configure nginx to support dynamic pages
Location ~\ .php$ {
Root html
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; # SCRIPT_FILENAME this is the name of the php file accessed by the client. $document_root tells php to explain that web file and get the pages accessed by the client.
Include fastcgi_params
}
C. Install mysql
D. Install php-fpm
2. Deploy PHP to support Redis
A. Install redis service
B. The default php is that you cannot connect to redis. You need to install the package php-redis that supports the php connection redis module.
Installing the php-devel package first will have the command / usr/bin/phpize, and then executing / usr/bin/phpize will generate the php-config configuration file under / usr/bin/, because the later configuration php-redis needs to get the configuration information of php, that is, the configuration file
Php-redis is a source code package, which needs to be compiled and installed.
Tar-zxf php-redis-2.2.4.tar.gz
Cd php-redis-2.2.4/
. / configure-- with-php-config=/usr/bin/php-config # configuration supports php-config configuration
Make
Make install
After the installation is completed, the module installation path information will be output. When we modify the php configuration file, we need to write this path and tell it to find our installed module under this path.
C. Test configuration
Php-m # looks at the modules supported by php
Modify php configuration file
Vim / etc/php/ini
Extension_dir = "/ usr/bin/php-config" # find the module under that path
Extension = "redis.so" # what's the module name?
Restart the php-fpm service test
Php connection redis Service php script page
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.