redis.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-4.3.0.tgz
  52. pushd redis-4.3.0 > /dev/null
  53. elif [[ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1$2}')" =~ ^7[0-1]$ ]]; then
  54. tar xzf redis-5.3.7.tgz
  55. pushd redis-5.3.7 > /dev/null
  56. else
  57. tar xzf redis-${pecl_redis_ver}.tgz
  58. pushd redis-${pecl_redis_ver} > /dev/null
  59. fi
  60. ${php_install_dir}/bin/phpize
  61. ./configure --with-php-config=${php_install_dir}/bin/php-config
  62. make -j ${THREAD} && make install
  63. popd > /dev/null
  64. if [ -f "${phpExtensionDir}/redis.so" ]; then
  65. echo 'extension=redis.so' > ${php_install_dir}/etc/php.d/05-redis.ini
  66. echo "${CSUCCESS}PHP Redis module installed successfully! ${CEND}"
  67. rm -rf redis-${pecl_redis_ver} redis-4.3.0 redis-5.3.7
  68. else
  69. 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
  70. fi
  71. popd > /dev/null
  72. fi
  73. }
  74. Uninstall_pecl_redis() {
  75. if [ -e "${php_install_dir}/etc/php.d/05-redis.ini" ]; then
  76. rm -f ${php_install_dir}/etc/php.d/05-redis.ini
  77. echo; echo "${CMSG}PHP redis module uninstall completed${CEND}"
  78. else
  79. echo; echo "${CWARNING}PHP redis module does not exist! ${CEND}"
  80. fi
  81. }