redis單機單一實例一鍵安裝指令碼

來源:互聯網
上載者:User

指令碼功能

redis單機單一實例一鍵安裝指令碼

注意事項

1.僅適用於Linux/CentOS 64位

2.安裝時需連網

步驟1.下載並安裝libunwind軟體包(是TCMalloc依賴包)2.下載並安裝TCMalloc3.下載並安裝redis4.配置redis5.準備redis啟動停止指令碼6.啟動redis 指令碼內容 
  1. #!/bin/bash
  2. # 2013-1-10 LEO chanyipiaomiao@163.com
  3. # Blog: http://www.bkjia.com
  4. # 指令碼功能
  5. # redis單機單一實例一鍵安裝指令碼
  6. # 注意事項
  7. # 僅適用於Linux/Centos 64位
  8. # 安裝時需連網
  9. # 步驟
  10. # 1.下載並安裝libunwind軟體包(是TCMalloc依賴包)
  11. # 2.下載並安裝TCMalloc
  12. # 3.下載並安裝redis
  13. # 4.配置redis
  14. # 5.準備redis啟動停止指令碼
  15. # 6.啟動redis
  16. #輸出PATH變數
  17. export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
  18. #定義存放軟體目錄
  19. software="/root/software"
  20. #如果軟體目錄不存在則建立該目錄
  21. if [[ ! -e $software ]]; then
  22. mkdir -p $software
  23. fi
  24. #定義判斷是否安裝成功函數
  25. function installIsOK(){
  26. if [[ $2 == 0 ]]; then
  27. echo"$1 install ...... OK !"
  28. else
  29. echo"$1 install ...... Failure!"
  30. exit 1
  31. fi
  32. }
  33. #進入軟體目錄
  34. cd $software
  35. # 1.下載並安裝libunwind軟體包(是TCMalloc依賴包)
  36. libunwind='libunwind-1.1'
  37. wget http://download.savannah.gnu.org/releases/libunwind/${libunwind}.tar.gz
  38. tar zxf ${libunwind}.tar.gz
  39. cd $libunwind
  40. ./configure && make && make install
  41. if [[ $? == 0 ]]; then
  42. installIsOK ${libunwind} 0
  43. else
  44. installIsOK ${libunwind} 1
  45. fi
  46. cd $software
  47. # 2.下載並安裝TCMalloc
  48. # TCMalloc (google-perftools) 是用於最佳化C++寫的多線程應用,比glibc 2.3的malloc快。這個模組可以用來最佳化redis效能
  49. gperftools='gperftools-2.0'
  50. wget http://gperftools.googlecode.com/files/${gperftools}.tar.gz
  51. tar zxf ${gperftools}.tar.gz
  52. cd $gperftools
  53. ./configure
  54. make && make install
  55. if [[ $? == 0 ]]; then
  56. installIsOK ${gperftools} 0
  57. else
  58. installIsOK ${gperftools} 2
  59. fi
  60. echo"/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  61. ldconfig
  62. cd $software
  63. # 3.下載並安裝redis
  64. redis='redis-2.6.7'
  65. redis_dir='/usr/local/redis'
  66. wget http://redis.googlecode.com/files/${redis}.tar.gz
  67. tar zxf ${redis}.tar.gz
  68. cd $redis
  69. make PREFIX=${redis_dir} USE_TCMALLOC=yes install
  70. if [[ $? == 0 ]]; then
  71. installIsOK ${redis} 0
  72. else
  73. installIsOK ${redis} 3
  74. fi
  75. # 4.配置redis
  76. mkdir -p ${redis_dir}/etc
  77. mkdir -p ${redis_dir}/run
  78. mkdir -p ${redis_dir}/data/6379
  79. mkdir -p ${redis_dir}/log
  80. cp redis.conf ${redis_dir}/redis.conf
  81. #cp ${redis_dir}/redis.conf ${redis_dir}/etc/redis_6379.conf
  82. #組建組態檔案
  83. redis_6379="${redis_dir}/etc/redis_6379.conf"
  84. cat >> ${redis_6379} << "EOF"
  85. daemonize yes
  86. pidfile /usr/local/redis/run/redis_6379.pid
  87. port 6379
  88. #bind 127.0.0.1
  89. timeout 300
  90. loglevel notice
  91. logfile /usr/local/redis/log/redis.log
  92. databases 16
  93. save 900 1
  94. save 300 10
  95. save 60 10000
  96. stop-writes-on-bgsave-error no
  97. rdbcompression yes
  98. rdbchecksum no
  99. dbfilename dump.rdb
  100. dir /usr/local/redis/data/6379
  101. #slave-serve-stale-data yes
  102. maxmemory 256mb
  103. maxmemory-policy volatile-lru
  104. maxmemory-samples 3
  105. appendonly yes
  106. appendfsync everysec
  107. no-appendfsync-on-rewrite no
  108. auto-aof-rewrite-percentage 100
  109. auto-aof-rewrite-min-size 64mb
  110. lua-time-limit 5000
  111. slowlog-log-slower-than 10000
  112. slowlog-max-len 1024
  113. hash-max-ziplist-entries 512
  114. hash-max-ziplist-value 64
  115. list-max-ziplist-entries 512
  116. list-max-ziplist-value 64
  117. set-max-intset-entries 512
  118. zset-max-ziplist-entries 128
  119. zset-max-ziplist-value 64
  120. activerehashing yes
  121. client-output-buffer-limit normal 0 0 0
  122. client-output-buffer-limit slave 256mb 64mb 60
  123. client-output-buffer-limit pubsub 32mb 8mb 60
  124. EOF
  125. # 5.redis啟動停止指令碼
  126. redis_start="/etc/rc.d/init.d/redis"
  127. cat >> ${redis_start} << "END"
  128. #!/bin/bash
  129. export PATH="/usr/local/redis/bin:$PATH"
  130. EXEC="/usr/local/redis/bin/redis-server"
  131. CLIEXEC="/usr/local/redis/bin/redis-cli"
  132. PIDFILE="/usr/local/redis/run/redis_6379.pid"
  133. CONF="/usr/local/redis/etc/redis_6379.conf"
  134. PORT="6379"
  135. case"$1" in
  136. start)
  137. if [ -f $$PIDFILE ]
  138. then
  139. echo"$PIDFILE exists, process is already running or crashed."
  140. else
  141. echo"Starting Redis server..."
  142. $EXEC$CONF
  143. fi
  144. ;;
  145. stop)
  146. if [ ! -f $PIDFILE ]
  147. then
  148. echo"$PIDFILE does not exist, process is not running."
  149. else
  150. PID=$(cat $PIDFILE)
  151. echo"Stopping ..."
  152. $CLIEXEC -p $PORT shutdown
  153. while [ -x /proc/${PID} ]
  154. do
  155. echo"Waiting for Redis to shutdown ..."
  156. sleep 1
  157. done
  158. echo"Redis stopped."
  159. fi
  160. ;;
  161. restart)
  162. $0 stop && $0 start
  163. ;;
  164. *)
  165. echo"Usage: $0 {start|stop|restart}" >&2
  166. exit 1
  167. ;;
  168. esac
  169. END
  170. #增加可執行許可權
  171. chmod u+x ${redis_start}
  172. # 6.啟動redis
  173. ${redis_start} start
  174. if [[ $? == 0 ]]; then
  175. echo"redis start ...... OK"
  176. else
  177. echo"redis start ...... Failure"
  178. fi

redis單機單一實例一鍵安裝指令碼

免費在 http://linux.bkjia.com/

使用者名稱與密碼都是www.bkjia.com

具體下載目錄在 /2013年資料/5月/25日/redis單機單一實例一鍵安裝指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.