Centos7安装配置Xhgui
生活随笔
收集整理的這篇文章主要介紹了
Centos7安装配置Xhgui
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
XhProf是Facebook出品的一個PHP性能監(jiān)控工具,只包含基本的界面和圖形來分析數(shù)據(jù)。后來Paul Reinheimer在此基礎(chǔ)上開發(fā)了Xhgui,提供了更好的界面和功能,其主頁在https://github.com/perftools/xhgui,其實步驟說的很詳細,但是在CentOS7上安裝并不容易,因為很多程序需要編譯,在這里記錄一下
1、CentOS7最小安裝, yum update 2、安裝gcc, yum install net-tools gcc gcc-c++ wget vim 3、安裝php, yum install php php-devel php-fpm git 4、下載nginx,? ? ? ? mkdir ~/download ? ? ? ?cd ~/download ? ? ? wget?http://nginx.org/download/nginx-1.9.9.tar.gz ? ? ? tar xvf nginx-1.99.tar.gz ? ? ? cd nginx-1.99 ? ? ? yum install pcre-devel zlib-devel ?(否則configure會出現(xiàn)錯誤) ? ? ? ./configure? ? ? ? make? ? ? ? make install ? ? ? nginx安裝在/usr/local/nginx下 5、取消selinux,centos7確實很穩(wěn)定安全,但是很麻煩,取消之后,避免出現(xiàn)一些奇怪的問題, ? ? ?vim /etc/selinux/config ? ? ?修改SELINUX=disabled ? ? ?上面的方法需要重啟,并且是長期有效的,臨時性的方法是setenforce 0 6、創(chuàng)建nginx的80端口根目錄,mkdir -p /data/html 7、修改nginx配置文件,vim /usr/local/nginx/conf/nginx.conf ? ? ?修改http->server 80下的內(nèi)容,如下 ? ? ?????server?{ ????????listen???????80; ????????server_name??localhost; ????????location?/?{ ????????????root???/data/html; ????????????index??index.html?index.htm; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???/data/html; ????????} ????????location?~?\.php$?{ ????????????root???????????/data/html; ????????????fastcgi_pass???127.0.0.1:9000; ????????????fastcgi_index??index.php; ????????????fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; ????????????include????????fastcgi_params; ????????} ????} ? ? 需要修改的地方,黑體字做了標(biāo)注,location ~ \.php$需要取消注釋 8、ln /usr/local/nginx/sbin/nginx /usr/sbin/nginx 9、systemctl auto php-fpm ? ? ?systemctl start php-fpm 10、vim /data/html/info.php ? ? ? ?<?php ? ? ? ? ? ? ? phpinfo(); ? ? ? curl localhost/info.php ? ? ? 說明php配置成功,需要注意,如果沒有取消selinux,這里會出現(xiàn)File not found,如果一定要用selinux,需要賦予/data/html的www運行權(quán)限。 11、配置xhgui的步驟其實很簡單,按照文檔來就可以了 12、XHProf ? ? ? ?cd ~/download ? ? ? ?wget?http://pecl.php.net/get/xhprof-0.9.4.tgz ? ? ? ?tar?xvf?xhprof-0.9.4.tgz ? ? ? ?cd xhprof-0.9.4/extension ? ? ? ?phpize ? ? ? ?./configure ? ? ? ?make ? ? ? ?make install ? ? ? ?vim /etc/php.ini ? ? ? ?在最后加入 ? ? ? ?extension=xhprof.so ? ? ? 通過php -m可以看到xhprof.so已經(jīng)安裝成功 12、UpProfiler ? ? ? ?cd ~/download ? ? ? ?git clone?https://github.com/FriendsOfPHP/uprofiler.git ? ? ? ?cd uprofiler/extension ? ? ? ?phpize ? ? ? ?./configure ? ? ? ?make? ? ? ? ?make install ? ? ? ?vim /etc/php.ini ? ? ? ?最后加入 ? ? ? ?extension=uprofiler.so ? ? ? ?用php -m驗證 13、tideways ? ? ? ?cd ~/download ? ? ? ?git?clone?https://github.com/tideways/php-profiler-extension.git?? ? ? ? ?cd?php-profiler-extension/ ? ? ? ?phpize ? ? ? ?./configure ? ? ? ?make? ? ? ? ?make install ? ? ? ?vim /etc/php.ini ? ? ? ?最后加入 ? ? ? ?extension=tideways.so ? ? ? ?用php -m驗證結(jié)果 14、 MongoDB的PHP驅(qū)動 ? ? ? ?cd ~/download ? ? ? ?wget?http://pecl.php.net/get/mongo-1.6.12.tgz ? ? ? ?tar xvf??mongo-1.6.12.tgz ? ? ? ?cd mongo-1.6.12 ? ? ? ?phpize ? ? ? ?yum install openssl-devel ? ? ? ?./configure ? ? ? ?make && make install ? ? ? ?vim /etc/php.ini ? ? ? ?最后增加 ? ? ? ?extension=mongo.so ? ? ? ?用php -m驗證 15、安裝MongoDB ? ? ? vim /etc/yum.repose.d/mongodb-org-3.2.repo ? ? ??[mongodb-org-3.2] ? ? ? ? ? name=MongoDB?Repository ? ? ? ? ? baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ ? ? ? ? ?gpgcheck=0 ? ? ? ? ?enabled=1 安裝 yum install mongodb-org systemctl enable mongod systemctl start mongod 16、mcrypt cd ~/download wget ?http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tar xvf libmcrypt-2.5.8.tar.gz cd? libmcrypt-2.5.8 ./configure make make install cd ~/download wget http://museum.php.net/php5/php-5.4.16.tar.gz ?cd?php-5.4.16/ext/mcrypt/ ?phpize ./configure make make install vim /etc/php.ini 最后增加 extension=mcrypt.so 用php -m驗證 17、Dom cd?~/download/php-5.4.16/ext/dom/ yum install libxml2-devel phpize ./configure make make install vim /etc/php.ini 最后增加 extension=dom.so 用php -m驗證 19、配置nginx,將xhgui放在88端口 vim /usr/local/nginx/conf/nginx.conf 增加 server{ listen?88; server_name?localhost; root?/data/xhgui/webroot; index?index.php; location?/?{ try_files?$uri?$uri/?/index.php?$uri&$args; } location?~?\.php$?{ try_files?$uri?=404; include?fastcgi_params; fastcgi_pass?127.0.0.1:9000; fastcgi_index?index.php; fastcgi_param?SCRIPT_FILENAME?$document_root$fastcgi_script_name; } } cd /data git clone https://github.com/perftools/xhgui.git 打開防火墻端口 firewall-cmd?--add-service=http firewall-cmd?--permanent?--add-service=http firewall-cmd?--add-port=88/tcp firewall-cmd?--permanent?--add-port=88/tcp 19、對80端口注入xhgui文件 location?~?\.php$?{ root???????????/data/html; fastcgi_pass???127.0.0.1:9000; fastcgi_index??index.php; fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; include????????fastcgi_params; fastcgi_param??PHP_VALUE?"auto_prepend_file=/data/xhgui/external/header.php"; } nginx -s reload 20、初始化 cd /data/xhgui php install.php 這一步包含下載composer,Slim,以及初始化mongodb 21、 驗證 curl localhost/info.php curl localhost:88 在這里88端口沒有輸出,是因為默認/etc/php.ini中設(shè)置了display_errors=Off,修改為On 重啟php-fpm, systemctl restart php-fpm 可以看到錯誤,是沒有設(shè)置時區(qū),修改/etc/php.ini 修改date.timezone?=?Asia/Chongqing 重啟php-fpm, systemctl restart php-fpm curl localhost:88 如果配置正確的話,這里應(yīng)該是正常的,沒有錯誤 也可以在瀏覽器中訪問,這臺機器的ip為172.16.9.145,所以可以訪問 http://172.16.9.145:88 22、測試程序 vim /data/html/test.php <?php$n=5000;
$a?=?createArray($n);
$a?=?sortArray($a);
echoArray($a);
function?createArray($n){
? ? ? ? $a;
? ? ? ? for($i=0;$i<$n;$i++){
? ? ? ? ? ? ? ? $a[$i]=rand(0,$n);
? ? ? ? }
? ? ? ? return?$a;
}
function?echoArray($a){
? ? ? ? for($i=0;$i<count($a);$i++){
? ? ? ? ? ? ? ? echo?$a[$i]."?";
? ? ? ? }
}
function?sortArray($a){
? ? ? ? for($i=0;$i<count($a);$i++){
? ? ? ? ? ? ? ? for($j=$i+1;$j<count($a);$j++){
? ? ? ? ? ? ? ? ? ? ? ? if($a[$i]<$a[$j]){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $tmp?=?$a[$i];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $a[$i]=$a[$j];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $a[$j]=$tmp;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return?$a; } 其實很簡單,就是一個創(chuàng)建數(shù)組,進行排序的過程,可以在瀏覽器中運行http://172.16.9.145/test.php,理論上就可以在http://172.16.9.145:88看到結(jié)果了, 但是,刷新88端口,一般是看不到結(jié)果的,這里是一個采樣問題,xhgui是按照1%采樣的,所以對于開發(fā)來說,需要100%采樣,需要修改 vim /data/xhgui/config/config.php 'profiler.enable'?=>?function()?{ //return rand(0,100) == 42 return?rand(0,?100)?>?0?; }, 黑體子是修改內(nèi)容,這就是100%的采樣,再運行http://172.16.9.145/test.php,就可以在http://172.16.9.145:88上看到結(jié)果了, 可以看到采樣的結(jié)果,包括程序的等待時間(wt)、cpu時間、內(nèi)存等等信息,還可以通過view Graphy看到函數(shù)調(diào)用的過程,顏色越深,說明運行越慢,需要處理。 23、其他 xhgui使用mongodb保存性能數(shù)據(jù),數(shù)據(jù)庫連接信息保存在xhgui/config/config.php中,這意味著可以將性能信息保存到遠程機器,還可以將多臺機器的性能數(shù)據(jù)放在一起,我們可以看一下性能數(shù)據(jù)的結(jié)構(gòu),如下 mongo >use xhprof >db.results.find().limit(1).pretty(); 查看一下鍵meta的信息,如下 "meta"?:?{ "url"?:?"/test.php", "SERVER"?:?{ "USER"?:?"apache", "HOME"?:?"/usr/share/httpd", "FCGI_ROLE"?:?"RESPONDER", "SCRIPT_FILENAME"?:?"/data/html/test.php", "QUERY_STRING"?:?"", "REQUEST_METHOD"?:?"GET", "CONTENT_TYPE"?:?"", "CONTENT_LENGTH"?:?"", "SCRIPT_NAME"?:?"/test.php", "REQUEST_URI"?:?"/test.php", "DOCUMENT_URI"?:?"/test.php", "DOCUMENT_ROOT"?:?"/data/html", "SERVER_PROTOCOL"?:?"HTTP/1.1", "REQUEST_SCHEME"?:?"http", "GATEWAY_INTERFACE"?:?"CGI/1.1", "SERVER_SOFTWARE"?:?"nginx/1.9.9", "REMOTE_ADDR"?:?"172.16.9.255", "REMOTE_PORT"?:?"62433", "SERVER_ADDR"?:?"172.16.9.145", "SERVER_PORT"?:?"80", "SERVER_NAME"?:?"localhost", "REDIRECT_STATUS"?:?"200", "PHP_VALUE"?:?"auto_prepend_file=/data/xhgui/external/header.php", "HTTP_HOST"?:?"172.16.9.145", "HTTP_CONNECTION"?:?"keep-alive", "HTTP_CACHE_CONTROL"?:?"max-age=0", "HTTP_ACCEPT"?:?"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "HTTP_UPGRADE_INSECURE_REQUESTS"?:?"1", "HTTP_USER_AGENT"?:?"Mozilla/5.0?(Windows?NT?6.3;?WOW64)?AppleWebKit/537.36?(KHTML,?like?Gecko)?Chrome/46.0.2490.86?Safari/537.36", "HTTP_ACCEPT_ENCODING"?:?"gzip,?deflate,?sdch", "HTTP_ACCEPT_LANGUAGE"?:?"zh-CN,zh;q=0.8", "HTTP_COOKIE"?:?"slim_session=1450653227%7CBxhI8%2BKm%2B47xsnTB%2BOZVAv9qjPHQYC1oCIcfWhIblGI%3D%7C3a5b1cf4f47a77302d253b577949544f4ffe627b", "PHP_SELF"?:?"/test.php", "REQUEST_TIME_FLOAT"?:?1450652599.176433, "REQUEST_TIME"?:?NumberLong(1450652599) }, 可以通過SERVER_*, HTTP_*看到服務(wù)器信息,可以用來區(qū)分不同的主機,所以可以通過這些信息來過濾,可以支持多個主機 ? ? ? ? ? ?? ?
轉(zhuǎn)載于:https://www.cnblogs.com/stone-fly/p/5062389.html
總結(jié)
以上是生活随笔為你收集整理的Centos7安装配置Xhgui的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下的iwpriv(iwlist
- 下一篇: 免费的HTML5连载来了《HTML5网页