centos6.5 yum安装nginx+hhvm+mariadb环境

post by rocdk890 / 2016-1-27 15:11 Wednesday linux技术
  一直都听说hhvm的性能怎么怎么好,速度怎么怎么快,就想自己也搭建个环境来测试下,在搭建的中途遇到的了各种坑,让我拖到今天才终于把hhvm搭建成功.好了,下面来看教程吧.
  系统:centos 6.5(64位)
1.添加搭建hhvm需要的源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
wget -O /etc/yum.repos.d/hop5.repo http://www.hop5.in/yum/el6/hop5.repo
rpm -Uvh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
或者
rpm -Uvh http://download.slogra.com/yum-x86_64/epel-release-6-8.noarch.rpm

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

2.安装hhvm
yum install hhvm -y
点击查看原图
3.安装nginx
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx -y

4.安装MariaDB
vi /etc/yum.repos.d/MariaDB.repo


yum install MariaDB-server MariaDB-client MariaDB-devel -y

5.验证hhvm
hhvm --version

6.修改hhvm配置文件
cp /etc/init.d/hhvm /etc/init.d/hhvm.old--
cp /etc/hhvm/config.hdf /etc/hhvm/config.hdf.old--
cp /etc/hhvm/php.ini /etc/hhvm/php.ini.old--
cp /etc/hhvm/server.hdf /etc/hhvm/server.hdf.old--

wget -O /etc/init.d/hhvm https://cdn.zntec.cn/store/tools/vhost_hhvm/hhvm
或者
wget -O /etc/init.d/hhvm http://download.slogra.com/hhvm/hhvm
chmod +x /etc/init.d/hhvm

cd /etc/hhvm
vi server.ini
01; php options
02pid = /var/run/hhvm/pid
03 
04; hhvm specific
05;hhvm.server.port = 9001
06hhvm.server.file_socket = /var/run/hhvm/sock
07hhvm.server.type = fastcgi
08hhvm.server.default_document = index.php
09hhvm.log.use_log_file = true
10hhvm.log.file = /var/log/hhvm/error.log
11hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc


vi config.hdf
01ResourceLimit {
02  CoreFileSize = 0          # in bytes
03  MaxSocket = 10000         # must be not 0, otherwise HHVM will not start
04  SocketDefaultTimeout = 5  # in seconds
05  MaxRSS = 0
06  MaxRSSPollingCycle = 0    # in seconds, how often to check max memory
07  DropCacheCycle = 0        # in seconds, how often to drop disk cache
08}
09 
10Log {
11  Level = Info
12  AlwaysLogUnhandledExceptions = true
13  RuntimeErrorReportingLevel = 8191
14  UseLogFile = true
15  UseSyslog = false
16  File = /var/log/hhvm/error.log
17  Access {
18    * {
19      File = /var/log/hhvm/access.log
20      Format = %h %l %u % t \"%r\" %>s %b
21    }
22  }
23}
24 
25MySQL {
26  ReadOnly = false
27  ConnectTimeout = 1000      # in ms
28  ReadTimeout = 1000         # in ms
29  SlowQueryThreshold = 1000  # in ms, log slow queries as errors
30  KillOnTimeout = false
31}
32 
33Mail {
34  SendmailPath = /usr/sbin/sendmail -t -i
35  ForceExtraParameters =
36}


vi php.ini
1hhvm.mysql.socket = /var/lib/mysql/mysql.sock ;
2expose_php = 0 ;
3memory_limit = 400M
4post_max_size = 50M


vi /etc/nginx/hhvm.conf
1location ~ [^/]\.php(/|$) {
2    fastcgi_keep_conn on;
3    fastcgi_pass   unix:/var/run/hhvm/sock;
4    fastcgi_index  index.php;
5    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
6    include        fastcgi_params;
7}


配置nginx虚拟主机:
vi /etc/nginx/conf.d/www.conf
01server {
02    listen 80;
03    server_name 192.168.10.241;   #这里修改成你自己的域名或ip
04    index index.html index.htm index.php;
05    root  /var/www/vhosts/;       #这里修改成你自己的目录
06 
07    #include wordpress.conf;
08    include hhvm.conf;
09 
10    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
11        expires      30d;
12    }
13 
14    location ~ .*\.(js|css)?$ {
15        expires      12h;
16    }
17 
18    access_log  /var/log/nginx/access.log;
19}


配置完成后,启动nginx hhvm MariaDB
service mysql start
service hhvm start
service nginx start
chkconfig mysql on
chkconfig hhvm on
chkconfig nginx on

mysql -u root
MariaDB [(none)]>UPDATE mysql.user SET password=PASSWORD('passwd') WHERE User='root';
MariaDB [(none)]>FLUSH PRIVILEGES;

好了,现在我们来测试hhvm是否可以连上mariadb.
vi /var/www/vhosts/index.php
01<?php
02phpinfo();
03$link=mysql_connect("localhost","root","passwd");
04if(!$link) echo "FAILD!连接错误,用户名密码不对,这是slogra的测试";
05else echo "is OK!可以连接,这是slogra的测试";
06 
07mysql_select_db("test");
08$sql = "CREATE TABLE user_info
09(
10user_id varchar(15),
11user_name varchar(15),
12user_age int
13)";
14 
15mysql_query($sql,$link);
16 
17mysql_close($link);
18 
19?>


保存后,我们在浏览器访问http://192.168.10.241
点击查看原图
可以看到hhvm连接mariadb是成功的,现在我们进mariadb里看是否有数据写入.
mysql -u root -p
MariaDB [(none)]>use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [(none)]>show tables;
+----------------+
| Tables_in_test |
+----------------+
| user_info      |
+----------------+
1 row in set (0.00 sec)
MariaDB [(none)]>desc user_info;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| user_id   | varchar(15) | YES  |     | NULL    |       |
| user_name | varchar(15) | YES  |     | NULL    |       |
| user_age  | int(11)     | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

可以看到有数据写入,证明hhvm跟mariadb之间通信是成功的.
好了,本文就到这里了,有兴趣的朋友可以自己继续去研究.
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-629.html

标签: centos yum 安装 install hhvm HipHop mariadb

正在载入...