memcached.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_memcached_server() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. # memcached server
  13. id -u memcached >/dev/null 2>&1
  14. [ $? -ne 0 ] && useradd -M -s /sbin/nologin memcached
  15. tar xzf memcached-${memcached_ver}.tar.gz
  16. pushd memcached-${memcached_ver} > /dev/null
  17. [ ! -d "${memcached_install_dir}" ] && mkdir -p ${memcached_install_dir}
  18. ./configure --prefix=${memcached_install_dir}
  19. make -j ${THREAD} && make install
  20. popd > /dev/null
  21. if [ -f "${memcached_install_dir}/bin/memcached" ]; then
  22. echo "${CSUCCESS}memcached installed successfully! ${CEND}"
  23. rm -rf memcached-${memcached_ver}
  24. ln -s ${memcached_install_dir}/bin/memcached /usr/bin/memcached
  25. /bin/cp ../init.d/memcached.service /lib/systemd/system/
  26. systemctl enable memcached
  27. systemctl start memcached
  28. rm -rf memcached-${memcached_ver}
  29. else
  30. rm -rf ${memcached_install_dir}
  31. echo "${CFAILURE}memcached-server install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  32. kill -9 $$; exit 1;
  33. fi
  34. popd > /dev/null
  35. }
  36. Install_pecl_memcache() {
  37. if [ -e "${php_install_dir}/bin/phpize" ]; then
  38. pushd ${oneinstack_dir}/src > /dev/null
  39. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  40. PHP_detail_ver=$(${php_install_dir}/bin/php-config --version)
  41. PHP_main_ver=${PHP_detail_ver%.*}
  42. if [ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1}')" == '5' ]; then
  43. tar xzf memcache-${pecl_memcache_oldver}.tgz
  44. pushd memcache-${pecl_memcache_oldver} > /dev/null
  45. else
  46. #git clone https://github.com/websupport-sk/pecl-memcache.git
  47. tar xzf memcache-${pecl_memcache_ver}.tgz
  48. pushd memcache-${pecl_memcache_ver} > /dev/null
  49. fi
  50. ${php_install_dir}/bin/phpize
  51. ./configure --with-php-config=${php_install_dir}/bin/php-config
  52. make -j ${THREAD} && make install
  53. popd > /dev/null
  54. if [ -f "${phpExtensionDir}/memcache.so" ]; then
  55. echo "extension=memcache.so" > ${php_install_dir}/etc/php.d/05-memcache.ini
  56. echo "${CSUCCESS}PHP memcache module installed successfully! ${CEND}"
  57. rm -rf memcache-${pecl_memcache_ver} memcache-${pecl_memcache_oldver}
  58. else
  59. echo "${CFAILURE}PHP memcache module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  60. fi
  61. popd > /dev/null
  62. fi
  63. }
  64. Install_pecl_memcached() {
  65. if [ -e "${php_install_dir}/bin/phpize" ]; then
  66. pushd ${oneinstack_dir}/src > /dev/null
  67. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  68. # php memcached extension
  69. tar xzf libmemcached-${libmemcached_ver}.tar.gz
  70. patch -d libmemcached-${libmemcached_ver} -p0 < libmemcached-build.patch
  71. pushd libmemcached-${libmemcached_ver} > /dev/null
  72. [ "${PM}" == 'yum' ] && yum -y install cyrus-sasl-devel
  73. [ "${PM}" == 'apt-get' ] && sed -i "s@lthread -pthread -pthreads@lthread -lpthread -pthreads@" ./configure
  74. ./configure --with-memcached=${memcached_install_dir}
  75. make -j ${THREAD} && make install
  76. popd > /dev/null
  77. rm -rf libmemcached-${libmemcached_ver}
  78. if [ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1}')" == '5' ]; then
  79. tar xzf memcached-${pecl_memcached_oldver}.tgz
  80. pushd memcached-${pecl_memcached_oldver} > /dev/null
  81. else
  82. tar xzf memcached-${pecl_memcached_ver}.tgz
  83. pushd memcached-${pecl_memcached_ver} > /dev/null
  84. fi
  85. ${php_install_dir}/bin/phpize
  86. ./configure --with-php-config=${php_install_dir}/bin/php-config
  87. make -j ${THREAD} && make install
  88. popd > /dev/null
  89. if [ -f "${phpExtensionDir}/memcached.so" ]; then
  90. cat > ${php_install_dir}/etc/php.d/05-memcached.ini << EOF
  91. extension=memcached.so
  92. memcached.use_sasl=1
  93. EOF
  94. echo "${CSUCCESS}PHP memcached module installed successfully! ${CEND}"
  95. rm -rf memcached-${pecl_memcached_oldver} memcached-${pecl_memcached_ver}
  96. else
  97. echo "${CFAILURE}PHP memcached module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  98. fi
  99. popd > /dev/null
  100. fi
  101. }
  102. Uninstall_pecl_memcache() {
  103. if [ -e "${php_install_dir}/etc/php.d/05-memcache.ini" ]; then
  104. rm -f ${php_install_dir}/etc/php.d/05-memcache.ini
  105. echo; echo "${CMSG}PHP memcache module uninstall completed${CEND}"
  106. else
  107. echo; echo "${CWARNING}PHP memcache module does not exist! ${CEND}"
  108. fi
  109. }
  110. Uninstall_pecl_memcached() {
  111. if [ -e "${php_install_dir}/etc/php.d/05-memcached.ini" ]; then
  112. rm -f ${php_install_dir}/etc/php.d/05-memcached.ini
  113. echo; echo "${CMSG}PHP memcached module uninstall completed${CEND}"
  114. else
  115. echo; echo "${CWARNING}PHP memcached module does not exist! ${CEND}"
  116. fi
  117. }