redis.sh 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_redis_server() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. tar xzf redis-${redis_ver}.tar.gz
  13. pushd redis-${redis_ver} > /dev/null
  14. make -j ${THREAD}
  15. if [ -f "src/redis-server" ]; then
  16. mkdir -p ${redis_install_dir}/{bin,etc,var}
  17. /bin/cp src/{redis-benchmark,redis-check-aof,redis-check-rdb,redis-cli,redis-sentinel,redis-server} ${redis_install_dir}/bin/
  18. /bin/cp redis.conf ${redis_install_dir}/etc/
  19. ln -s ${redis_install_dir}/bin/* /usr/local/bin/
  20. sed -i 's@pidfile.*@pidfile /var/run/redis/redis.pid@' ${redis_install_dir}/etc/redis.conf
  21. sed -i "s@logfile.*@logfile ${redis_install_dir}/var/redis.log@" ${redis_install_dir}/etc/redis.conf
  22. sed -i "s@^dir.*@dir ${redis_install_dir}/var@" ${redis_install_dir}/etc/redis.conf
  23. sed -i 's@daemonize no@daemonize yes@' ${redis_install_dir}/etc/redis.conf
  24. sed -i "s@^# bind 127.0.0.1@bind 127.0.0.1@" ${redis_install_dir}/etc/redis.conf
  25. redis_maxmemory=`expr $Mem / 8`000000
  26. [ -z "`grep ^maxmemory ${redis_install_dir}/etc/redis.conf`" ] && sed -i "s@maxmemory <bytes>@maxmemory <bytes>\nmaxmemory `expr $Mem / 8`000000@" ${redis_install_dir}/etc/redis.conf
  27. echo "${CSUCCESS}Redis-server installed successfully! ${CEND}"
  28. popd > /dev/null
  29. rm -rf redis-${redis_ver}
  30. id -u redis >/dev/null 2>&1
  31. [ $? -ne 0 ] && useradd -M -s /sbin/nologin redis
  32. chown -R redis:redis ${redis_install_dir}/{var,etc}
  33. /bin/cp ../init.d/redis-server.service /lib/systemd/system/
  34. sed -i "s@/usr/local/redis@${redis_install_dir}@g" /lib/systemd/system/redis-server.service
  35. systemctl enable redis-server
  36. #[ -z "`grep 'vm.overcommit_memory' /etc/sysctl.conf`" ] && echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
  37. #sysctl -p
  38. systemctl start redis-server
  39. else
  40. rm -rf ${redis_install_dir}
  41. echo "${CFAILURE}Redis-server install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  42. kill -9 $$; exit 1;
  43. fi
  44. popd > /dev/null
  45. }
  46. Install_pecl_redis() {
  47. if [ -e "${php_install_dir}/bin/phpize" ]; then
  48. pushd ${oneinstack_dir}/src > /dev/null
  49. phpExtensionDir=`${php_install_dir}/bin/php-config --extension-dir`
  50. if [ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1}')" == '5' ]; then
  51. tar xzf redis-${pecl_redis_oldver}.tgz
  52. pushd redis-${pecl_redis_oldver} > /dev/null
  53. else
  54. tar xzf redis-${pecl_redis_ver}.tgz
  55. pushd redis-${pecl_redis_ver} > /dev/null
  56. fi
  57. ${php_install_dir}/bin/phpize
  58. ./configure --with-php-config=${php_install_dir}/bin/php-config
  59. make -j ${THREAD} && make install
  60. popd > /dev/null
  61. if [ -f "${phpExtensionDir}/redis.so" ]; then
  62. echo 'extension=redis.so' > ${php_install_dir}/etc/php.d/05-redis.ini
  63. echo "${CSUCCESS}PHP Redis module installed successfully! ${CEND}"
  64. rm -rf redis-${pecl_redis_ver} redis-${pecl_redis_oldver}
  65. else
  66. echo "${CFAILURE}PHP Redis module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  67. fi
  68. popd > /dev/null
  69. fi
  70. }
  71. Uninstall_pecl_redis() {
  72. if [ -e "${php_install_dir}/etc/php.d/05-redis.ini" ]; then
  73. rm -f ${php_install_dir}/etc/php.d/05-redis.ini
  74. echo; echo "${CMSG}PHP redis module uninstall completed${CEND}"
  75. else
  76. echo; echo "${CWARNING}PHP redis module does not exist! ${CEND}"
  77. fi
  78. }