Hi 你好,欢迎访问!登录
当前位置:首页 - 自动化运维 - 正文 忍人所不忍,能人所不能。

Linux自动化工具之安装redis及扩展redis

2020-03-16自动化运维90root229°c
A+ A-

1. 创建redis所需目录

[[email protected]_210 ~]# cd /data/etc/salt/
[[email protected]_210 salt]# mkdir -p redis/files
[[email protected]_210 ~]# cd /data/etc/salt/
[[email protected]_210 salt]# tree redis/
redis/
├── config.sls
├── files
│   ├── redis
│   ├── redis-2.2.5.tgz
│   ├── redis-3.0.1.tar.gz
│   ├── redis.conf
│   └── tcl8.6.5-src.tar.gz
├── init.sls
└── install.sls
[[email protected]_210 salt]# cat redis/init.sls
include:
  - redis.config
  - redis.install
[[email protected]_210 salt]# cat top.sls
base:
  '*':
    - redis.init

2. 下载redis所需文件

[[email protected]_210 salt]# cd redis/files/
[[email protected]_210 files]# wget http://downloads.sourceforge.net/tcl/tcl8.6.5-src.tar.gz
[[email protected]_210 files]# wget http://download.redis.io/releases/redis-3.0.1.tar.gz
[[email protected]_210 files]# wget http://pecl.php.net/get/redis-2.2.5.tgz

3. 编写redis文件

3.1 redis安装文件(install.sls)

[[email protected]_210 files]# cd /data/etc/salt/redis/
[[email protected]_210 redis]# cat install.sls
## Install config and install tcl
tcl_source:
  file.managed:
    - name: /usr/local/src/tcl8.6.5-src.tar.gz
    - source: salt://redis/files/tcl8.6.5-src.tar.gz
    - user: root
    - group: root
tcl_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
       - tar zxf tcl8.6.5-src.tar.gz && chown -R root:root tcl8.6.5
    - unless: test -d /usr/local/src/tcl8.6.5
    - require:
      - file: tcl_source
tcl_compile:
  cmd.run:
    - names:
      - cd /usr/local/src/tcl8.6.5/unix && ./configure && make && make install
    - unless: test -d /usr/local/tcl
    - require:
      - cmd: tcl_extrace
## Install config and install redis-php
redis_php_source:
  file.managed:
    - name: /usr/local/src/redis-3.0.1.tar.gz
    - source: salt://redis/files/redis-3.0.1.tar.gz
    - user: root
    - group: root
redis_php_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf redis-3.0.1.tar.gz && chown -R root:root redis-3.0.1 && mkdir -p /usr/local/src/redis-3.0.1/var
    - unless: test -d /usr/local/src/redis-3.0.1
    - require:
      - file: redis_php_source
redis_php_compila:
  cmd.run:
    - names:
      - cd /usr/local/src/redis-3.0.1 && make && make install
    - require:
      - cmd: redis_php_extrace
## Install config and install redis
redis_source:
  file.managed:
    - name: /usr/local/src/redis-2.2.5.tgz
    - source: salt://redis/files/redis-2.2.5.tgz
    - user: root
    - group: root
redis_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf redis-2.2.5.tgz && chown -R root:root redis-2.2.5
    - unless: test -d /usr/local/src/redis-2.2.5
    - require:
      - file: redis_source
redis_compila:
  cmd.run:
    - names:
      - cd /usr/local/src/redis-2.2.5 && /usr/local/php-fpm/bin/phpize && ./configure --with-php-config=/usr/local/php-fpm/bin/php-config && make && make install
    - unless: test -f /usr/local/php-fpm/lib/php/extensions/*/redis.so
    - require:
      - cmd: redis_extrace
/usr/local/php-fpm/etc/php.ini:
  file.append:
    - text:
      - extension=redis.so

3.2 redis配置管理文件(config.sls)

[[email protected]_210 redis]# cat config.sls
include:
  - redis.install
redis-config:
  file.managed:
    - name: /etc/redis.conf
    - source: salt://redis/files/redis.conf
    - user: root
    - group: root
redis-service:
  file.managed:
    - name: /etc/init.d/redis
    - source: salt://redis/files/redis
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - names:
      - chkconfig --add redis && chkconfig redis on
    - unless: chkconfig --list | grep redis
    - require:
      - file: redis-service
  service.running:
    - name: redis
    - enable: True
    - restart: True
    - watch:
      - file: redis-config

3.3 redis配置文件(redis.conf)

[[email protected]_210 redis]# cd files/
[[email protected]_210 files]# cat redis.conf
#后台daemon方式运行redis
daemonize yes
#本地快照数据库存放目录
dir "/usr/local/src/redis-3.0.1/var"
#pid存放路径
pidfile /var/run/redis.pid
#默认端口号
port 6379
tcp-backlog 511
#设置客户端超时时间30s
timeout 300
tcp-keepalive 0
#设置日志级别. debug,notice,verbose,waring
loglevel notice
#日志纪录方式,默认为标准输出, logs不写文件. 输出到空设置/dev/null
logfile "/usr/local/src/redis-3.0.1/var/redis.log"
#开启数据库的数量,默认数据库为0
databases 16
save 900 1
save 300 10
save 600 10000
stop-writes-on-bgsave-error yes
#启用数据库压缩数据
rdbcompression yes
rdbchecksum yes
#设置redis数据库连接密码
requirepass 123.com
#本地快照数据库名称
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
#开启日志纪录.相当于mysql的binlog
appendonly yes
#日志文件名, 不是目录路径
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

3.4 redis启动文件(redis)

[[email protected]_210 files]# cat redis
#!/bin/bash
#redis Start script for Redis Server
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
## Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start(){
       if [ -e $PIDFILE ];then
       echo "$desc already running......"
       exit 1
       fi
       echo -n $"Starting $desc:"
       daemon $BIN/$prog $CONFIG
       RETVAL=$?
       echo
       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
       return $RETVAL
}
stop(){
       echo -n $"Stop $desc:"
       killproc $prog
       echo
       [ $RETVAL -eq 0 ] && rm -rf /var/lock/subsys/$prog $PIDFILE
       return $RETVAL
}
restart(){
       stop
       start
}
case "$1" in
       start)
       start
       ;;
       stop)
       stop
       ;;
       restart)
       restart
       ;;
       condrestart)
       [ -e /var/lock/subsys/$prog ] && restart
       RETVAL=$?
       ;;
       status)
       status $prog
       ETVAL=$?
       ;;
       *)
       echo $"Usage: $0{start|stop|restart|condrestart|status}"
       ETVAL=1
esac
exit $ETVAL

4. 先测试后安装redis

[[email protected]_210 salt]# salt 'docker_212' state.highstate test=True     ->无报错即可.
[[email protected]_210 salt]# salt 'docker_212' state.highstate
  移步手机端
Linux自动化工具之安装redis及扩展redis

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录