1
0

hhvm_CentOS.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_hhvm_CentOS() {
  11. id -u ${run_user} >/dev/null 2>&1
  12. [ $? -ne 0 ] && useradd -M -s /sbin/nologin ${run_user}
  13. if [ "${CentOS_ver}" == '7' ]; then
  14. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  15. [epel]
  16. name=Extra Packages for Enterprise Linux 7 - \$basearch
  17. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  18. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  19. failovermethod=priority
  20. enabled=1
  21. gpgcheck=0
  22. EOF
  23. cat > /etc/yum.repos.d/hhvm.repo << EOF
  24. [hhvm]
  25. name=gleez hhvm-repo
  26. baseurl=http://mirrors.linuxeye.com/hhvm-repo/7/\$basearch/
  27. enabled=1
  28. gpgcheck=0
  29. EOF
  30. yum -y install hhvm
  31. [ ! -e "/usr/bin/hhvm" -a "/usr/local/bin/hhvm" ] && ln -s /usr/local/bin/hhvm /usr/bin/hhvm
  32. fi
  33. if [ "${CentOS_ver}" == '6' ]; then
  34. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  35. [epel]
  36. name=Extra Packages for Enterprise Linux 6 - \$basearch
  37. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  38. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  39. failovermethod=priority
  40. enabled=1
  41. gpgcheck=0
  42. EOF
  43. # Install needed packages
  44. pkgList="libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel libevent-devel libcurl-devel libmemcached-devel lcms2 inotify-tools"
  45. for Package in ${pkgList}; do
  46. yum -y install ${Package}
  47. done
  48. # Uninstall the conflicting packages
  49. yum -y remove libwebp boost-system boost-filesystem
  50. cat > /etc/yum.repos.d/hhvm.repo << EOF
  51. [hhvm]
  52. name=gleez hhvm-repo
  53. baseurl=http://mirrors.linuxeye.com/hhvm-repo/6/\$basearch/
  54. enabled=1
  55. gpgcheck=0
  56. EOF
  57. yum --disablerepo=epel -y install mysql mysql-devel mysql-libs
  58. yum --disablerepo=epel -y install hhvm
  59. fi
  60. userdel -r nginx;userdel -r saslauth
  61. rm -rf /var/log/hhvm
  62. mkdir /var/log/hhvm
  63. chown -R ${run_user}.${run_user} /var/log/hhvm
  64. cat > /etc/hhvm/config.hdf << EOF
  65. ResourceLimit {
  66. CoreFileSize = 0 # in bytes
  67. MaxSocket = 10000 # must be not 0, otherwise HHVM will not start
  68. SocketDefaultTimeout = 5 # in seconds
  69. MaxRSS = 0
  70. MaxRSSPollingCycle = 0 # in seconds, how often to check max memory
  71. DropCacheCycle = 0 # in seconds, how often to drop disk cache
  72. }
  73. Log {
  74. Level = Info
  75. AlwaysLogUnhandledExceptions = true
  76. RuntimeErrorReportingLevel = 8191
  77. UseLogFile = true
  78. UseSyslog = false
  79. File = /var/log/hhvm/error.log
  80. Access {
  81. * {
  82. File = /var/log/hhvm/access.log
  83. Format = %h %l %u % t \"%r\" %>s %b
  84. }
  85. }
  86. }
  87. MySQL {
  88. ReadOnly = false
  89. ConnectTimeout = 1000 # in ms
  90. ReadTimeout = 1000 # in ms
  91. SlowQueryThreshold = 1000 # in ms, log slow queries as errors
  92. KillOnTimeout = false
  93. }
  94. Mail {
  95. SendmailPath = /usr/sbin/sendmail -t -i
  96. ForceExtraParameters =
  97. }
  98. EOF
  99. cat > /etc/hhvm/server.ini << EOF
  100. ; php options
  101. pid = /var/log/hhvm/pid
  102. ; hhvm specific
  103. ;hhvm.server.port = 9001
  104. hhvm.server.file_socket = /var/log/hhvm/sock
  105. hhvm.server.type = fastcgi
  106. hhvm.server.default_document = index.php
  107. hhvm.log.use_log_file = true
  108. hhvm.log.file = /var/log/hhvm/error.log
  109. hhvm.repo.central.path = /var/log/hhvm/hhvm.hhbc
  110. EOF
  111. cat > /etc/hhvm/php.ini << EOF
  112. hhvm.mysql.socket = /tmp/mysql.sock
  113. expose_php = 0
  114. memory_limit = 400000000
  115. post_max_size = 50000000
  116. EOF
  117. if [ -e "${web_install_dir}/sbin/nginx" -a -e "/usr/bin/hhvm" -a ! -e "${php_install_dir}" ]; then
  118. sed -i 's@/dev/shm/php-cgi.sock@/var/log/hhvm/sock@' ${web_install_dir}/conf/nginx.conf
  119. [ -z "$(grep 'fastcgi_param SCRIPT_FILENAME' ${web_install_dir}/conf/nginx.conf)" ] && sed -i "s@fastcgi_index index.php;@&\n\t\tfastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;@" ${web_install_dir}/conf/nginx.conf
  120. sed -i 's@include fastcgi.conf;@include fastcgi_params;@' ${web_install_dir}/conf/nginx.conf
  121. service nginx reload
  122. fi
  123. rm -rf /etc/ld.so.conf.d/*_64.conf
  124. ldconfig
  125. # Supervisor
  126. yum -y install python-setuptools
  127. ping pypi.python.org -c 4 >/dev/null 2>&1
  128. easy_install supervisor
  129. echo_supervisord_conf > /etc/supervisord.conf
  130. sed -i 's@pidfile=/tmp/supervisord.pid@pidfile=/var/run/supervisord.pid@' /etc/supervisord.conf
  131. [ -z "$(grep 'program:hhvm' /etc/supervisord.conf)" ] && cat >> /etc/supervisord.conf << EOF
  132. [program:hhvm]
  133. command=/usr/bin/hhvm --mode server --user ${run_user} --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
  134. numprocs=1 ; number of processes copies to start (def 1)
  135. directory=/tmp ; directory to cwd to before exec (def no cwd)
  136. autostart=true ; start at supervisord start (default: true)
  137. autorestart=unexpected ; whether/when to restart (default: unexpected)
  138. stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  139. EOF
  140. /bin/cp ${oneinstack_dir}/init.d/Supervisor-init-CentOS /etc/init.d/supervisord
  141. chmod +x /etc/init.d/supervisord
  142. chkconfig supervisord on
  143. service supervisord start
  144. }