In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
How to install Redis server on CentOS 7, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, hope you can gain something.
Redis is an open source multi-platform data storage software written in ANSI C, Redis can support Lua, C, Java, Python, Perl, PHP and many other languages.
Build Redis
Redis currently has no official RPM installation package, we need to compile from the source code, and in order to compile, we need to install Make and GCC.
If you don't have GCC and Make installed, use the yum installation.
Yum install gcc make
Download the tar package from the official website.
Curl http://download.redis.io/releases/redis-3.0.4.tar.gz-o redis-3.0.4.tar.gz
Decompress.
Tar zxvf redis-3.0.4.tar.gz
Enter the decompressed directory.
Cd redis-3.0.4
Use Make to compile the source file.
Make installation
Go to the directory of the source file.
Cd src
Copy the server and client of Redis to / usr/local/bin.
Cp redis-server redis-cli / usr/local/bin
It's best to copy sentinel,benchmark and check, too.
Cp redis-sentinel redis-benchmark redis-check-aof redis-check-dump / usr/local/bin
Create a redis configuration folder.
Mkdir / etc/redis
Create a valid directory to save data under / var/lib/redis
Mkdir-p / var/lib/redis/6379 system parameters
Some kernel parameters need to be configured for redis to work properly.
Configure vm.overcommit_memory to 1, which prevents the data from being truncated, as detailed here.
Sysctl-w vm.overcommit_memory=1
The maximum number of modified backlog connections exceeds the tcp-backlog value in redis.conf, which is the default value of 511. You can find more information about sysctl-based ip network tunnels at kernel.org.
Sysctl-w net.core.somaxconn=512
Remove support for transparent giant page memory (transparent huge pages) because this can cause latency and memory access problems during redis usage.
Echo never > / sys/kernel/mm/transparent_hugepage/enabledredis.conf
Redis.conf is the configuration file for redis, but you will see that the name of this file is 6379.conf, and this number is the network port on which redis listens. If you want to run more than one instance of redis, this name is recommended.
Copy the redis.conf of the example to / etc/redis/6379.conf.
Cp redis.conf / etc/redis/6379.conf
Now edit the file and configure the parameters.
Vi / etc/redis/6379.confdaemonize
Setting daemonize to no,systemd requires it to run in the foreground, otherwise redis will suddenly hang up.
Daemonize nopidfile
Set pidfile to / var/run/redis_6379.pid.
Pidfile / var/run/redis_6379.pidport
If you are not going to use the default port, you can modify it.
Port 6379loglevel
Sets the log level.
Loglevel noticelogfile
Modify the log file path.
Logfile / var/log/redis_6379.logdir
Set the directory to / var/lib/redis/6379
Dir / var/lib/redis/6379 security
Here are a few actions that can improve security.
Unix sockets
In many cases, client and server programs run on the same machine, so there is no need to listen to socket on the network. If this is similar to your usage, you can use unix socket instead of network socket. To do this, you need to configure port to 0, and then configure the following options to enable unix socket.
Sets the socket file for unix socket.
Unixsocket / tmp/redis.sock
Restrict permissions on socket files.
Unixsocketperm 700
Now in order for redis-cli to be accessible, you should point to the socket file with the-s parameter.
Redis-cli-s / tmp/redis.sockrequirepass
You may need remote access, and if so, you should set a password so that you are required to enter a password before each operation.
Requirepass "bTFBx1NYYWRMTUEyNHhsCg" rename-command
Imagine the output of the following instructions. Yes, this will output the configuration of the server, so you should deny this access whenever possible.
CONFIG GET *
To restrict or even prohibit this or other instructions, you can use the rename-command command. You must provide a command name and an alternative name. To prohibit it, you need to set the alternate name to an empty string, which prevents anyone from guessing the name of the command.
Rename-command FLUSHDB "FLUSHDB_MY_SALT_G0ES_HERE09u09u" rename-command FLUSHALL "rename-command CONFIG" CONFIG_MY_S4LT_GO3S_HERE09u09u "
Use a password to access through unix socket, and modify commands
Snapshot
By default, redis periodically dumps the dataset to the dump.rdb file in the directory we set up. You can use the save command to configure the frequency of the dump, whose first parameter is the time frame in seconds, and the second parameter is the number of changes made on the data file.
The keys are changed every 15 minutes and at least once.
Save 900 1
The keys have been modified at least 10 times every 5 minutes.
Save 300 10
The keys have been modified at least 10000 times every 1 minute.
Save 60 10000
The file / var/lib/redis/6379/dump.rdb contains the dump data of the dataset in memory since it was last saved. Because it first creates a temporary file and then replaces the previous dump file, there is no data corruption problem here, you don't have to worry, you can copy this file directly.
Start when you power on
You can use systemd to add redis to the system boot list.
Copy the sample init_script file to / etc/init.d, and note the port number represented by the script name.
Cp utils/redis_init_script / etc/init.d/redis_6379
Now we're going to use systemd, so create a unit file named redis_6379.service under / etc/systems/system.
Vi / etc/systemd/system/redis_6379.service
Fill in the contents below. For more information, please see systemd.service.
[Unit] Description=Redis on port 6379 [Service] Type=forkingExecStart=/etc/init.d/redis_6379 startExecStop=/etc/init.d/redis_6379 stop[Install] WantedBy=multi-user.target
Now add the options for memory overusage and backlog maximum that I modified earlier in / etc/sysctl.conf.
Vm.overcommit_memory = 1net.core.somaxconn=512
For transparent giant page memory support, there is no direct sysctl command to control, so you need to put the following command at the end of / etc/rc.local.
Echo never > / sys/kernel/mm/transparent_hugepage/enabled
This enables you to deploy redis services to many simple scenarios by setting these options, but there are many redis options for complex environments in redis.conf. In some cases, you can use replication and Sentinel to improve availability, or spread data across multiple servers to create server clusters.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.