在CentOS 7下安装Redis和MongoDB
前一篇折腾了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
2、解压,切换目录
tar xzf redis-2.8.13.tar.gz cd redis-2.8.13
3、编译
make make install
4、打开redis.conf
修改配置文件,最关键是下面几行,其他的设置参考官方文档:
daemonize yes loglevel notice logfile /var/log/redis.log dir ./
5、设置系统的overcommit_memory,执行
vi /etc/sysctl.conf
在文件中添加一行,保存:
vm.overcommit_memory = 1
执行:
sysctl vm.overcommit_memory=1
6、添加启动脚本,执行:
vi /etc/init.d/redis
写入下面的代码,保存:
#!/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
设置权限和开机启动:
chmod +x /etc/init.d/redis chkconfig --add redis chkconfig redis on
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
2、解压,进入目录:
tar -zxvf mongodb-linux-x86_64-2.6.4.tgz -C /usr/src cd mongodb-linux-x86_64-2.6.4
3、创建数据库和日志的目录:
mkdir log mkdir db
4、以后台运行方式启动:
./bin/mongod --dbpath=./db --logpath=./log/mongodb.log --fork
会显示如下内容:
about to fork child process, waiting until server is ready for connections. forked process: 4623 child process started successfully, parent exiting
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
ok,搞定,然后可以参看下端口netstat -nalupt | grep mongo
:
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 4623/./bin/mongod
原文地址:在CentOS 7下安装Redis和MongoDB, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

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.

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.
