saltstack(十五):saltstack实例-redis-yum安装和编译安装

 

saltstack实例-安装redis-yum/编译

 

1.1          yum安装

 

1.1.1         文件目录

 

 

1.1.2          redis-yum.sls

redis-install:
  pkg.installed:
    - name: redis

redis-config:
  file.managed:
    - name: /etc/redis.conf
    - source: salt://redis/files/redis.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja    #告诉模板使用jinja
    - defaults:
      PORT: 6379   #定义的参数
      IPADDR: {{ grains['fqdn_ip4'][0] }}     #获取主机ip

redis-service:
  service.running:
    - name: redis
    - enable: True
    - restart: True
    - watch:
      - file: redis-config

 

1.1.3         测试

 

 

2.1          编译安装添加并systemctl

 

2.1.1          目录

 

 

2.1.2          文件详解

 

redis-configure.sls

#redis 安装
redis_dep:
  pkg.installed:
    - names:
      - gcc
      - tcl
source_file:
  file.managed:
    - name: /home/admin/soft/redis-4.0.6.tar.gz
    - source: salt://redis/files/redis-4.0.6.tar.gz
shell_file:
  file.managed:
    - name: /home/admin/soft/redis_install.sh
    - source: salt://redis/files/redis_install.sh
    - user: root
    - mode: 755
    - unless: ps -C redis-server --no-heading
    - require:
      - pkg: redis_dep

#加入systemctl
exec_file:
  file.managed:
    - name: /lib/systemd/system/redis.service
    - source: salt://redis/files/redis.service
    - unless: /lib/systemd/system/redis.service
    - user: root
    - mode: 755


redis_install:
  cmd.run:
    - name: /home/admin/soft/redis_install.sh  && rm -rf /home/admin/soft/redis*
    - unless: ps -C redis-server --no-heading || test -d /home/admin/redis/bin
    - require:
      - file: source_file
      - file: shell_file
      - file: exec_file

conf_file:
  file.managed:
    - name: /home/admin/redis/etc/redis.conf
    - source: salt://redis/files/redis.conf
    #- makedirs: True
    #- unless: test -f /home/admin/redis/etc/redis.conf
    - user: admin
    - group: admin
    - mode: 644
    - template: jinja    #告诉模板使用jinja
    - defaults:
      PORT: 6379   #定义的参数
    - require:
      - file: shell_file
redis_service:
  service.running:
    - user: admin
    - group: admin
    - name: redis
    - enable: True

 

redis_install.sh 远程安装配置

#!/bin/bash
#redis_install.sh
source /etc/profile

Version=redis-4.0.6
Tar_version=$Version.tar.gz
Install_dir=/home/admin/redis
Count=`ps -C redis-server --no-heading | wc -l`
[[ $Count -ne 0 ]] && echo -e "\033[31mredis已经安装,退出!\033[0m"    && exit 1

echo "$Tar_version !!!"
#wget http://download.redis.io/releases/$Tar_version
cd /home/admin/soft
[[ ! -f $Tar_version ]] && echo -e "\033[31m没有redis安装包,退出!\033[0m"   && exit 2
[[ ! -d $Install_dir ]] && mkdir -p $Install_dir   && mkdir -p $Install_dir/{bin,logs,etc}

sudo chown -R admin: /home/admin/redis

tar zxf $Tar_version
cd $Version
make
make PREFIX=/home/admin/redis/  install
cp redis.conf $Install_dir/etc/
ls $Install_dir
ls $Install_dir/bin

echo "export PATH=$PATH:$Install_dir/bin" | sudo tee -a /etc/profile  #加入系统变量
#echo 'export PATH=$PATH:/home/admin/redis/bin' | sudo tee -a /etc/profile  #加入系统变量
source  /etc/profile

sudo ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
sudo systemctl daemon-reload

 

redis.conf

port {{ PORT }}
#要传递端口
#传递要获取的主机ip
#test
protected-mode yes
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
#如果手动启动需要yes, systemctl 设成yes,否则会失败。
supervised no
pidfile /home/admin/redis/redis_6379.pid
loglevel notice
logfile "/home/admin/redis/logs/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
#dbfilename dump.rdb
dir /home/admin/redis/
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
appendonly no
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-size -2
list-compress-depth 0
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

 

redis.service

[Unit]

Description=Redis

After=network.target

[Service]
#普通用户启动
User=admin
ExecStart=/home/admin/redis/bin/redis-server /home/admin/redis/etc/redis.conf

ExecStop=/home/admin/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown


[Install]
WantedBy=multi-user.target

 

2.1.3         测试

 

posted on 2019-06-13 12:19  光阴8023  阅读(348)  评论(0编辑  收藏  举报