Tutorial on installing redis database on Linux server, linuxredis
Previously, Alan told you about jdk installation. In this article, we will talk about the installation of redis non-relational databases on Linux servers.
Redis Introduction
REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo.
Redis is an open-source log-type, Key-Value database written in ansi c language that complies with the BSD Protocol, supports the network, and can be persistent based on memory, and provides APIs in multiple languages.
It is usually called a Data Structure server, because values can be strings, maps, lists, sets) and sorted sets.
1. Installation on the Internet (I have talked about the internet configuration in the linux classification essay)
Step 1: Install the compilation tool. redis is written in ansi c language. We need to install the tool for compiling it.
Command: yum install wget make gcc-c ++ zlib-devel openssl-devel pcre-devel kernel keyutils patch perl
Step 2: Install the tcl package. We need to support the tcl script language when installing redis.
# Select a place where the software package is stored and enter the directory file of the software package.
Command: cd/usr/local/src
# Download the tcl package
Command: wget http://downloads.sourceforge.net/tcl/tcl8.6.6-src.tar.gz
# Decompress the tcl package in the current directory
Command: tar zxvf tcl8.6.6-src.tar.gz
# Enter the decompressed installation directory file
Command: cd tcl8.6.6
# Configure the tcl component
Command: cd unix
Command :. /configure -- prefix =/usr -- without-tzdata -- mandir =/usr/share/man $ ([$ (uname-m) = x86_64] & echo -- enable-64bit)
# Compile
Command: make
# Use the script specified in the options to process input text files
Command: sed-e "s @ ^ \ (TCL_SRC_DIR = '\). * @ \ 1/usr/include '@ "-e"/TCL_ B/s @ =' \ (-L \)\?. * Unix @ = '\ 1/usr/lib @ "-I tclConfig. sh
# Installation
Command: make install
Command: make install-private-headers
# Establishing a soft connection (like a shortcut in windows)
Command: ln-v-sf tclsh8.6/usr/bin/tclsh
# Modifying execution File Permissions
Command: chmod-v 755/usr/lib/libtcl8.6.so
Step 3: Install the Redis Database
# Select a place where the software package is stored and enter the directory file of the software package.
Command: cd/usr/local/src
# Download the redis database package
Command: wget http://download.redis.io/redis-stable.tar.gz
# Decompress the redis database package
Command: tar-zxvf redis-stable.tar.gz
# Create an installation directory file for redis
Command: mkdir/usr/local/redis
# Move the file to the installation directory
Command: mv redis-stable/usr/local/redis
# Enter the installation directory
Command: cd/usr/local/redis
# Compile
Command: make
# Installation
Command: make install
# Check whether redis program files exist in the/usr/local/bin directory. If no, copy the redis program files from redis-stable.
Command: cd/usr/local/bin
Command: ls
# Note: if not, copy
Command: cd/usr/local/redis-stable
Command: mkdir-p/usr/local/bin
# Copy operation
Command: cp-p redis-server/usr/local/bin
Command: cp-p redis-benchmark/usr/local/bin
Command: cp-p redis-cli/usr/local/bin
Command: cp-p redis-check-dump/usr/local/bin
Command: cp-p redis-check-aof/usr/local/bin
# Create a soft connection to the redis configuration file (like a shortcut in windows)
Command: ln-s/usr/local/redis-stable/redis. conf/etc/redis. conf
# Edit the redis configuration file
Command: vi/etc/redis. conf
# Set the background to start redis (vim editor press I to enter the edit mode, exit the edit mode to enter the command mode)
Daemonize yes
# Force save and exit
: Wq!
# Switch to the/usr/local/bin directory to start the redis Service (cd switching command)
Command: redis-server/etc/redis. conf
# Disable the redis Service
Command: redis-cli shutdown
# Edit, add the following code in the last line
Command: vi/etc/sysctl. conf
Vm. overcommit_memory = 1
# Force save and exit
: Wq!
# Make the settings take effect immediately
Command: sysctl-p
Step 4: Set redis to start on linux Server
# Copy the initialization script in the redis tool to the/etc/init. d/directory file and rename it
Command: cd/usr/local/redis-stable/utils/
Command: cp redis_init_script/etc/init. d/
Command: cd/etc/init. d/
Command: mv redis_init_script redis
# Modify the script execution permission
Command: chmod 755/etc/init. d/redis
# Add boot start
Command: chkconfig -- add redis
In this case, you may encounter a problem, that is, you cannot add redis to startup. How can this problem be solved?
# Edit the/etc/init. d/redis File
Command: vi/etc/init. d/redis (I enters the editing mode, exit returns the command mode: wq! Force save and Exit)
Add two lines of comment at the beginning to the comment at the front of the/etc/init. d/redis file:
# Chkconfig: 2345 90 10
# Description: Redis is a persistent key-value database
The above comment indicates that the redis service must be started or shut down under runtime Level 2, 3, 4, 5. The priority of startup is 90, and the priority of shutdown is 10.
# Add boot start
Command: chkconfig -- add redis
# Redis is in the on (on) status when the running level is 2, 3, 4, and 5.
Command: chkconfig-level redis 2345 on
# Check whether all system services are added successfully, and check whether redis exists in them.
Command: chkconfig -- list
# Disable the redis service and start the redis Service
Command: service redis stop
Command: service redis start
Last step: test whether redis has successfully started the service
# View the local IP Address
# Use a third-party jar package jedis to test in a local java application
I believe that many people will definitely fail during execution, such as connection timeout. Why? Let's solve the problem one by one:
1. view the redis configuration file, troubleshoot the problem, and save it after editing
Command: vi/etc/redis. conf
The first possible problem is that the ip address is bound and cannot be accessed by other ip addresses:
Comment out the property bound to the ip address and continue troubleshooting. Another possible problem is that the protection mode is Enabled:
Change "yes" to "no" and run java program tests. Many people may still encounter similar errors, such:
After the preceding operations, we can confirm that the redis service is started, the ip port is set correctly, and the protection mode is disabled and cannot be accessed, it is probably because of the Linux firewall that other computers cannot access port 6379 of redis. Now we test it on windows and open the command window through cmd. If the telnet command cannot be used, start it on Baidu.
Command: telnet 192.168.0.21 6379
If you haven't responded for a long time or encounter an error, you need to turn off the firewall on the Linux server or add this port to allow access.
# Log on to the Linux server as the root user and run the command to open the port
Command:/sbin/iptables-I INPUT-p tcp -- dport 6379-j ACCEPT
Then execute the Java application to test a wave. Basically, there is no problem, and we can get the correct results as above.
2. If there is no Internet, what should I do if there is only a LAN at this time?
Step 1: mount the image file corresponding to the Linux server to the/mnt directory file
For example: mount-o loop/data/downloads/redhat/rhel-server-6.5-x86_64-dvd.iso/mnt
# The image package contains the software required for most Linux games.
Cd/mnt/Packages
Step 2: Install the gcc compilation tool. obtain the relevant installation packages from the package of the centos6.6.iso image file.
Run the following command:
Rpm-ivh mpfr-2.4.1-6.el6.i686.rpm carriage return
Rpm-ivh cpp-4.4.6-4.el6.i686.rpm carriage return
Rpm-ivh kernel-headers-2.6.32-279.el6.i686.rpm carriage return
Rpm-ivh glibc-headers-2.12-1.80.el6.i686.rpm carriage return
Rpm-ivh glibc-devel-2.12-1.80.el6.i686.rpm carriage return
Rpm-ivh libgomp-4.4.6-4.el6.i686.rpm carriage return
Rpm-ivh ppl-0.10.2-11.el6.i686.rpm
Rpm-ivh cloog-ppl-0.15.7-1.2.el6.i686.rpm carriage return
Rpm-ivh gcc-4.4.6-4.el6.i686.rpm carriage return
Rpm-ivh libstdc +-devel-4.4.7-11.el6.x86_64.rpm carriage return
Rpm-ivh gcc-c ++-4.4.6-4. el6.i686. rpm press ENTER
If error: Failed dependencies: cpp = 4.4.7-4. el6 is needed by gcc-4.4.7-4.el6.x86_64
When installing gcc and other dependent packages, add the parameter -- force -- nodeps
For example:
Rpm-ivh gcc-4.4.7-4.el6.x86_64.rpm -- nodeps -- force
# Rpm uninstall command
Rpm-e -- nodeps gcc-4.4.7-4.el6.x86_64
# Detach a mounted Resource
Umount/mnt
Step 3: Install the downloaded tcl package on the Linux Server
Copy the file to the/usr/local/src directory (random directory)
Chmod 777 tcl8.6.1-src.tar.gz
Tar xzvf tcl8.6.1-src.tar.gz
Cd tcl8.6.1/nuix
./Configure or./configure -- prefix =/usr/local/tcl8.6.1/-- enable-shared
Make
Make install
Step 4: Install the downloaded redis database installation package on the Linux Server
Copy the file to the/usr/local/src directory (random directory)
Chmod 777 redis-2.8.8.tar.gz
Tar xzf redis-2.8.8.tar.gz
Cd redis-2.8.8
Make MALLOC = libc
Make test
Make install
Later, I will give you an idea about this method. You can use the above detailed online installation method to implement installation without the Internet, the main difference here is that the gcc compilation tool can be obtained from the mounted ios image without the Internet, and all the installation packages have been downloaded. You need to upload them to the Linux server by yourself, for the upload method, refer to the previous tutorial on installing the JDK running environment on a Linux server.
Conclusion: The silence that does not disturb others is compassion, and the self-esteem that does not harm others is kindness. If a person lives, just send his own light. Do not blow off others' lights.
Alimail: AlanLee
Blog: http://www.cnblogs.com/AlanLee
This article is from the blog site. You are welcome to join the blog site.