Home Database Mysql Tutorial 在CentOS 7下安装Redis和MongoDB

在CentOS 7下安装Redis和MongoDB

Jun 07, 2016 pm 04:38 PM
centos mongodb redis Install

前一篇折腾了node.js,这一次折腾下Redis和Mongodb,这样基本就安装好nodejs的整套开发环境了。 Redis 在CentOS下安装Redis也比较简单,按照步骤一步一步的操作,基本不会出错。 1、切换到 /usr/src 目录(如果你安装在别的目录,注意后面要一些路径也要修改

前一篇折腾了node.js,这一次折腾下Redis和Mongodb,这样基本就安装好nodejs的整套开发环境了。


Redis

在CentOS下安装Redis也比较简单,按照步骤一步一步的操作,基本不会出错。

1、切换到/usr/src 目录(如果你安装在别的目录,注意后面要一些路径也要修改),下载Redis,目前最新的是2.8.13版本

cd /usr/src
wget http://download.redis.io/releases/redis-2.8.13.tar.gz
Copy after login

2、解压,切换目录

tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
Copy after login

3、编译

make
make install
Copy after login

4、打开redis.conf 修改配置文件,最关键是下面几行,其他的设置参考官方文档:

daemonize yes
loglevel notice
logfile /var/log/redis.log
dir ./
Copy after login

5、设置系统的overcommit_memory,执行

vi /etc/sysctl.conf
Copy after login

在文件中添加一行,保存:

vm.overcommit_memory = 1
Copy after login

执行:

sysctl vm.overcommit_memory=1
Copy after login

6、添加启动脚本,执行:

vi /etc/init.d/redis
Copy after login

写入下面的代码,保存:

#!/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
Copy after login

设置权限和开机启动:

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

ok,现在就安装好了。启动redis使用service redis start 或者/etc/init.d/redis start ,停止redis的命令service redis stop 或者/etc/init.d/redis stop ,在windows系统下使用redis可以参考这篇文章。

参考文章:

    http://hi.baidu.com/cxc0378/item/40f4b70e7fda603af3eafcbb

    http://www.saltwebsites.com/2012/install-redis-245-service-centos-6

    http://chenjinglys.blog.163.com/blog/static/16657571620127133616965


MongoDB

1、下面安装MongoDB,先下载:

cd /usr/src
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz
Copy after login

2、解压,进入目录:

tar -zxvf mongodb-linux-x86_64-2.6.4.tgz -C /usr/src
cd mongodb-linux-x86_64-2.6.4
Copy after login

3、创建数据库和日志的目录:

mkdir log
mkdir db
Copy after login

4、以后台运行方式启动:

./bin/mongod --dbpath=./db --logpath=./log/mongodb.log --fork
Copy after login

会显示如下内容:

about to fork child process, waiting until server is ready for connections.
forked process: 4623
child process started successfully, parent exiting
Copy after login

5、设置开机启动:

echo "/usr/src/mongodb-linux-x86_64-2.6.4/bin/mongod --dbpath=/usr/src/mongodb-linux-x86_64-2.6.4/db --logpath=/usr/src/mongodb-linux-x86_64-2.6.4/log/mongodb.log --fork" >> /etc/rc.local
Copy after login

ok,搞定,然后可以参看下端口netstat -nalupt | grep mongo

tcp   0   0 0.0.0.0:27017    0.0.0.0:*    LISTEN     4623/./bin/mongod
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Tips for using HDFS file system on CentOS Tips for using HDFS file system on CentOS Apr 14, 2025 pm 07:30 PM

The Installation, Configuration and Optimization Guide for HDFS File System under CentOS System This article will guide you how to install, configure and optimize Hadoop Distributed File System (HDFS) on CentOS System. HDFS installation and configuration Java environment installation: First, make sure that the appropriate Java environment is installed. Edit /etc/profile file, add the following, and replace /usr/lib/java-1.8.0/jdk1.8.0_144 with your actual Java installation path: exportJAVA_HOME=/usr/lib/java-1.8.0/jdk1.8.0_144exportPATH=$J

What files do you need to modify in HDFS configuration CentOS? What files do you need to modify in HDFS configuration CentOS? Apr 14, 2025 pm 07:27 PM

When configuring Hadoop Distributed File System (HDFS) on CentOS, the following key configuration files need to be modified: core-site.xml: fs.defaultFS: Specifies the default file system address of HDFS, such as hdfs://localhost:9000. hadoop.tmp.dir: Specifies the storage directory for Hadoop temporary files. hadoop.proxyuser.root.hosts and hadoop.proxyuser.ro

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to mount hard disk in centos How to mount hard disk in centos Apr 14, 2025 pm 08:15 PM

CentOS hard disk mount is divided into the following steps: determine the hard disk device name (/dev/sdX); create a mount point (it is recommended to use /mnt/newdisk); execute the mount command (mount /dev/sdX1 /mnt/newdisk); edit the /etc/fstab file to add a permanent mount configuration; use the umount command to uninstall the device to ensure that no process uses the device.

See all articles