Install the Redis and MongoDB tutorials under CentOS 7

  • 2020-05-13 04:15:28
  • OfStack

node.js, Redis, Mongodb, Mongodb, nodejs, Redis, Mongodb, nodejs

Redis

It is also easy to install Redis under CentOS. You can follow step by step without making any mistakes.

1, switch to /usr/src directory (if you install in a different directory, please note that you need to change some paths later), download Redis, the latest version is 2.8.13
d /usr/src


wget http://download.redis.io/releases/redis-2.8.13.tar.gz

2. Unzip and switch directories


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13

3, compile,


make
make install

4. Open redis.conf to modify the configuration file. The most important thing is the following lines.


daemonize yes
loglevel notice
logfile /var/log/redis.log
dir ./

5. Set overcommit_memory of the system and execute


vi /etc/sysctl.conf

Add 1 line to the file and save:


vm.overcommit_memory = 1

Perform:


sysctl vm.overcommit_memory=1

6. Add startup script and execute:


vi /etc/init.d/redis

Write the following code to save:


#!/bin/sh
#
# redis    Startup script for Redis Server
#
# chkconfig: - 90 10
# description: Redis is an open source, advanced key-value store. 
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
 
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
 
PIDFILE=/var/run/redis.pid
CONF="/usr/src/redis-2.8.13/redis.conf"
 
case "$1" in
  start)
    if [ -f $PIDFILE ]
    then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        $EXEC $CONF
    fi
    if [ "$?"="0" ] 
    then 
       echo "Redis is running..."
    fi 
    ;;
  stop)
    if [ ! -f $PIDFILE ]
    then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping ..."
        $REDIS_CLI -p $REDISPORT SHUTDOWN
        while [ -x ${PIDFILE} ]
        do
          echo "Waiting for Redis to shutdown ..."
          sleep 1
        done
        echo "Redis stopped"
    fi
    ;;
  restart|force-reload)
    ${0} stop
    ${0} start
    ;;
 *)
  echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
    exit 1
esac

Set permissions and boot:


chmod +x /etc/init.d/redis
chkconfig --add redis
chkconfig redis on

ok, now installed. Start redis use < code > service redis start < / code > or < code > / etc/init d/redis start < / code >, Stop redis command < code > service redis stop < / code > or < code > / etc/init d/redis stop < / code >, under windows system using redis can refer to this article.

MongoDB

1. Install MongoDB below, download first:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
0

2. Unzip and enter the directory:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
1

3, create the database and log directory:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
2

4. Starting the operation mode of the back desk:


./bin/mongod --dbpath=./db --logpath=./log/mongodb.log --fork --auth

The following will be displayed:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
4

5. Setup startup:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
5

ok, done. See port netstat-nalupt | grep mongo:


tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
6

The original link: http: / / keenwon com / 1335. html


Related articles: