安装3.x

[root@node1 ~]# yum install wget gcc-c++ make
[root@node1 ~]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[root@node1 ~]# tar -zxvf redis-3.2..tar.gz
[root@node1 ~]# mv redis-3.2. /usr/local/redis
[root@node1 ~]# cd /usr/local/redis/
[root@node1 redis]# make
[root@node1 redis]# make install

出错截图:

安装4.0.x

[root@node4 redis]# yum install wget gcc-c++ make
[root@node4 ~]# wget http://download.redis.io/releases/redis-4.0.0.tar.gz
[root@node4 ~]# tar zxvf redis-4.0.0.tar.gz
[root@node4 ~]# mv redis-4.0.0 /usr/local/redis
[root@node4 ~]# cd /usr/local/redis/
[root@node4 redis]# yum install epel-release
[root@node4 redis]# yum install jemalloc-devel
[root@node4 redis]# ls deps/
hiredis jemalloc linenoise lua Makefile README.md update-jemalloc.sh
[root@node4 redis]# cd deps/
[root@node4 deps]# make hiredis lua jemalloc linenoise
[root@node4 deps]# cd ..
[root@node4 redis]# make
[root@node4 redis]# make install

出错截图:

服务器启动

redis-server

客户端启动

# redis-cli
127.0.0.1:> ping
PONG

开机启动

在源码包的utils目录下存在 install_server.sh 脚本,执行即可

假设安装目录为: /usr/local/redis/

[root@node1 ~]# cd /usr/local/redis/utils/
# 安装开机启动服务
[root@node1 utils]# ./install_server.sh
# 查看状态
[root@node1 utils]# systemctl status redis_6379
[root@node1 utils]# systemctl start redis_6379
# 查看是否开机自启动
[root@node1 utils]# systemctl is-enabled redis_6379

个人觉得redis_6379看着不舒服,于是对原配置文件稍作修改。

除了端口号后 安装效果如下:

[root@node4 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server Please select the redis port for this instance: []
Selecting default:
Please select the redis config file name [/etc/redis/redis.conf]
Selected default - /etc/redis/redis.conf
Please select the redis log file name [/var/log/redis.log]
Selected default - /var/log/redis.log
Please select the data directory for this instance [/var/lib/redis/]
Selected default - /var/lib/redis/
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port :
Config file : /etc/redis/redis.conf
Log file : /var/log/redis.log
Data dir : /var/lib/redis/
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/.conf => /etc/init.d/redis
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels !
Starting Redis server...
Installation successful!

修改后的配置文件如下:

#!/bin/sh

# Copyright  Dvir Volk <dvirsk at gmail dot com>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# . Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# . Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL Dvir Volk OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################
#
# Service installer for redis server, runs interactively by default.
#
# To run this script non-interactively (for automation/provisioning purposes),
# feed the variables into the script. Any missing variables will be prompted!
# Tip: Environment variables also support command substitution (see REDIS_EXECUTABLE)
#
# Example:
#
# sudo REDIS_PORT= \
# REDIS_CONFIG_FILE=/etc/redis/.conf \
# REDIS_LOG_FILE=/var/log/redis_1234.log \
# REDIS_DATA_DIR=/var/lib/redis/ \
# REDIS_EXECUTABLE=`command -v redis-server` ./utils/install_server.sh
#
# This generates a redis config file and an /etc/init.d script, and installs them.
#
# /!\ This script should be run as root
#
################################################################################ die () {
echo "ERROR: $1. Aborting!"
exit
} #Absolute path to this script
SCRIPT=$(readlink -f $)
#Absolute path this script is in
SCRIPTPATH=$(dirname $SCRIPT) #Initial defaults
_REDIS_PORT=
_MANUAL_EXECUTION=false echo "Welcome to the redis service installer"
echo "This script will help you easily set up a running redis server"
echo #check for root user
if [ "$(id -u)" -ne ] ; then
echo "You must run this script as root. Sorry!"
exit
fi if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then
_MANUAL_EXECUTION=true
#Read the redis port
read -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT
if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then
echo "Selecting default: $_REDIS_PORT"
REDIS_PORT=$_REDIS_PORT
fi
fi if [ -z "$REDIS_CONFIG_FILE" ] ; then
_MANUAL_EXECUTION=true
#read the redis config file
_REDIS_CONFIG_FILE="/etc/redis/redis.conf"
read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE
if [ -z "$REDIS_CONFIG_FILE" ] ; then
REDIS_CONFIG_FILE=$_REDIS_CONFIG_FILE
echo "Selected default - $REDIS_CONFIG_FILE"
fi
fi if [ -z "$REDIS_LOG_FILE" ] ; then
_MANUAL_EXECUTION=true
#read the redis log file path
_REDIS_LOG_FILE="/var/log/redis.log"
read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE
if [ -z "$REDIS_LOG_FILE" ] ; then
REDIS_LOG_FILE=$_REDIS_LOG_FILE
echo "Selected default - $REDIS_LOG_FILE"
fi
fi if [ -z "$REDIS_DATA_DIR" ] ; then
_MANUAL_EXECUTION=true
#get the redis data directory
_REDIS_DATA_DIR="/var/lib/redis/"
read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR
if [ -z "$REDIS_DATA_DIR" ] ; then
REDIS_DATA_DIR=$_REDIS_DATA_DIR
echo "Selected default - $REDIS_DATA_DIR"
fi
fi if [ ! -x "$REDIS_EXECUTABLE" ] ; then
_MANUAL_EXECUTION=true
#get the redis executable path
_REDIS_EXECUTABLE=`command -v redis-server`
read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE
if [ ! -x "$REDIS_EXECUTABLE" ] ; then
REDIS_EXECUTABLE=$_REDIS_EXECUTABLE if [ ! -x "$REDIS_EXECUTABLE" ] ; then
echo "Mmmmm... it seems like you don't have a redis executable. Did you run make install yet?"
exit
fi
fi
fi #check the default for redis cli
CLI_EXEC=`command -v redis-cli`
if [ -z "$CLI_EXEC" ] ; then
CLI_EXEC=`dirname $REDIS_EXECUTABLE`"/redis-cli"
fi echo "Selected config:" echo "Port : $REDIS_PORT"
echo "Config file : $REDIS_CONFIG_FILE"
echo "Log file : $REDIS_LOG_FILE"
echo "Data dir : $REDIS_DATA_DIR"
echo "Executable : $REDIS_EXECUTABLE"
echo "Cli Executable : $CLI_EXEC" if $_MANUAL_EXECUTION == true ; then
read -p "Is this ok? Then press ENTER to go on or Ctrl-C to abort." _UNUSED_
fi mkdir -p `dirname "$REDIS_CONFIG_FILE"` || die "Could not create redis config directory"
mkdir -p `dirname "$REDIS_LOG_FILE"` || die "Could not create redis log dir"
mkdir -p "$REDIS_DATA_DIR" || die "Could not create redis data directory" #render the templates
TMP_FILE="/tmp/${REDIS_PORT}.conf"
DEFAULT_CONFIG="${SCRIPTPATH}/../redis.conf"
INIT_TPL_FILE="${SCRIPTPATH}/redis_init_script.tpl"
INIT_SCRIPT_DEST="/etc/init.d/redis"
PIDFILE="/var/run/redis.pid" if [ ! -f "$DEFAULT_CONFIG" ]; then
echo "Mmmmm... the default config is missing. Did you switch to the utils directory?"
exit
fi #Generate config file from the default config file as template
#changing only the stuff we're controlling from this script
echo "## Generated by install_server.sh ##" > $TMP_FILE read -r SED_EXPR <<-EOF
s#^port .\+#port ${REDIS_PORT}#; \
s#^logfile .\+#logfile ${REDIS_LOG_FILE}#; \
s#^dir .\+#dir ${REDIS_DATA_DIR}#; \
s#^pidfile .\+#pidfile ${PIDFILE}#; \
s#^daemonize no#daemonize yes#;
EOF
sed "$SED_EXPR" $DEFAULT_CONFIG >> $TMP_FILE #cat $TPL_FILE | while read line; do eval "echo \"$line\"" >> $TMP_FILE; done
cp $TMP_FILE $REDIS_CONFIG_FILE || die "Could not write redis config file $REDIS_CONFIG_FILE" #Generate sample script from template file
rm -f $TMP_FILE #we hard code the configs here to avoid issues with templates containing env vars
#kinda lame but works!
REDIS_INIT_HEADER=\
"#!/bin/sh\n
#Configurations injected by install_server below....\n\n
EXEC=$REDIS_EXECUTABLE\n
CLIEXEC=$CLI_EXEC\n
PIDFILE=\"$PIDFILE\"\n
CONF=\"$REDIS_CONFIG_FILE\"\n\n
REDISPORT=\"$REDIS_PORT\"\n\n
###############\n\n" REDIS_CHKCONFIG_INFO=\
"# REDHAT chkconfig header\n\n
# chkconfig: - \n
# description: redis is the redis daemon.\n
### BEGIN INIT INFO\n
# Provides: redis_6379\n
# Required-Start: \$network \$local_fs \$remote_fs\n
# Required-Stop: \$network \$local_fs \$remote_fs\n
# Default-Start: \n
# Default-Stop: \n
# Should-Start: \$syslog \$named\n
# Should-Stop: \$syslog \$named\n
# Short-Description: start and stop redis\n
# Description: Redis daemon\n
### END INIT INFO\n\n" if command -v chkconfig >/dev/null; then
#if we're a box with chkconfig on it we want to include info for chkconfig
echo "$REDIS_INIT_HEADER" "$REDIS_CHKCONFIG_INFO" > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die "Could not write init script to $TMP_FILE"
else
#combine the header and the template (which is actually a static footer)
echo "$REDIS_INIT_HEADER" > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die "Could not write init script to $TMP_FILE"
fi ###
# Generate sample script from template file
# - No need to check which system we are on. The init info are comments and
# do not interfere with update_rc.d systems. Additionally:
# Ubuntu/debian by default does not come with chkconfig, but does issue a
# warning if init info is not available. cat > ${TMP_FILE} <<EOT
#!/bin/sh
#Configurations injected by install_server below.... EXEC=$REDIS_EXECUTABLE
CLIEXEC=$CLI_EXEC
PIDFILE=$PIDFILE
CONF="$REDIS_CONFIG_FILE"
REDISPORT="$REDIS_PORT"
###############
# SysV Init Information
# chkconfig: -
# description: redis is the redis daemon.
### BEGIN INIT INFO
# Provides: redis
# Required-Start: \$network \$local_fs \$remote_fs
# Required-Stop: \$network \$local_fs \$remote_fs
# Default-Start:
# Default-Stop:
# Should-Start: \$syslog \$named
# Should-Stop: \$syslog \$named
# Short-Description: start and stop redis
# Description: Redis daemon
### END INIT INFO EOT
cat ${INIT_TPL_FILE} >> ${TMP_FILE} #copy to /etc/init.d
cp $TMP_FILE $INIT_SCRIPT_DEST && \
chmod +x $INIT_SCRIPT_DEST || die "Could not copy redis init script to $INIT_SCRIPT_DEST"
echo "Copied $TMP_FILE => $INIT_SCRIPT_DEST" #Install the service
echo "Installing service..."
if command -v chkconfig >/dev/null >&; then
# we're chkconfig, so lets add to chkconfig and put in runlevel 345
chkconfig --add redis && echo "Successfully added to chkconfig!"
chkconfig --level redis on && echo "Successfully added to runlevels 345!"
elif command -v update-rc.d >/dev/null >&; then
#if we're not a chkconfig box assume we're able to use update-rc.d
update-rc.d redis defaults && echo "Success!"
else
echo "No supported init tool found."
fi /etc/init.d/redis start || die "Failed starting service..." #tada
echo "Installation successful!"
exit

install_server.sh

参考:

https://redis.io/topics/quickstart

centos7 源码安装redis的更多相关文章

  1. centos7源码安装Python3的前提条件

    centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...

  2. 高级运维(六):源码安装Redis缓存服务、常用Redis数据库操作指令、配置Redis主从服务器

    一.源码安装Redis缓存服务 目标: 本案例要求先快速搭建好一台Redis服务器,并测试该缓存服务器: 1> 设置变量test,值为123 2> 查看变量test的值 3> 设置计 ...

  3. CentOS7(Linux)源码安装Redis

    介绍 项目中经常需要用到Redis做缓存数据库,可是还有小伙伴不会在Linux上安装Redis,毕竟我们开发的项目都是要在服务器上运行的,今天就来讲讲如何在CentOS7环境使用源码进行安装Redis ...

  4. 搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展

    上一篇:搭建LNAMP环境(四)- 源码安装PHP7 一.安装Redis 1.创建redis用户组和用户 groupadd redis useradd -r -g redis -s /sbin/nol ...

  5. CentOS7源码安装Redis5.0.4非关系型数据库

    源码安装redis-5.0.4 一. 下载redis 1. 需要连接网络 二. 案例(另一种安装方法) [root@localhost ~]# wget http://download.redis.i ...

  6. centos7源码安装mysql5.7.19

    centos7源码包安装mysql5.7 5.7.20安装方法和5.7.19的一样. 1.安装前准备 清空环境.安装相应的软件包 1>关闭防火墙和SELinux 2>配置yum源(阿里云, ...

  7. Centos7源码安装mysql及读写分离,互为主从

       Linux服务器 -源码安装mysql 及读写分离,互为主从   一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...

  8. CentOS7源码安装qbittorrent最新版本

    CentOS的软件 yum 里 yum search qbittorrent yum info qbittorrent 找到的是3.37版本 官网最新的是4.12版本.但需要源码安装: 官网下载最新版 ...

  9. CentOS7 源码安装 PostgreSQL 12

    PostgreSQL 12 源码安装 Table of Contents 1. 下载 2. 准备环境 3. 编译安装 4. 设置环境变量 5. 初始化数据库 6. 配置参数文件 6.1. postgr ...

随机推荐

  1. jdbc,mysql 数据库BLOB返回值 [B 的问题

    当jdbc返回值类型对应的java类型是[B,那就表示返回值的类型比较模糊难以区分: BLOB类型是mysql数据库常用来存储,但是通过getBlob()方法获取值得时候会报错: 错误信息: java ...

  2. [hdu P3085] Nightmare Ⅱ

    [hdu P3085] Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  3. Oracle优化之旅:使用leading, use_nl, rownum调优例子

    1.使用leading和use_nl来设置表的查询顺序,来加快查询速度,一般把小表设为第一个表. /*+LEADING(TABLE)*/  将指定的表作为连接次序中的首表. /*+USE_NL(TAB ...

  4. 合并分支,从dev到master

    我在本地创建了dev分支,项目也push到远程的dev分支,今天在远程分支进行合并时,将dev合并到master,结果公司的gitlab始终不响应,我不知道是公司的网络不行还是我操作错误,就只能另想办 ...

  5. sql多表查询(单表查询略过)

    表library: 表borrow: 表reader: 1.等值连接:(常用) 原理:将多张表组合成一个逻辑大表,即字段相加记录相乘(笛卡尔积). 语法:select * from 表A,表B whe ...

  6. 数的全排列 dfs深度优先搜索

    数的全排列. 输入格式: 一个n(n<10),表示长度 输出格式: 按字典序输出长度为n的所有排列,每个排列后需要换行,每个排列数字以空格分开. 输入样例: 在这里给出一组输入.例如: 3 输出 ...

  7. Selenium HTMLTestRunner 执行测试成功但无法生成报告

    为什么用PyCharm或者Eclipse执行测试成功但无法生成HTMLTestRunner报告 最近遇到一些人问这样的问题: 他们的代码写的没问题,执行也成功了,但就是无法生成HTMLTestRunn ...

  8. 关于maven环境变量的配置问题

    开始使用“MAVEN_HOME”配置完环境变量后,在cmd中输入mvn -v提示不是内部命令,后直接在PATH 路径里面添加maven所在的位置+\bin,比如,maven的路径为E:\maven\a ...

  9. 剑指Offer 57. 二叉树的下一个结点 (二叉树)

    题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 题目地址 https://www.nowcoder.c ...

  10. 剑指Offer 8. 跳台阶 (递归)

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 题目地址 https://www.nowcoder.com/pract ...