[实践OK]CentOS 6.5和CentOS7.0分别安装了下HHVM,并将此用于wordpress网站上,相当不错。

jackxiang 2015-3-5 22:22 | |
CentOS 7下hhvm Nginx环境搭建:
http://www.linuxeye.com/Linux/2029.html
Supervisor管理hhvm进程:
http://www.linuxeye.com/Linux/Supervisor-hhvm.html
注意一下路径:
;logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile=/data/logs/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

=======================================================
Q:多处出现:软件包boost-regex-1.54.0-9.el6.x86_64.rpm没有签名?
Q:大家都用source编译?我是想通过yum 安装了解一下php的hhvm 尽量用yum 安装。
A:比较容易标准化 机器多的话,可以统一标准化 对,标准化很重要
https://github.com/lj2007331/lnmp
淘宝一个人建的,其中functions目录把每个l n/a mp版本安装封装成了一个shell函数(包含了依赖包),有hhvm和php7。如果是在机器上体验一下,可以使用这个项目或者把他的函数抠出来,可以省去从源码编译挨个找依赖包的痛苦。

————————————————兼容过渡办法—————————————————

测试了下6月6日下载编译的PHP7和HHVM最新的3.7.1.
ab -c100 -n1000 http://127.0.0.1/wordpress/
100并发完成1000个请求,PHP7(开启opcache,5个PHP-FPM工作进程)每秒处理117个请求,HHVM则是每秒126个,性能差距很小.值得一提的是,HHVM没有热身时(第一次压测),每秒只能处理56个请求,而PHP7仍能处理117个请求.

这是我6月6日编译的PHP7开发版,你可以下载进行测试:
http://my.oschina.net/eechen/blog/411534

补充:
如果你觉得处于Alpha版本的PHP7还不够稳定,你可以配置Nginx,PHP7-FPM监听9000端口,PHP5-FPM监听9001端口,当PHP7崩掉的时候自动切换到作为备用的PHP5.

upstream php.backend {
    server 127.0.0.1:9000;
    server 127.0.0.1:9001 backup;
}
PHP-FPM是多进程的架构,PHP7并没有改动PHP-FPM的架构,所以说就算PHP-FPM工作进程因为内置的PHP7引擎发生故障,我估计也就工作进程会崩溃退出,而PHP-FPM的master进程会自动重启一个新的工作进程.
————————————————————————————————————————————————————

已加载插件:fastestmirror, refresh-packagekit, security
/var/run/yum.pid 已被锁定,PID 为 8085 的另一个程序正在运行。
另外一个程序锁定了 yum;等待它退出……
  The other application is: PackageKit
    Memory :  22 M RSS (328 MB VSZ)
    Started: Mon May  4 16:41:46 2015 - 00:09 ago
    State  : Uninterruptible, pid: 8085
另外一个程序锁定了 yum;等待它退出……
  The other application is: PackageKit
    Memory :  31 M RSS (339 MB VSZ)
    Started: Mon May  4 16:41:46 2015 - 00:11 ago
你怎么2个东西在跑,kill:


重复执行 install.sh

ps -ef | grep hhvm
service hhvm start

find . -name "hhvm"
./etc/rc.d/init.d/hhvm
./var/run/hhvm
./var/log/hhvm

如果说想配置nginx+hhvm,我用nginx+hhvm可以吧?
vhost.sh

最后,
mysql源码安装的是 mysql-server
mysql x86_64是客户端,别搞错。

还是有问题:
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16(libmysqlclient_16)(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16(libmysqlclient_16)(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-devel-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient_r.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient_r.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16(libmysqlclient_16)(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16(libmysqlclient_16)(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
错误:Package: mysql-devel-5.1.73-3.el6_5.x86_64 (base)
          Requires: libmysqlclient.so.16()(64bit)
          Available: mysql-libs-5.1.73-3.el6_5.x86_64 (base)
              libmysqlclient.so.16()(64bit)
          已安装: mysql-libs-5.5.43-1.el6.remi.x86_64 (@remi)
              Not found
You could try using --skip-broken to work around the problem
问题在:
lnmp.org安装了mysql-
有可能不行 php 用的 mysql库 就有问题。

删除这个包就Ok了?mysql-libs-5.5.43-1.el6.remi.x86_64

Q:干嘛不用我的来安装 整套?
A:历史原因啊。
Q:删除两个?
rpm -e  mysql-libs-5.5.43-1.el6.remi.x86_64
rpm -e   mysql-5.5.43-1.el6.remi.x86_64

A:
rpm -e mysql-5.1.73-3.el6_5.x86_64  删掉

回家后实践,如下且成功:
rpm -qa |grep mysql
mysql-devel-5.5.43-1.el6.remi.x86_64
mysql-libs-5.5.43-1.el6.remi.x86_64
mysql-5.5.43-1.el6.remi.x86_64
实践是这样的:
rpm -e mysql-devel-5.5.43-1.el6.remi.x86_64
rpm -e mysql-5.5.43-1.el6.remi.x86_64      
rpm -e mysql-libs-5.5.43-1.el6.remi.x86_64

于是重新安装一次并重启:
./install.sh
________
ps aux|grep hhvm
www       3155 55.0  2.5 676320 150628 ?       R    22:56   0:09 /usr/bin/hhvm --mode server --user www --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf


修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:

        location ~ .*\.(php|php5)?$  {
                #fastcgi_pass  unix:/data/runsock/php-cgi.sock;
                fastcgi_pass   unix:/data/runsock/hhvmsock/hhvm.sock;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
                include        fastcgi_params;
                }
service nginx reload
详细配置看后面,安装就按上面安装得了。依赖太多,太麻烦了。

ps aux|grep hhvm  
www       3155  3.3  2.8 880828 172836 ?       Sl   23:23   0:22 /usr/bin/hhvm --mode server --user www --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
strace  -f -p 3155 //访问一下看有无输出,实践是有输出的。说明安装成功了。


CentOS7 hhvm交给supervisord管理了:
ps -ef | grep super supervisord 这个进程在吗?
service supervisord restart

最后解决,开机这个/var/run/hhvm 会不见了(CentOS7里估计是一个内存磁盘,重启就没了,导致启动失败。),呵,开机就创建好了:
创好是这样的: ls /var/run/hhvm/
hhvm.hhbc  pid  sock


配置hhvm
# vi /etc/hhvm/server.ini


vi /etc/hhvm/php.ini



一个www的hhvm去读取一个mysql.sock,
而我的sock是放在一个mysql的组目录下,如何实现无permission Denny的读取?
所以得注意权限,如下所示 :
[root@iZ25z0ugwgtZ runsock]# ll /data/runsock
drwxrwxrwx 2 www   www   4096 2月  17 17:30 hhvm
drwxrwxrwx 2 mysql mysql 4096 2月  17 17:28 mysqlsock
drwxrwxrwx 2 www   www   4096 2月  17 17:30 phpsock

因为hhvm是www运行,而mysql是mysql运行,这块hhvm去读取mysql的sock时, mysql这个sock上层目录是mysql,导致不能读取,于是得对mysql的这个sock进行777,chmod -R 777 /data/runsock/mysqlsock :
cd /data
chown -R www:www runsock hhvm logs
chmod -R 777 runsock hhvm logs

访问后是502,如下修改:
./jackxiang.conf:       fastcgi_pass   unix:/var/run/hhvm/sock;修改:
./jackxiang.conf:       fastcgi_pass   unix:/data/runsock/hhvmsock/hhvm.sock;

于是,就好了?没有,必须重启动nginx,而不是reload,
connect() to unix:/var/run/hhvm/sock failed (2: No such file or directory) while connecting to upstream, client: 106.37.79.53, server: jackxiang.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/hhvm/sock:", host: "jackxiang.com"

pkill -9 nginx //否则会出现还是找原来的sock:
../sbin/nginx
这样就不用前面的每次开机建立如下目录和赋权限:

centOs7.0也就可以使用hhvm了,性能用在wordpress上,结合前端nginx的cache插件相当不错~
———————————————————安装问题—————————————————————————
yum -y --nogpgcheck install hhvm 出现:
--> 处理依赖关系 libwebp.so.4()(64bit),它被软件包 hhvm-3.5.0-4.el6.x86_64 需要
--> 完成依赖关系计算
错误:Package: hhvm-3.5.0-4.el6.x86_64 (gleez)
          Requires: libwebp.so.4()(64bit)
You could try using --skip-broken to work around the problem

出现:
一)源码安装webp库:
先下载libwebp-0.3.0.tar.gz
tar -zxvf libwebp-0.3.0.tar.gz
cd libwebp-0.3.0
./configure && make && make install
cp /usr/local/lib/libwebp.so.4.0.2 /usr/lib64/
ln -s /usr/lib64/libwebp.so.4.0.2 /usr/lib64/libwebp.so.4
ln -s /usr/lib64/libwebp.so.4.0.2 /usr/lib64/libwebp.so

二)yum search libwebp :
libwebp-devel.i686 : Development files for libwebp, a library for the WebP format
libwebp-devel.x86_64 : Development files for libwebp, a library for the WebP format
libwebp-java.x86_64 : Java bindings for libwebp, a library for the WebP format
libwebp.i686 : Library and tools for the WebP graphics format
libwebp.x86_64 : Library and tools for the WebP graphics format
libwebp-tools.x86_64 : The WebP command line tools

处理依赖关系 libwebp.so.4()(64bit),它被软件包 hhvm-3.5.0-4.el6.x86_64 需要,于是:
root@119.10.6.23:~# ln -s /usr/lib64/libwebp.so /usr/lib64/libwebp.so.4
root@119.10.6.23:~# ls /usr/lib64/libwebp.so.4
/usr/lib64/libwebp.so.4
root@119.10.6.23:~# ls -lart  /usr/lib64/libwebp.so.4
lrwxrwxrwx 1 root root 21 4月  28 10:08 /usr/lib64/libwebp.so.4 -> /usr/lib64/libwebp.so

还缺一堆东西:
yum install libyaml.x86_64
yum install libyaml-devel.x86_64
yum install php-pecl-yaml.x86_64

yum install inotify-tools-devel.x86_64
yum install  boost-python.x86_64
yum install boost-random.x86_64
yum install mysql-libs.x86_64
软件包 boost-1.54.0-9.el6.x86_64.rpm 没有签名
rpm -e  boost-devel-1.41.0-25.el6.centos.x86_64
rpm -e boost-1.41.0-25.el6.centos.x86_64      




———————————————建议centos hhvm使用下面的安装脚本———————————————
这样直接就是最新的了hhvm3.4了
添加epel yum源
rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装hhvm所需要的依赖包
yum -y install libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-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
添加gleez yum源(官方地址被墙)
rpm -Uvh http://blog.linuxeye.com/wp-content/uploads/2014/05/gleez-repo-6-0.el6.noarch.rpm
添加remi yum源
rpm -Uvh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.5-1.el6.remi.noarch.rpm
从remi安装hhvm依赖包
yum -y --enablerepo=remi install libwebp mysql mysql-devel mysql-lib
安装hhvm
yum -y --nogpgcheck install hhvm
查看hhvm版本号
hhvm --versionHipHop VM 3.4.0-dev+2014.09.29 (rel)Compiler: heads/master-0-gfe70efe4efa8318536ea1d4940362e83e641d905Repo schema: e3bee358a000cf7efe3a0f9642cdc9b488963dcaExtension API: 20140829脚本来自:http://blog.linuxeye.com/


CentOS 7下hhvm Nginx环境搭建:
http://www.linuxeye.com/Linux/2029.html
———————————————————安装步骤—————————————————————————
一、CentOS 6.5 32位安装 HHVM:
安装:
yum -y install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
cd /etc/yum.repos.d
wget http://www.hop5.in/yum/el6/hop5.repo
yum clean all
yum install hhvm
可能遇到的问题:
1.hhvm: error while loading shared libraries: liblcms2.so.2: cannot open shared object file: No such file or directory

yum install http://pkgrepo.linuxtech.net/el6/release/x86_64/liblcms2-2.4-1.el6.x86_64.rpm
2.其他相关文章
http://blog.csdn.net/ownfire/article/details/41366995
http://blog.linuxeye.com/396.html
http://blog.csdn.net/lxlmj/article/details/22283043


二、64位安装HHVM包:
安装hhvm
添加epel yum源

rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装hhvm所需要的依赖包

yum -y install libmcrypt-devel glog-devel jemalloc-devel tbb-devel libdwarf-devel mysql-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
添加gleez yum源(官方地址被墙)

rpm -Uvh http://blog.linuxeye.com/wp-content/uploads/2014/05/gleez-repo-6-0.el6.noarch.rpm
添加remi yum源

rpm -Uvh http://rpms.famillecollet.com/enterprise/6/remi/x86_64/remi-release-6.5-1.el6.remi.noarch.rpm
从remi安装hhvm依赖包

yum -y --enablerepo=remi install libwebp mysql mysql-devel mysql-lib
安装hhvm

yum -y --nogpgcheck install hhvm
查看hhvm版本号

hhvm --version
HipHop VM 3.4.0-dev+2014.09.29 (rel)
Compiler: heads/master-0-gfe70efe4efa8318536ea1d4940362e83e641d905
Repo schema: e3bee358a000cf7efe3a0f9642cdc9b488963dca
Extension API: 20140829
3. 配置hhvm
删除安装hhvm时创建的nginx用户

userdel -r nginx
修改hhvm目录权限为www

chown -R www.www /var/run/hhvm
chown -R www.www /var/log/hhvm
修改/usr/local/nginx/conf/nginx.conf使其中一段成为如下:

        location ~ .*\.(php|php5)?$  {
                fastcgi_pass   unix:/var/run/hhvm/sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
                }
service nginx reload
下载支持hhvm方式添加虚拟主机脚本 vhost_hhvm.sh

cd lnmp
wget http://blog.linuxeye.com/wp-content/uploads/2014/05/vhost_hhvm.sh
chmod +x vhost_hhvm.sh
配置hhvm修改/etc/hhvm/config.hdf,保持如下:

ResourceLimit {
  CoreFileSize = 0          # in bytes
  MaxSocket = 10000         # must be not 0, otherwise HHVM will not start
  SocketDefaultTimeout = 5  # in seconds
  MaxRSS = 0
  MaxRSSPollingCycle = 0    # in seconds, how often to check max memory
  DropCacheCycle = 0        # in seconds, how often to drop disk cache
}

Log {
  Level = Info
  AlwaysLogUnhandledExceptions = true
  RuntimeErrorReportingLevel = 8191
  UseLogFile = true
  UseSyslog = false
  File = /data/logs/hhvm/error.log
  Access {
    * {
      File = /data/logs/hhvm/access.log
      Format = %h %l %u % t \"%r\" %>s %b
    }
  }
}

MySQL {
  ReadOnly = false
  ConnectTimeout = 1000      # in ms
  ReadTimeout = 1000         # in ms
  SlowQueryThreshold = 1000  # in ms, log slow queries as errors
  KillOnTimeout = false
}

Mail {
  SendmailPath = /usr/sbin/sendmail -t -i
  ForceExtraParameters =
}
配置hhvm修改/etc/hhvm/server.ini,使内容保存如下:

; php options
pid = /var/run/hhvm/pid

; hhvm specific
;hhvm.server.port = 9001
hhvm.server.file_socket = /var/run/hhvm/sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
修改/etc/hhvm/php.ini,使内容保存如下:

hhvm.mysql.socket = /tmp/mysql.sock ;指定mysql.sock路径(hhvm默认路径sock路径是/var/lib/mysql/mysql.sock)
expose_php = 0 ;关闭头信息X-Powered-By (和hhvm.server.expose_hphp = false作用一样)
memory_limit = 400M
post_max_size = 50M
默认hhvm不提供php中类似disable_functions参数,如何禁用hhvm中shell_exec函数?(可选)
在/etc/hhvm/php.ini中追加如下:

hhvm.jit_enable_rename_function=true
auto_prepend_file= /home/wwwroot/default/disable_functions
新建/home/wwwroot/default/disable_functions,使该文件内容如下:

<?php

function __forbidden_function($name, $obj, $args, $data, &$done) {
  throw new Exception('Calling '.$name.' is forbidden.');
}

fb_intercept('shell_exec', '__forbidden_function');
配置service管理hhvm:

cd /etc/init.d/
rm -rf hhvm #官方默认脚本是以www运行,建议用我修改后的
wget http://blog.linuxeye.com/wp-content/uploads/2014/05/hhvm
chmod +x hhvm
chkconfig hhvm on
service hhvm restart


管理hhvm服务
systemctl enable hhvm #开机自启动
systemctl start hhvm #启动hhvm
systemctl stop hhvm #停止hhvm
systemctl restart hhvm #重启动hhvm
systemctl status hhvm #查看hhvm状态

添加虚拟主机:
vhost_hhvm.sh #和lnmp添加虚拟主机一样
测试wordpress完美运行,且速度非常快;discuz后台正常,前台页面显示有点问题
参考:https://github.com/facebook/hhvm/wiki/HHVM-Pre-built-packages-for-Centos-6.5

安装时,这个rpm包是有很多的依赖:
因为依赖关系问题而跳过的软件包:
    OpenEXR-libs-1.6.1-8.1.el6.x86_64 来自 base
    boost-1.54.0-9.el6.x86_64 来自 gleez
    boost-atomic-1.54.0-9.el6.x86_64 来自 gleez
    boost-chrono-1.54.0-9.el6.x86_64 来自 gleez
    boost-context-1.54.0-9.el6.x86_64 来自 gleez
    boost-date-time-1.54.0-9.el6.x86_64 来自 gleez
    boost-devel-1.54.0-9.el6.x86_64 来自 gleez
    boost-filesystem-1.54.0-9.el6.x86_64 来自 gleez
    boost-graph-1.54.0-9.el6.x86_64 来自 gleez
    boost-iostreams-1.54.0-9.el6.x86_64 来自 gleez
    boost-locale-1.54.0-9.el6.x86_64 来自 gleez
    boost-log-1.54.0-9.el6.x86_64 来自 gleez
    boost-math-1.54.0-9.el6.x86_64 来自 gleez
    boost-program-options-1.54.0-9.el6.x86_64 来自 gleez
    boost-python-1.54.0-9.el6.x86_64 来自 gleez
    boost-random-1.54.0-9.el6.x86_64 来自 gleez
    boost-regex-1.54.0-9.el6.x86_64 来自 gleez
    boost-serialization-1.54.0-9.el6.x86_64 来自 gleez
    boost-signals-1.54.0-9.el6.x86_64 来自 gleez
    boost-system-1.54.0-9.el6.x86_64 来自 gleez
    boost-test-1.54.0-9.el6.x86_64 来自 gleez
    boost-thread-1.54.0-9.el6.x86_64 来自 gleez
    boost-timer-1.54.0-9.el6.x86_64 来自 gleez
    boost-wave-1.54.0-9.el6.x86_64 来自 gleez
    hhvm-3.5.0-4.el6.x86_64 来自 gleez
    ilmbase-1.0.1-6.1.el6.x86_64 来自 base
    inotify-tools-3.14-1.el6.x86_64 来自 epel
    lcms2-2.3-2.el6.x86_64 来自 epel
    libvpx-1.3.0-5.el6_5.x86_64 来自 base
    libyaml-0.1.3-4.el6_6.x86_64 来自 updates


yum install boost-1.54.0-9.el6.x86_64

源码安装:http://tomlog.com/tech/2012/12/21/build-hhvm.html


安装脚本:http://amh.sh/bbs/post-4874-1-1.htm

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/7838/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2016-3-2 23:52
评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]