
前一篇折腾了node.js,这一次折腾下Redis和Mongodb,这样基本就安装好nodejs的整套开发环境了。
Redis
在CentOS下安装Redis也比较简单,按照步骤一步一步的操作,基本不会出错。
1、切换到 /usr/src目录(如果你安装在别的目录,注意后面要一些路径也要修改),下载Redis,目前最新的是2.8.13版本
d /usr/src
?
|
1
|
wget http://download.redis.io/releases/redis-2.8.13.tar.gz
|
2、解压,切换目录
?
|
1
2
|
tarxzf redis-2.8.13.tar.gz
cdredis-2.8.13
|
3、编译
?
|
1
2
|
make
makeinstall
|
4、打开 redis.conf 修改配置文件,最关键是下面几行,其他的设置参考官方文档:
?
|
1
2
3
4
|
daemonize yes
loglevel notice
logfile /var/log/redis.log
dir./
|
5、设置系统的overcommit_memory,执行
?
|
1
|
vi/etc/sysctl.conf
|
在文件中添加一行,保存:
?
|
1
|
vm.overcommit_memory = 1
|
执行:
?
|
1
|
sysctl vm.overcommit_memory=1
|
6、添加启动脚本,执行:
?
|
1
|
vi/etc/init.d/redis
|
写入下面的代码,保存:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/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 ..."
sleep1
done
echo"Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo"Usage: /etc/init.d/redis {start|stop|restart|force-reload}">&2
exit1
esac
|
设置权限和开机启动:
?
|
1
2
3
|
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可以参考这篇文章。
MongoDB
1、下面安装MongoDB,先下载:
?
|
1
2
|
cd/usr/src
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz
|
2、解压,进入目录:
?
|
1
2
|
tar-zxvf mongodb-linux-x86_64-2.6.4.tgz -C /usr/src
cdmongodb-linux-x86_64-2.6.4
|
3、创建数据库和日志的目录:
?
|
1
2
|
mkdirlog
mkdirdb
|
4、以后台运行方式启动:
?
|
1
|
./bin/mongod--dbpath=./db--logpath=./log/mongodb.log --fork --auth
|
会显示如下内容:
?
|
1
2
3
|
about to fork child process, waiting untilserver is ready forconnections.
forked process: 4623
child process started successfully, parent exiting
|
5、设置开机启动:
?
|
1
|
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 --auth">> /etc/rc.local
|
ok,搞定,然后可以参看下端口 netstat -nalupt | grep mongo :
?
|
1
|
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 4623/./bin/mongod
|


























