将来的你
一定会感谢现在拼命努力的自己

Redis实战案例:一键编译安装Redis脚本

实战案例:一键编译安装Redis脚本

[root@redis-node1 ~]#cat install_redis_for_centos.sh #!/bin/bash # #******************************************************************** #Author: wangxiaochun #QQ: 29308620 #Date: 2020-02-22 #FileName: install_redis_for_centos.sh #URL: http://www.magedu.com #Description: The test script #Copyright (C): 2020 All rights reserved #******************************************************************** . /etc/init.d/functions VERSION=redis-4.0.14 PASSWORD=123456 INSTALL_DIR=/apps/redis install() { yum -y install gcc jemalloc-devel || { action "安装软件包失败,请检查网络配置" false ; exit; } wget http://download.redis.io/releases/${VERSION}.tar.gz || { action "Redis 源码下载失败" false ; exit; } tar xf ${VERSION}.tar.gz cd ${VERSION} make -j 4 PREFIX=${INSTALL_DIR} install && action "Redis 编译安装完成" || { action "Redis 编译安装失败" false ;exit ; } ln -s ${INSTALL_DIR}/bin/redis-* /usr/bin/ mkdir -p ${INSTALL_DIR}/{etc,logs,data,run} cp redis.conf ${INSTALL_DIR}/etc/ sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e "/# requirepass/a requirepass $PASSWORD" ${INSTALL_DIR}/etc/redis.conf if id redis &> /dev/null ;then action "Redis 用户已存在" false else useradd -r -s /sbin/nologin redis action "Redis 用户创建成功" fi chown -R redis.redis ${INSTALL_DIR} cat >> /etc/sysctl.conf <<EOF net.core.somaxconn = 1024 vm.overcommit_memory = 1 EOF cat > /usr/lib/systemd/system/redis.service <<EOF [Unit] Description=Redis persistent key-value database After=network.target [Service] ExecStart=${INSTALL_DIR}/bin/redis-server ${INSTALL_DIR}/etc/redis.conf --supervised systemd ExecStop=/bin/kill -s QUIT \$MAINPID Type=notify User=redis Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=0755 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start redis &> /dev/null && action "Redis 服务启动成功,Redis信息如下:" || { action "Redis 启动失败" false ;exit; } redis-cli -a $PASSWORD INFO Server 2> /dev/null } install

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [ root @ redis - node1 ~ ] #cat install_redis_for_centos.sh #!/bin/bash # #******************************************************************** #Author:        wangxiaochun #QQ:            29308620 #Date:          2020-02-22 #FileName:      install_redis_for_centos.sh #URL:           http://www.magedu.com #Description:       The test script #Copyright (C):     2020 All rights reserved #******************************************************************** . / etc / init . d / functions VERSION = redis - 4.0.14 PASSWORD = 123456 INSTALL_DIR = / apps / redis   install ( ) { yum    - y install gcc jemalloc - devel || { action "安装软件包失败,请检查网络配置" false ; exit ; }   wget http : //download.redis.io/releases/${VERSION}.tar.gz || { action "Redis 源码下载失败" false ; exit; }   tar xf $ { VERSION } . tar . gz cd $ { VERSION } make - j 4 PREFIX = $ { INSTALL_DIR } install && action "Redis 编译安装完成" || { action "Redis 编译安装失败" false ; exit ; }   ln - s $ { INSTALL_DIR } / bin / redis - *    / usr / bin / mkdir - p $ { INSTALL_DIR } / { etc , logs , data , run } cp redis . conf    $ { INSTALL_DIR } / etc / sed - i . bak - e 's/bind 127.0.0.1/bind 0.0.0.0/' - e "/# requirepass/a requirepass $PASSWORD"    $ { INSTALL_DIR } / etc / redis . conf   if id redis & > / dev / null ; then      action "Redis 用户已存在" false    else      useradd - r - s / sbin / nologin redis      action "Redis 用户创建成功" fi   chown - R redis . redis $ { INSTALL_DIR }   cat >> / etc / sysctl . conf << EOF net . core . somaxconn = 1024 vm . overcommit_memory = 1 EOF   cat > / usr / lib / systemd / system / redis . service << EOF [ Unit ] Description = Redis persistent key - value database After = network . target   [ Service ] ExecStart = $ { INSTALL_DIR } / bin / redis - server $ { INSTALL_DIR } / etc / redis . conf -- supervised systemd ExecStop = / bin / kill - s QUIT \ $ MAINPID Type = notify User = redis Group = redis RuntimeDirectory = redis RuntimeDirectoryMode = 0755   [ Install ] WantedBy = multi - user . target   EOF systemctl daemon - reload systemctl start redis & > / dev / null && action "Redis 服务启动成功,Redis信息如下:" || { action "Redis 启动失败" false ; exit ; }   redis - cli - a $ PASSWORD INFO Server 2 > / dev / null   }   install  

赞(0) 打赏
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除,联系邮箱:contact@3yyy.top。文章观点不代表本站立场。本站原创内容未经允许不得转载:三叶运维 » Redis实战案例:一键编译安装Redis脚本
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏