memcached.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-3.0.8.tgz
  44. pushd memcache-3.0.8 > /dev/null
  45. elif [ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1}')" == '7' ]; then
  46. tar xzf memcache-${pecl_memcache_oldver}.tgz
  47. pushd memcache-${pecl_memcache_oldver} > /dev/null
  48. else
  49. #git clone https://github.com/websupport-sk/pecl-memcache.git
  50. tar xzf memcache-${pecl_memcache_ver}.tgz
  51. pushd memcache-${pecl_memcache_ver} > /dev/null
  52. fi
  53. ${php_install_dir}/bin/phpize
  54. ./configure --with-php-config=${php_install_dir}/bin/php-config
  55. make -j ${THREAD} && make install
  56. popd > /dev/null
  57. if [ -f "${phpExtensionDir}/memcache.so" ]; then
  58. echo "extension=memcache.so" > ${php_install_dir}/etc/php.d/05-memcache.ini
  59. echo "${CSUCCESS}PHP memcache module installed successfully! ${CEND}"
  60. rm -rf memcache-${pecl_memcache_ver} memcache-${pecl_memcache_oldver} memcache-3.0.8
  61. else
  62. 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
  63. fi
  64. popd > /dev/null
  65. fi
  66. }
  67. Install_pecl_memcached() {
  68. if [ -e "${php_install_dir}/bin/phpize" ]; then
  69. pushd ${oneinstack_dir}/src > /dev/null
  70. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  71. # php memcached extension
  72. tar xzf libmemcached-${libmemcached_ver}.tar.gz
  73. patch -d libmemcached-${libmemcached_ver} -p0 < libmemcached-build.patch
  74. pushd libmemcached-${libmemcached_ver} > /dev/null
  75. [ "${PM}" == 'yum' ] && yum -y install cyrus-sasl-devel
  76. [ "${PM}" == 'apt-get' ] && sed -i "s@lthread -pthread -pthreads@lthread -lpthread -pthreads@" ./configure
  77. ./configure --with-memcached=${memcached_install_dir}
  78. make -j ${THREAD} && make install
  79. popd > /dev/null
  80. rm -rf libmemcached-${libmemcached_ver}
  81. if [ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1}')" == '5' ]; then
  82. tar xzf memcached-${pecl_memcached_oldver}.tgz
  83. pushd memcached-${pecl_memcached_oldver} > /dev/null
  84. else
  85. tar xzf memcached-${pecl_memcached_ver}.tgz
  86. pushd memcached-${pecl_memcached_ver} > /dev/null
  87. fi
  88. ${php_install_dir}/bin/phpize
  89. ./configure --with-php-config=${php_install_dir}/bin/php-config
  90. make -j ${THREAD} && make install
  91. popd > /dev/null
  92. if [ -f "${phpExtensionDir}/memcached.so" ]; then
  93. cat > ${php_install_dir}/etc/php.d/05-memcached.ini << EOF
  94. extension=memcached.so
  95. memcached.use_sasl=1
  96. EOF
  97. echo "${CSUCCESS}PHP memcached module installed successfully! ${CEND}"
  98. rm -rf memcached-${pecl_memcached_oldver} memcached-${pecl_memcached_ver}
  99. else
  100. 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
  101. fi
  102. popd > /dev/null
  103. fi
  104. }
  105. Uninstall_pecl_memcache() {
  106. if [ -e "${php_install_dir}/etc/php.d/05-memcache.ini" ]; then
  107. rm -f ${php_install_dir}/etc/php.d/05-memcache.ini
  108. echo; echo "${CMSG}PHP memcache module uninstall completed${CEND}"
  109. else
  110. echo; echo "${CWARNING}PHP memcache module does not exist! ${CEND}"
  111. fi
  112. }
  113. Uninstall_pecl_memcached() {
  114. if [ -e "${php_install_dir}/etc/php.d/05-memcached.ini" ]; then
  115. rm -f ${php_install_dir}/etc/php.d/05-memcached.ini
  116. echo; echo "${CMSG}PHP memcached module uninstall completed${CEND}"
  117. else
  118. echo; echo "${CWARNING}PHP memcached module does not exist! ${CEND}"
  119. fi
  120. }