
前一篇记录了Node.js,这一次说说在CentOS 7下安装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
- 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
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/221002.html<