Redis & Sentinel 安裝指令碼

來源:互聯網
上載者:User

標籤:

#!/bin/bash


# 判斷是否為root使用者,不是root使用者提示退出
if [[ $EUID -ne 0 ]]; then
?? echo "This script. must be run as root" 1>&2
?? exit 1
fi?# 安裝必要的組件yum install -y gcc?#?下載redis原始碼cd /tmpwget -P /tmp?http://download.redis.io/releases/redis-3.2.1.tar.gz?# 對比檔案下載是否正確echo 26c0fc282369121b4e278523fce122910b65fbbf ?redis-3.2.1.tar.gz > /tmp/download.txtsha1sum -c download.txtif [ $? -ne 0 ]
then
? echo "The Download File is not Correct, Please Download it again."? exit 0
fi?# 編譯安裝tar xf redis-3.2.1.tar.gzcd redis-3.2.1makemake install?# 建立組和使用者groupadd redisuseradd -g redis redis?# LOG檔案存放位置mkdir /var/log/redischown?redis:redis /var/log/redis?# 當前IP地址IP=`ifconfig eth0 | grep "inet " | awk ‘{ print $2}‘`?# Redis服務開機運行echo "[Unit]" >?/usr/lib/systemd/system/redis.service?
echo "Description=Redis persistent key-value database" >>?/usr/lib/systemd/system/redis.service?
echo "After=network.target" >>?/usr/lib/systemd/system/redis.service?
echo "[Service]" >>?/usr/lib/systemd/system/redis.service??
echo "Type=forking" >>?/usr/lib/systemd/system/redis.service??
echo "ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf" >>?/usr/lib/systemd/system/redis.service??echo "ExecStop=/usr/local/bin/redis-cli -h ${IP} shutdown" >>?/usr/lib/systemd/system/redis.service??echo "User=redis" >>?/usr/lib/systemd/system/redis.service??
echo "Group=redis" >>?/usr/lib/systemd/system/redis.service??
echo "[Install]" >>?/usr/lib/systemd/system/redis.service??echo "WantedBy=multi-user.target" >>?/usr/lib/systemd/system/redis.service?# Redis Sentinel 服務開機運行echo "[Unit]" >?/usr/lib/systemd/system/redis-sentinel.service?echo "Description=Redis Sentinel" >>?/usr/lib/systemd/system/redis-sentinel.service?echo "After=network.target" >>?/usr/lib/systemd/system/redis-sentinel.service?echo "[Service]" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "Type=forking" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "ExecStart=/usr/local/bin/redis-sentinel /etc/redis/sentinel.conf" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "ExecStop=/usr/local/bin/redis-cli -h ${IP} -p 26379 shutdown" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "User=redis" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "Group=redis" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "[Install]" >>?/usr/lib/systemd/system/redis-sentinel.service??echo "WantedBy=multi-user.target" >>?/usr/lib/systemd/system/redis-sentinel.service?# redis 服務限制mkdir?/etc/systemd/system/redis.service.d/echo "[Service]" >?/etc/systemd/system/redis.service.d/limits.conf?echo "LimitNOFILE=65535" >> /etc/systemd/system/redis.service.d/limits.conf?# 啟用開機自動運行systemctl enable redis.servicesystemctl enable redis-sentinel.service?# 禁用selinuxsed -i ‘s/SELINUX=enforcing/SELINUX=disable/‘?/etc/selinux/config
# 系統最佳化echo "net.core.somaxconn=4096" >> /etc/sysctl.confecho "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.localchmod +x /etc/rc.localecho "vm.overcommit_memory=1" >> /etc/sysctl.confecho "*? soft? nofile? 65535" >>?/etc/security/limits.confecho "?* ?hard? nofile? 65535" >>?/etc/security/limits.confecho "?* ?soft? nproc? 65535" >>?/etc/security/limits.confecho "?* ?hard? nproc? 65535" >>?/etc/security/limits.confecho "net.ipv4.tcp_tw_recycle=1"?>> /etc/sysctl.conf?# 別名echo "alias redis=‘redis-cli -h ${IP}‘" >> /etc/profileecho "alias sentinel=‘redis-cli -h ${IP} -p 26379‘" >> /etc/profile?# 修改時區/bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime?#Redis設定檔存放位置mkdir /etc/redis?# 修改設定檔redis.confecho "bind ${IP}" > /etc/redis/redis.confecho "protected-mode no" >> /etc/redis/redis.confecho "tcp-backlog 4096" >> /etc/redis/redis.confecho "timeout 300" >> /etc/redis/redis.confecho "tcp-keepalive 60" >> /etc/redis/redis.confecho "daemonize yes" >> /etc/redis/redis.confecho "supervised systemd" >> /etc/redis/redis.confecho "logfile /var/log/redis/redis.log" >> /etc/redis/redis.confecho "dir /var/log/redis" >> /etc/redis/redis.confecho "maxclients 10000" >> /etc/redis/redis.confecho "maxmemory 4G" >> /etc/redis/redis.confecho "maxmemory-policy volatile-lru" >> /etc/redis/redis.confecho "appendonly no" >> /etc/redis/redis.confecho "slowlog-max-len 512" >> /etc/redis/redis.confecho "client-output-buffer-limit slave 512mb 256mb 300" >> /etc/redis/redis.conf?# 修改設定檔sentinel.confecho "port 26379" > /etc/redis/sentinel.confecho "bind ${IP}" >> /etc/redis/sentinel.confecho "dir /var/log/redis" >> /etc/redis/sentinel.confecho "sentinel monitor mymaster ${IP} 6379 2" >> /etc/redis/sentinel.confecho "maxclients 10" >> /etc/redis/sentinel.confecho "logfile /var/log/redis/sentinel.log" >> /etc/redis/sentinel.confecho "daemonize yes" >> /etc/redis/sentinel.confecho "sentinel down-after-milliseconds mymaster 5000" >> /etc/redis/sentinel.confecho "sentinel failover-timeout mymaster 60000" >> /etc/redis/sentinel.conf

Redis & Sentinel 安裝指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.