SaltStack安装Redis-第十篇
生活随笔
收集整理的這篇文章主要介紹了
SaltStack安装Redis-第十篇
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
實(shí)驗(yàn)環(huán)境
node1 ?192.168.56.11 ? 角色 ?salt-master?
node2 ?192.168.56.12 ? 角色 ?salt-minon
完成內(nèi)容
Salt遠(yuǎn)程安裝Redis服務(wù)
步驟
在前面的文章中已經(jīng)搭建好了salt-master和saltminion環(huán)境
一,在prod目錄下創(chuàng)建redis相關(guān)的目錄,存放狀態(tài)文件
[root@linux-node1 ~]# cd /srv/salt/prod/ [root@linux-node1 prod]# mkdir modules/redis -p [root@linux-node1 prod]# tree . └── modules└── redis二,進(jìn)入redis目錄創(chuàng)建redis基礎(chǔ)狀態(tài)文件,這里我們用簡(jiǎn)單的rpm包按照為例
[root@linux-node1 redis]# cat redis-install.sls redis-install:pkg.installed:- name: redis三,有時(shí)候我們修改redis的配置文件或創(chuàng)建集群
[root@linux-node1 prod]# pwd /srv/salt/prod [root@linux-node1 prod]# mkdir redis-cluster [root@linux-node1 prod]# cd redis-cluster/ [root@linux-node1 redis-cluster]# vi redis-master.sls [root@linux-node1 redis-cluster]# cat redis-master.sls include:- modules.redis.redis-installredis-master-config:file.managed:- name: /etc/redis.conf- source: salt://redis-cluster/files/redis-master.conf- user: root- group: root- mode: 644- template: jinja- defaults:REDIS_MEM: 1Gredis-master-service:service.running:- name: redis- enable: True- watch:- file: redis-master-config四,按照redis取配置文件作為salt模板
[root@linux-node1 redis-cluster]# yum install redis [root@linux-node1 redis-cluster]# cp /etc/redis.conf /srv/salt/prod/redis-cluster/files/ [root@linux-node1 redis-cluster]# tree . ├── files │?? └── redis.conf └── redis-master.sls五,重命名redis模板文件名
[root@linux-node1 files]# mv redis.conf redis-master.conf [root@linux-node1 files]# pwd /srv/salt/prod/redis-cluster/files六,更改redis配置文件模板,bind也可以只監(jiān)聽(tīng)內(nèi)網(wǎng)端口
[root@linux-node1 files]# grep -E 'bind|daemonize|maxmemory' redis-master.conf |grep -v ^# bind 0.0.0.0 daemonize yes maxmemory {{ REDIS_MEM }}七,測(cè)試,因?yàn)槭窃趐rod目錄下 需要添加 saltenv=prod環(huán)境變量
[root@linux-node1 redis-cluster]# salt 'linux-node2*' state.sls redis-cluster.redis-master test=True saltenv=prod linux-node2.example.com: ----------ID: redis-installFunction: pkg.installedName: redisResult: NoneComment: The following packages are set to be installed/updated: redisStarted: 22:45:55.034779Duration: 2514.889 msChanges: ----------ID: redis-master-configFunction: file.managedName: /etc/redis.confResult: NoneComment: The file /etc/redis.conf is set to be changedStarted: 22:45:57.551713Duration: 27.659 msChanges: ----------newfile:/etc/redis.conf ----------ID: redis-master-serviceFunction: service.runningName: redisResult: NoneComment: Service is set to be startedStarted: 22:45:57.637546Duration: 71.324 msChanges: Summary ------------ Succeeded: 3 (unchanged=3, changed=1) Failed: 0 ------------ Total states run: 3八,執(zhí)行redis狀態(tài)模塊
[root@linux-node1 redis-cluster]# salt 'linux-node2*' state.sls redis-cluster.redis-master saltenv=prod linux-node2.example.com: ----------ID: redis-installFunction: pkg.installedName: redisResult: TrueComment: The following packages were installed/updated: redisStarted: 22:48:16.616612Duration: 15732.74 msChanges: ----------jemalloc:----------new:3.6.0-1.el7old:redis:----------new:3.2.10-2.el7old: ----------ID: redis-master-configFunction: file.managedName: /etc/redis.confResult: TrueComment: File /etc/redis.conf updatedStarted: 22:48:32.351877Duration: 45.19 msChanges: ----------diff:--- +++ @@ -44,7 +44,7 @@## Examples:#-# bind 192.168.1.100 10.0.0.1+#bind 0.0.0.0# bind 127.0.0.1 ::1## ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the@@ -58,7 +58,7 @@# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES# JUST COMMENT THE FOLLOWING LINE.# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-bind 127.0.0.1+bind 0.0.0.0# Protected mode is a layer of security protection, in order to avoid that# Redis instances left open on the internet are accessed and exploited.@@ -125,7 +125,7 @@# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.-daemonize no+daemonize yes# If you run Redis from upstart or systemd, Redis can interact with your# supervision tree. Options:@@ -534,7 +534,7 @@# limit for maxmemory so that there is some free RAM on the system for slave# output buffers (but this is not needed if the policy is 'noeviction').#-# maxmemory <bytes>+maxmemory 1G# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory# is reached. You can select among five behaviors:mode:0644user:root ----------ID: redis-master-serviceFunction: service.runningName: redisResult: TrueComment: Service redis has been enabled, and is runningStarted: 22:48:32.412154Duration: 453.972 msChanges: ----------redis:TrueSummary ------------ Succeeded: 3 (changed=3) Failed: 0 ------------ Total states run: 3 salt 'linux-node2*' state.sls redis-cluster.redis-master saltenv=prod九,登陸n(yōu)ode2節(jié)點(diǎn)查看redis服務(wù)已經(jīng)成功啟動(dòng)
[root@linux-node2 ~]# ps aux |grep redis redis 5147 0.3 0.3 142904 5808 ? Ssl 22:48 0:00 /usr/bin/redis-server 0.0.0.0:6379 root 5192 0.0 0.0 112648 976 pts/0 S+ 22:49 0:00 grep --color=auto redis [root@linux-node2 ~]#總結(jié)
1.生產(chǎn)環(huán)境我們的狀態(tài)模塊可以在prod下面,在執(zhí)行的時(shí)候需要設(shè)置環(huán)境saltenv=prod(使用top.sls不需要設(shè)置環(huán)境變量)
2.記得使用test=True先測(cè)試
3.提前查清楚軟件包和相關(guān)配置文件
4.當(dāng)使用jinja模板管理時(shí),可以不用登陸redis服務(wù)器就可以查看redis設(shè)置的最大內(nèi)存
附 趙班長(zhǎng)的 GitHub saltbook-code網(wǎng)址
https://github.com/unixhot/saltbook-code/tree/master
?
轉(zhuǎn)載于:https://www.cnblogs.com/xiewenming/p/7714764.html
總結(jié)
以上是生活随笔為你收集整理的SaltStack安装Redis-第十篇的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: u盘里面隐藏的文件怎么恢复出厂设置密码
- 下一篇: 刚组装的电脑怎么进入bios 新标题:如