Centos7编译安装redis

yum -y install gcc-c++
wget http://59.80.44.48/download.redis.io/releases/redis-5.0.4.tar.gz
tar -xvf redis-5.0.4.tar.gz -C /usr/local/	
cd /usr/local/redis-5.0.4/
make
make PREFIX=/usr/local/redis install
如果不做成systemctl服务
	vim /usr/local/redis-5.0.4/redis.conf
		daemonize yes			以守护进程的方式运行在后台
	/usr/local/redis-5.0.4/src/redis-server /usr/local/redis-5.0.4/redis.conf		启动
	/usr/local/redis-5.0.4/src/redis-cli shutdown				停止
做systemctl服务执行以下步骤
	vim /usr/lib/systemd/system/redis.service
		[Unit]
		Description=Redis persistent key-value database
		After=network.target
		[Service]
		ExecStart=/usr/local/redis-5.0.4/src/redis-server       /usr/local/redis-5.0.4/redis.conf --supervised systemd		指定启动用哪里的配置文件启动
		ExecStop=/usr/libexec/redis-shutdown
		Type=notify
		User=redis					
		Group=redis
		RuntimeDirectory=redis
		RuntimeDirectoryMode=0755
		[install]
		WantedBy=multi-user.target
	vim /usr/libexec/redis-shutdown		停止脚本
		#!/bin/bash
		test x"$REDIS_DEBUG" != x && set -x
		REDIS_CLI=/usr/local/redis-5.0.4/src/redis-cli
		SERVICE_NAME="$1"
		if [ -z "$SERVICE_NAME" ]; then
			SERVICE_NAME=redis
		fi
		CONFIG_FILE="/etc/$SERVICE_NAME.conf"
		HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1`
		PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1`
		PASS=`awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1`
		SOCK=`awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1`
		HOST=${HOST:-127.0.0.1}
		if [ "$SERVICE_NAME" = redis ]; then
			PORT=${PORT:-6379}
		else
			 PORT=${PORT:-26739}
		fi
		[ -z "$PASS"  ] || ADDITIONAL_PARAMS="-a $PASS"
		if [ -e "$SOCK" ] ; then
			 $REDIS_CLI -s $SOCK $ADDITIONAL_PARAMS shutdown
		else
			 $REDIS_CLI -h $HOST -p $PORT $ADDITIONAL_PARAMS shutdown
		fi
	useradd -r redis -s /sbin/nologin
	chmod a+x /usr/libexec/redis-shutdown
	vim /usr/local/redis-5.0.4/redis.conf
		logfile /var/log/redis/redis_log.log		日志目录,不做日志可以不写
		dir /usr/local/redis/redis_dbfile/		存放dump.rdb的目录
	mkdir /usr/local/redis/redis_dbfile/
	chmod 777 /usr/local/redis/redis_dbfile/		存放dump.rdb的目录
		{如果不想定义日志文件位置可不做
			mkdir /var/log/redis
			touch /var/log/redis/redis_log.log
			chmod -R 777 /var/log/redis/
		}
	cp /usr/local/redis-5.0.4/redis.conf /etc/		若不做日志定义,可不执行这条(配置文件不参考etc下的这个、而是启动脚本哪个)
	systemctl daemon-reload 
	systemctl start redis
	systemctl enable redis.service
	systemctl stop redis

你可能感兴趣的:(Centos7编译安装redis)