由于默认的 smtp_line_length_limit值为990,所以会自动换行,并导致中文邮件可能出现部分汉字的乱码。
处理方法: 修改该属性值,或者邮件内容不要放一行。
修改属性值方法: postconf -e smtp_line_length_limit=10240
由于默认的 smtp_line_length_limit值为990,所以会自动换行,并导致中文邮件可能出现部分汉字的乱码。
处理方法: 修改该属性值,或者邮件内容不要放一行。
修改属性值方法: postconf -e smtp_line_length_limit=10240
My favorite question during Interview for people to work as MySQL DBAs or be involved with MySQL Performance in some way is to ask them what should be tuned in MySQL Server straight after installation, assuming it was installed with default settings.
在面试MySQL DBA或者那些打算做MySQL性能优化的人时,我最喜欢问题是:MySQL服务器按照默认设置安装完之后,应该做哪些方面的调节呢?
I’m surprised how many people fail to provide any reasonable answer to this question, and how many servers are where in wild which are running with default settings.
令我很惊讶的是,有多少人对这个问题无法给出合理的答案,又有多少服务器都运行在默认的设置下。
Even though you can tune quite a lot of variables in MySQL Servers only few of them are really important for most common workload. After you get these settings right other changes will most commonly offer only incremental performance improvements.
尽管你可以调节很多MySQL服务器上的变量,但是在大多数通常的工作负载下,只有少数几个才真正重要。如果你把这些变量设置正确了,那么修改其他变量最多只能对系统性能改善有一定提升。
key_buffer_size - Very important if you use MyISAM tables. Set up to 30-40% of available memory if you use MyISAM tables exclusively. Right size depends on amount of indexes, data size and workload – remember MyISAM uses OS cache to cache the data so you need to leave memory for it as well, and data can be much larger than indexes in many cases. Check however if all of key_buffer is used over time – it is not rare to see key_buffer being set to 4G while combined size of .MYI files is just 1GB. This would be just a waste. If you use few MyISAM tables you’ll want to keep it lower but still at least 16-32Mb so it is large enough to accommodate indexes for temporary tables which are created on disk.
key_buffer_size - 这对MyISAM表来说非常重要。如果只是使用MyISAM表,可以把它设置为可用内存的 30-40%。合理的值取决于索引大小、数据量以及负载 — 记住,MyISAM表会使用操作系统的缓存来缓存数据,因此需要留出部分内存给它们,很多情况下数据比索引大多了。尽管如此,需要总是检查是否所有的 key_buffer 都被利用了 — .MYI 文件只有 1GB,而 key_buffer 却设置为 4GB 的情况是非常少的。这么做太浪费了。如果你很少使用MyISAM表,那么也保留低于 16-32MB 的 key_buffer_size 以适应给予磁盘的临时表索引所需。
innodb_buffer_pool_size This is very important variable to tune if you’re using Innodb tables. Innodb tables are much more sensitive to buffer size compared to MyISAM. MyISAM may work kind of OK with default key_buffer_size even with large data set but it will crawl with default innodb_buffer_pool_size. Also Innodb buffer pool caches both data and index pages so you do not need to leave space for OS cache so values up to 70-80% of memory often make sense for Innodb only installations. Same rules as for key_buffer apply – if you have small data set and it is not going to grow dramatically do not oversize innodb_buffer_pool_size you might find better use for memory available.
innodb_buffer_pool_size - 这对Innodb表来说非常重要。Innodb相比MyISAM表对缓冲更为敏感。MyISAM可以在默认的 key_buffer_size 设置下运行的可以,然而Innodb在默认的 innodb_buffer_pool_size 设置下却跟蜗牛似的。由于Innodb把数据和索引都缓存起来,无需留给操作系统太多的内存,因此如果只需要用Innodb的话则可以设置它高达 70-80% 的可用内存。一些应用于 key_buffer 的规则有 — 如果你的数据量不大,并且不会暴增,那么无需把 innodb_buffer_pool_size 设置的太大了。
innodb_additional_pool_size This one does not really affect performance too much, at least on OS with decent memory allocators. Still you might want to have it 20MB (sometimes larger) so you can see how much memory Innodb allocates for misc needs.
innodb_additional_pool_size - 这个选项对性能影响并不太多,至少在有差不多足够内存可分配的操作系统上是这样。不过如果你仍然想设置为 20MB(或者更大),因此就需要看一下Innodb其他需要分配的内存有多少。
innodb_log_file_size Very important for write intensive workloads especially for large data sets. Larger sizes offer better performance but increase recovery times so be careful. I normally use values 64M-512M depending on server size.
innodb_log_file_size 在高写入负载尤其是大数据集的情况下很重要。这个值越大则性能相对越高,但是要注意到可能会增加恢复时间。我经常设置为 64-512MB,跟据服务器大小而异。
innodb_log_buffer_size Default for this one is kind of OK for many workloads with medium write load and shorter transactions. If you have update activity spikes however or work with blobs a lot you might want to increase it. Do not set it too high however as it would be waste of memory – it is flushed every 1 sec anyway so you do not need space for more than 1 sec worth of updates. 8MB-16MB are typically enough. Smaller installations should use smaller values.
innodb_log_buffer_size 默认的设置在中等强度写入负载以及较短事务的情况下,服务器性能还可以。如果存在更新操作峰值或者负载较大,就应该考虑加大它的值了。如果它的值设置太高了,可能会浪费内存 — 它每秒都会刷新一次,因此无需设置超过1秒所需的内存空间。通常 8-16MB 就足够了。越小的系统它的值越小。
innodb_flush_logs_at_trx_commit Crying about Innodb being 100 times slower than MyISAM ? You probably forgot to adjust this value. Default value of 1 will mean each update transaction commit (or each statement outside of transaction) will need to flush log to the disk which is rather expensive, especially if you do not have Battery backed up cache. Many applications, especially those moved from MyISAM tables are OK with value 2 which means do not flush log to the disk but only flush it to OS cache. The log is still flushed to the disk each second so you normally would not loose more than 1-2 sec worth of updates. Value 0 is a bit faster but is a bit less secure as you can lose transactions even in case MySQL Server crashes. Value 2 only cause data loss with full OS crash.
innodb_flush_logs_at_trx_commit 是否为Innodb比MyISAM慢1000倍而头大?看来也许你忘了修改这个参数了。默认值是 1,这意味着每次提交的更新事务(或者每个事务之外的语句)都会刷新到磁盘中,而这相当耗费资源,尤其是没有电池备用缓存时。很多应用程序,尤其是从 MyISAM转变过来的那些,把它的值设置为 2 就可以了,也就是不把日志刷新到磁盘上,而只刷新到操作系统的缓存上。日志仍然会每秒刷新到磁盘中去,因此通常不会丢失每秒1-2次更新的消耗。如果设置为 0 就快很多了,不过也相对不安全了 — MySQL服务器崩溃时就会丢失一些事务。设置为 2 指挥丢失刷新到操作系统缓存的那部分事务。
table_cache - Opening tables can be expensive. For example MyISAM tables mark MYI header to mark table as currently in use. You do not want this to happen so frequently and it is typically best to size your cache so it is large enough to keep most of your tables open. It uses some OS resources and some memory but for modern hardware it is typically not the problem. 1024 is good value for applications with couple hundreds tables (remember each connection needs its own entry) if you have many connections or many tables increase it larger. I’ve seen values over 100.000 used.
table_cache – 打开一个表的开销可能很大。例如MyISAM把MYI文件头标志该表正在使用中。你肯定不希望这种操作太频繁,所以通常要加大缓存数量,使得足以最大限度地缓存打开的表。它需要用到操作系统的资源以及内存,对当前的硬件配置来说当然不是什么问题了。如果你有200多个表的话,那么设置为 1024 也许比较合适(每个线程都需要打开表),如果连接数比较大那么就加大它的值。我曾经见过设置为 100,000 的情况。
thread_cache Thread creation/destructions can be expensive, which happen at each connect/disconnect. I normally set this value to at least 16. If application has large jumps in amount of concurrent connections and I see fast growth of
Threads_Created variable I boost it higher. The goal is not to have threads created in normal operation.
thread_cache – 线程的创建和销毁的开销可能很大,因为每个线程的连接/断开都需要。我通常至少设置为 16。如果应用程序中有大量的跳跃并发连接并且 Threads_Created 的值也比较大,那么我就会加大它的值。它的目的是在通常的操作中无需创建新线程。
query_cache If your application is read intensive and you do not have application level caches this can be great help. Do not set it too large as it may slow things down as its maintenance may get expensive. Values from 32M to 512M normally make sense. Check it however after a while and see if it is well used. For certain workloads cache hit ratio is lower than would justify having it enabled.
query_cache – 如果你的应用程序有大量读,而且没有应用程序级别的缓存,那么这很有用。不要把它设置太大了,因为想要维护它也需要不少开销,这会导致MySQL变慢。通常设置为 32-512Mb。设置完之后最好是跟踪一段时间,查看是否运行良好。在一定的负载压力下,如果缓存命中率太低了,就启用它。
Note: as you can see all of these are global variables. These variables depend on hardware and mix of storage engines, while per session variables are typically workload specific. If you have simple queries there is no reason to increase sort_buffer_sizeeven if you have 64GB of memory to waste. Furthermore doing so may decrease performance.
I normally leave per session variable tuning to second step after I can analyze workload.
注意:就像你看到的上面这些全局表量,它们都是依据硬件配置以及不同的存储引擎而不同,但是会话变量通常是根据不同的负载来设定的。如果你只有一些简单的查询,那么就无需增加sort_buffer_size 的值了,尽管你有 64GB 的内存。搞不好也许会降低性能。
我通常在分析系统负载后才来设置会话变量。
P.S Note MySQL distribution contains bunch of sample my.cnf files which may be great templates to use. Typically they would already be much better than defaults if you chose correct one.
P.S,MySQL的发行版已经包含了各种 my.cnf 范例文件了,可以作为配置模板使用。通常这比你使用默认设置好的多了。
转自:http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation
1)环境:
a. 我们本地是Windows系统,然后使用VirutalBox安装一个虚拟的Linux系统。
在本地的Windows系统上分别安装nginx(侦听8080端口)和apache(侦听80端口)。在虚拟的Linux系统上安装apache(侦听80端口)。
这样我们相当于拥有了1台nginx在前端作为反向代理服务器;后面有2台apache作为应用程序服务器(可以看作是小型的server cluster。;-) );
b. nginx用来作为反向代理服务器,放置到两台apache之前,作为用户访问的入口;
nginx仅仅处理静态页面,动态的页面(php请求)统统都交付给后台的两台apache来处理。
也就是说,可以把我们网站的静态页面或者文件放置到nginx的目录下;动态的页面和数据库访问都保留到后台的apache服务器上。
c. 如下介绍两种方法实现server cluster的负载均衡。
我们假设前端nginx(为127.0.0.1:80)仅仅包含一个静态页面index.html;
后台的两个apache服务器(分别为localhost:80和158.37.70.143:80),一台根目录放置phpMyAdmin文件夹和test.php(里面测试代码为print “server1″;),另一台根目录仅仅放置一个test.php(里面测试代码为print “server2″;)。
2)针对不同请求 的负载均衡:
a. 在最简单地构建反向代理的时候 (nginx仅仅处理静态不处理动态内容,动态内容交给后台的apache server来处理),我们具体的设置为:在nginx.conf中修改:
location ~ \.php$ {
proxy_pass 158.37.70.143:80 ;
}
>这样当客户端访问localhost:8080/index.html的时候,前端的nginx会自动进行响应;
>当用户访问localhost:8080/test.php的时候(这个时候nginx目录下根本就没有该文件),但是通过上面的设置location ~ \.php$(表示正则表达式匹配以.php结尾的文件,详情参看location是如何定义和匹配的http://wiki.nginx.org/NginxHttpCoreModule) ,nginx服务器会自动pass给158.37.70.143的apache服务器了。该服务器下的test.php就会被自动解析,然后将html的结果页面返回给nginx,然后nginx进行显示(如果nginx使用memcached模块或者squid还可以支持缓存),输出结果为打印server2。
如上是最为简单的使用nginx做为反向代理服务器的例子;
b. 我们现在对如上例子进行扩展,使其支持如上的两台服务器。
我们设置nginx.conf的server模块部分,将对应部分修改为:
location ^~ /phpMyAdmin/ {
proxy_pass 127.0.0.1:80 ;
}
location ~ \.php$ {
proxy_pass 158.37.70.143:80 ;
}
上面第一个部分location ^~ /phpMyAdmin/,表示不使用正则表达式匹配(^~),而是直接匹配,也就是如果客户端访问的URL是以http://localhost:8080/phpMyAdmin/ 开头的话(本地的nginx目录下根本没有phpMyAdmin目录),nginx会自动pass到127.0.0.1:80 的Apache服务器,该服务器对phpMyAdmin目录下的页面进行解析,然后将结果发送给nginx,后者显示;
如果客户端访问URL是http://localhost/test.php 的话,则会被pass到158.37.70.143:80 的apache进行处理。
因此综上,我们实现了针对不同请求的负载均衡。
>如果用户访问静态页面index.html,最前端的nginx直接进行响应;
>如果用户访问test.php页面的话,158.37.70.143:80 的Apache进行响应;
>如果用户访问目录phpMyAdmin下的页面的话,127.0.0.1:80 的Apache进行响应;
3)访问同一页面 的负载均衡:
即用户访问http://localhost:8080/test.php 这个同一页面的时候,我们实现两台服务器的负载均衡 (实际情况中,这两个服务器上的数据要求同步一致,这里我们分别定义了打印server1和server2是为了进行辨认区别)。
a. 现在我们的情况是在windows下nginx是localhost侦听8080端口;
两台apache,一台是127.0.0.1:80(包含test.php页面但是打印server1),另一台是虚拟机的158.37.70.143:80(包含test.php页面但是打印server2)。
b. 因此重新配置nginx.conf为:
>首先在nginx的配置文件nginx.conf的http模块中添加,服务器集群server cluster(我们这里是两台)的定义:
upstream myCluster {
server 127.0.0.1:80 ;
server 158.37.70.143:80 ;
}
表示这个server cluster包含2台服务器
>然后在server模块中定义,负载均衡:
location ~ \.php$ {
proxy_pass http://myCluster ; #这里的名字和上面的cluster的名字相同
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这样的话,如果访问http://localhost:8080/test.php 页面的话,nginx目录下根本没有该文件,但是它会自动将其pass到myCluster定义的服务区机群中,分别由127.0.0.1:80;或者158.37.70.143:80;来做处理。
上面在定义upstream的时候每个server之后没有定义权重,表示两者均衡;如果希望某个更多响应的话例如:
upstream myCluster {
server 127.0.0.1:80 weight=5;
server 158.37.70.143:80 ;
}
这样表示5/6的几率访问第一个server,1/6访问第二个。另外还可以定义max_fails和fail_timeout等参数。
http://wiki.nginx.org/NginxHttpUpstreamModule
====================
综上,我们使用nginx的反向代理服务器reverse proxy server的功能,将其布置到多台apache server的前端。
nginx仅仅用来处理静态页面响应和动态请求的代理pass,后台的apache server作为app server来对前台pass过来的动态页面进行处理并返回给nginx。
通过以上的架构,我们可以实现nginx和多台apache构成的机群cluster的负载均衡。
两种均衡:
1)可以在nginx中定义访问不同的内容,代理到不同的后台server; 如上例子中的访问phpMyAdmin目录代理到第一台server上;访问test.php代理到第二台server上;
2)可以在nginx中定义访问同一页面,均衡 (当然如果服务器性能不同可以定义权重来均衡)地代理到不同的后台server上。 如上的例子访问test.php页面,会均衡地代理到server1或者server2上。
实际应用中,server1和server2上分别保留相同的app程序和数据,需要考虑两者的数据同步。
原文链接:http://blog.csdn.net/omohe/archive/2009/07/09/4335765.aspx
PHP工程师/上海市
所属职类:互联网软件开发工程师
需求人数:3人
发布时间:2009-08-18
职位描述
岗位职责:
1.网站搭建、代码编写及测试;
2. Web程序系统的策划、开发及测试;
3. 改进、增强现有产品的性能与功能;
4. 网站后台实时维护。
任职要求:
1.精通PHP语言、MySQL数据库,熟悉Linux网站开发环境
2.熟悉Linux操作系统,熟悉Apache,熟悉MySQL数据库的设计、管理、开发和优化;
3.精通CSS/HTML/XML等网页技术规范,熟悉JavaScript/AJAX等客户端脚本语言;
4.熟悉开发文档的编写,有良好文档编写能力和编程风格,熟悉版本控制SVN或CVS的使用;
5.有JAVA开发经验者优先;
6.具有Web2.0应用实例开发经验者优先;
7.有1年或以上相关工作经验;
8.有很强的学习能力和敬业精神,较好的沟通能力,有良好的团队合作精神。
有意者,请发送简历至william@fantha.com
本文所介绍的技术不是原创,而是从一个叫Robert Eisele的德国人那里学习来的。他写了一个PHP扩展openCV,只封装了两个函数,叫face_detect和face_count。 openCV是一个开源的用C/C++开发的计算机图形图像库,非常强大,研究资料很齐全。本文重点是介绍如何使用php来调用其中的局部的功能。人脸侦查技术只是openCV一个应用分支。
OpenCV安装之前必须依赖的包:(请先安装好)
pkgconfig
libpng
zlib
libjpeg
libtiff
python
1.安装
从源代码编译成一个动态的so文件。
1.1.安装 OpenCV (OpenCV 1.0.0)
下载地址:http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
#tar xvzf OpenCV-1.0.0.tar.gz
#cd opencv-1.0.0
#./configure
#make
#make install
#make check (检查是否安装全部正确)
提示: 不要指定安装路径,否则后面编译facedetect会找不到OpenCV的路径。
1.2 安装facedetect
下载地址http://www.xarg.org/download/facedetect-1.0.0.tar.gz
#tar xzvf facedetect-1.0.0.tar.gz
#cd facedetect-1.0.0
#phpize && ./configure && make && make install
编译完之后会提示facedetect.so 文件所在的位置。
最后确认在php.ini加入
extension=facedetect.so,重启apache.
2.函数使用
在phpinfo()里检查是否有facedetect这个模块。
从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下
3.应用
结合imagick可以将图片做一下应用。因为 face_detect只返回一个矩形参数,包含x,y坐标和w,h长宽参数。下面是我的一个应用demo
imagick 扩展需要安装 ImageMagick 和 imagick 扩展,请参考:
ImageMagick官网:http://www.imagemagick.org
imagick扩展下载: http://pecl.php.net/package/imagick
参考资料:
http://www.xarg.org/2008/07/face-detection-with-php/
http://www.opencv.org.cn/index.php/首页
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html
以上文章来源:http://blog.csdn.net/zhongmao/archive/2009/01/11/3753377.aspx
使用测试
安装测试了一下,如果越是高清的大图,效果越明显,感觉不错
一 安装
1 安装opencv
http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
下载opencv-1.1pre1.tar.gz(1.0版本没有安装成功)
#tar zxvf opencv-1.1pre1.tar.gz
# cd opencv-1.1.0/
# /.configure
#make
#make install
2 安装facedetect
#wget http://www.xarg.org/download/facedetect-1.0.0.tar.gz
#tar xzvf facedetect-1.0.0.tar.gz
#cd facedetect-1.0.0
#/usr/local/php/bin/phpize
#./configure –with-php-config=/usr/local/php/bin/php-config
#make
#make install
#vi /usr/local/php/etc/php.ini
// 增加extension=facedetect.so
3 重启web服务器,在phpinfo()里查看是否有facedetect这个模块
二 简单测试
从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下
//检查有多少个脸型
var_dump(face_count(’test.jpg’, ‘haarcascade_frontalface_alt.xml’));
//返回脸型在图片中的位置参数,多个则返回数组
$arr = face_detect(’test.jpg’, ‘haarcascade_frontalface_alt2.xml’);
print_r($arr);
三 测试代码
<?
if(empty($_POST)) {
?>
<form name=”form” id=”form” method=”POST” enctype=”multipart/form-data” action=””>
上传图片:<input type=”file” name=”pic” size=”20″><input type=”submit” name=”submit” value=”上传”>
</form>
<?
} else {
$img = $_FILES['pic']['tmp_name'];
$arr = face_detect($img, ‘haarcascade_frontalface_alt2.xml’);
if(is_array($arr1)) {
$all = array_merge($arr,$arr1);
} else {
$all = $arr;
}
$allowtype = 1;
switch($_FILES['pic']['type']){
case ‘image/pjpeg’: $fix_pic.= “.jpg”; break;
case ‘image/jpeg’: $fix_pic.= “.jpg”; break;
case ‘image/x-png’: $fix_pic.= “.png”; break;
case ‘image/png’: $fix_pic.= “.png”; break;
default: $allowtype = 0; break;
}
if($allowtype == 0) {
echo “文件格式错误:只运行jpg或png图片”;exit;
}
$tmp_name = time();
$src_pic = “/usr/website/nginx/face/haarcascades/upload/”.$tmp_name.$fix_pic;
move_uploaded_file($_FILES['pic']['tmp_name'], $src_pic);
$pic_src = $pic_dst = array();
if(is_array($all)){
foreach ($all as $k => $v){
$tmp_name_new = $tmp_name.”_”.$k;
$x = $v['x'];
$y = $v['y'];
$w = $v['w'];
$h = $v['h'];
$dst_pic = “/usr/website/nginx/face/haarcascades/upload/”.$tmp_name_new.$fix_pic;
// echo $src_pic.”<br>”;
// echo $dst_pic.”<br>”;
$cmd = “/usr/bin/convert -crop “.$w.”x”.$h.”+”.$x.”+”.$y.” “.$src_pic.” “.$dst_pic;
// echo $cmd.”<br>”;
echo `$cmd`;
$pic_src[] = “upload/”.$tmp_name.$fix_pic;
$pic_dst[] = “upload/”.$tmp_name_new.$fix_pic;
}
}
foreach($pic_src as $key => $value) {
echo “<img src=’”.$value.”‘> => <img src=’”.$pic_dst[$key].”‘><br>”;
}
}
?>
以上文章来源:http://www.sysbus.com/?p=124