hhvm_CentOS.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_hhvm_CentOS()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../options.conf
  9. id -u $run_user >/dev/null 2>&1
  10. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  11. if [ -n "$(grep ' 7\.' /etc/redhat-release)" ];then
  12. CentOS_RHL=7
  13. elif [ -n "$(grep ' 6\.' /etc/redhat-release)" ];then
  14. CentOS_RHL=6
  15. fi
  16. if [ "$CentOS_RHL" == '7' ];then
  17. if [ -e /etc/yum.repos.d/epel.repo_bk ];then
  18. /bin/mv /etc/yum.repos.d/epel.repo{_bk,}
  19. elif [ ! -e /etc/yum.repos.d/epel.repo ];then
  20. cat > /etc/yum.repos.d/epel.repo << EOF
  21. [epel]
  22. name=Extra Packages for Enterprise Linux 7 - \$basearch
  23. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  24. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  25. failovermethod=priority
  26. enabled=1
  27. gpgcheck=0
  28. EOF
  29. fi
  30. cat > /etc/yum.repos.d/hhvm.repo << EOF
  31. [hhvm]
  32. name=Copr repo for hhvm-repo owned by no1youknowz
  33. baseurl=https://copr-be.cloud.fedoraproject.org/results/no1youknowz/hhvm-repo/epel-7-\$basearch/
  34. skip_if_unavailable=True
  35. gpgcheck=0
  36. enabled=0
  37. EOF
  38. yum --enablerepo=hhvm -y install hhvm
  39. [ ! -e "/usr/bin/hhvm" -a "/usr/local/bin/hhvm" ] && ln -s /usr/local/bin/hhvm /usr/bin/hhvm
  40. fi
  41. if [ "$CentOS_RHL" == '6' ];then
  42. if [ -e /etc/yum.repos.d/epel.repo_bk ];then
  43. /bin/mv /etc/yum.repos.d/epel.repo{_bk,}
  44. elif [ ! -e /etc/yum.repos.d/epel.repo ];then
  45. cat > /etc/yum.repos.d/epel.repo << EOF
  46. [epel]
  47. name=Extra Packages for Enterprise Linux 6 - \$basearch
  48. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  49. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  50. failovermethod=priority
  51. enabled=1
  52. gpgcheck=0
  53. EOF
  54. fi
  55. yum -y install libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-devel \
  56. libxml2-devel libicu-devel pcre-devel gd-devel boost-devel sqlite-devel pam-devel \
  57. bzip2-devel oniguruma-devel openldap-devel readline-devel libc-client-devel libcap-devel \
  58. libevent-devel libcurl-devel libmemcached-devel lcms2 inotify-tools
  59. public_IP=`../functions/get_public_ip.py`
  60. if [ "`../functions/get_ip_area.py $public_IP`" == '\u4e2d\u56fd' ];then
  61. FLAG_IP=CN
  62. fi
  63. echo $public_IP $FLAG_IP
  64. [ "$FLAG_IP"x == "CN"x ] && REMI_ADDR=http://mirrors.swu.edu.cn || REMI_ADDR=http://mirrors.mediatemple.net
  65. cat > /etc/yum.repos.d/remi.repo << EOF
  66. [remi]
  67. name=Les RPM de remi pour Enterprise Linux 6 - \$basearch
  68. baseurl=$REMI_ADDR/remi/enterprise/6/remi/\$basearch/
  69. #mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
  70. enabled=0
  71. gpgcheck=0
  72. EOF
  73. yum -y remove libwebp
  74. src_url=http://mirrors.linuxeye.com/lnmp/src/libwebp-0.3.1-2.el6.remi.x86_64.rpm && Download_src
  75. src_url=http://mirrors.linuxeye.com/lnmp/src/hhvm-3.5.0-4.el6.x86_64.rpm && Download_src
  76. rpm -ivh libwebp-0.3.1-2.el6.remi.x86_64.rpm
  77. yum --enablerepo=remi --disablerepo=epel -y install mysql mysql-devel mysql-libs
  78. yum -y remove boost-system boost-filesystem
  79. cat > /etc/yum.repos.d/gleez.repo << EOF
  80. [gleez]
  81. name=Gleez repo
  82. baseurl=http://yum.gleez.com/6/\$basearch/
  83. enabled=0
  84. gpgcheck=0
  85. EOF
  86. ping yum.gleez.com -c 4 >/dev/null 2>&1
  87. yum --enablerepo=gleez --disablerepo=epel -y install -R 2 ./hhvm-3.5.0-4.el6.x86_64.rpm
  88. fi
  89. userdel -r nginx;userdel -r saslauth
  90. rm -rf /var/log/hhvm
  91. mkdir /var/log/hhvm
  92. chown -R ${run_user}.$run_user /var/log/hhvm
  93. cat > /etc/hhvm/config.hdf << EOF
  94. ResourceLimit {
  95. CoreFileSize = 0 # in bytes
  96. MaxSocket = 10000 # must be not 0, otherwise HHVM will not start
  97. SocketDefaultTimeout = 5 # in seconds
  98. MaxRSS = 0
  99. MaxRSSPollingCycle = 0 # in seconds, how often to check max memory
  100. DropCacheCycle = 0 # in seconds, how often to drop disk cache
  101. }
  102. Log {
  103. Level = Info
  104. AlwaysLogUnhandledExceptions = true
  105. RuntimeErrorReportingLevel = 8191
  106. UseLogFile = true
  107. UseSyslog = false
  108. File = /var/log/hhvm/error.log
  109. Access {
  110. * {
  111. File = /var/log/hhvm/access.log
  112. Format = %h %l %u % t \"%r\" %>s %b
  113. }
  114. }
  115. }
  116. MySQL {
  117. ReadOnly = false
  118. ConnectTimeout = 1000 # in ms
  119. ReadTimeout = 1000 # in ms
  120. SlowQueryThreshold = 1000 # in ms, log slow queries as errors
  121. KillOnTimeout = false
  122. }
  123. Mail {
  124. SendmailPath = /usr/sbin/sendmail -t -i
  125. ForceExtraParameters =
  126. }
  127. EOF
  128. cat > /etc/hhvm/server.ini << EOF
  129. ; php options
  130. pid = /var/log/hhvm/pid
  131. ; hhvm specific
  132. ;hhvm.server.port = 9001
  133. hhvm.server.file_socket = /var/log/hhvm/sock
  134. hhvm.server.type = fastcgi
  135. hhvm.server.default_document = index.php
  136. hhvm.log.use_log_file = true
  137. hhvm.log.file = /var/log/hhvm/error.log
  138. hhvm.repo.central.path = /var/log/hhvm/hhvm.hhbc
  139. EOF
  140. cat > /etc/hhvm/php.ini << EOF
  141. hhvm.mysql.socket = /tmp/mysql.sock
  142. expose_php = 0
  143. memory_limit = 400000000
  144. post_max_size = 50000000
  145. EOF
  146. if [ "$CentOS_RHL" == '7' ];then
  147. cat > /etc/systemd/system/hhvm.service << EOF
  148. [Unit]
  149. Description=HHVM HipHop Virtual Machine (FCGI)
  150. [Service]
  151. ExecStartPre=/usr/bin/rm -rf /var/log/hhvm ; /usr/bin/mkdir /var/log/hhvm ; /usr/bin/chown ${run_user}.$run_user /var/log/hhvm
  152. ExecStart=/usr/bin/hhvm --mode server --user $run_user --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
  153. [Install]
  154. WantedBy=multi-user.target
  155. EOF
  156. #systemctl enable hhvm
  157. #systemctl start hhvm
  158. elif [ "$CentOS_RHL" == '6' ];then
  159. /bin/cp ../init/hhvm-init-CentOS6 /etc/init.d/hhvm
  160. sed -i "s@^USER=www@USER=$run_user@" /etc/init.d/hhvm
  161. chmod +x /etc/init.d/hhvm
  162. #chkconfig hhvm on
  163. #service hhvm start
  164. fi
  165. if [ -e "/usr/bin/hhvm" -a ! -e "$php_install_dir" ];then
  166. sed -i 's@/dev/shm/php-cgi.sock@/var/log/hhvm/sock@' $web_install_dir/conf/nginx.conf
  167. [ -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
  168. sed -i 's@include fastcgi.conf;@include fastcgi_params;@' $web_install_dir/conf/nginx.conf
  169. service nginx reload
  170. fi
  171. rm -rf /etc/ld.so.conf.d/*_64.conf
  172. ldconfig
  173. # Supervisor
  174. yum -y install python-setuptools
  175. ping pypi.python.org -c 4 >/dev/null 2>&1
  176. easy_install supervisor
  177. echo_supervisord_conf > /etc/supervisord.conf
  178. sed -i 's@pidfile=/tmp/supervisord.pid@pidfile=/var/run/supervisord.pid@' /etc/supervisord.conf
  179. [ -z "`grep 'program:hhvm' /etc/supervisord.conf`" ] && cat >> /etc/supervisord.conf << EOF
  180. [program:hhvm]
  181. command=/usr/bin/hhvm --mode server --user $run_user --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
  182. numprocs=1 ; number of processes copies to start (def 1)
  183. directory=/tmp ; directory to cwd to before exec (def no cwd)
  184. autostart=true ; start at supervisord start (default: true)
  185. autorestart=unexpected ; whether/when to restart (default: unexpected)
  186. stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  187. EOF
  188. src_url=https://github.com/Supervisor/initscripts/raw/master/redhat-init-mingalevme && Download_src
  189. /bin/mv redhat-init-mingalevme /etc/init.d/supervisord
  190. chmod +x /etc/init.d/supervisord
  191. chkconfig supervisord on
  192. service supervisord start
  193. cd ..
  194. }