CentOS 5.4 X86_64
安装GD
yum install -y libpng freetype libjpeg libpng-devel freetype-devel libjpeg-devel libmcrypt-devel libxml2 zlib curl SDL_ttf SDL_ttf-devel gd-devel
或者
wget
LIBICONV
./configure --prefix=/usr/local/libiconv --enable-static=yes
GD
./configure --prefix=/usr/local/gd --with-png=/usr --with-freetype=/usr --with-jpeg=/usr
make ; make install
安装Mysql
5.1-old
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.25-rc.tar.gz/from/http://mysql.byungsoo.net/
MYSQL=/usr/local/mysql
./configure --prefix=$MYSQL --enable-assembler --with-charset=gbk \
--with-extra-charsets=gb2312,latin1,utf8 --enable-largefile --with-big-tables \
--without-debug --with-max-indexes=64 --with-zlib-dir=/usr \
--with-mysqld-ldflags=-all-static --without-ndbcluster \
--with-plugins=innobase
make & make install
5.5 later
安装 PHP
下载:
tar xzvf php-5.4.16.tar.gz
- ./configure --prefix=/usr/local/php54 --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib\
- --disable-pdo --with-curl --disable-debug --disable-rpath\
- --enable-inline-optimization --with-bz2 --with-zlib=/usr --enable-sockets \
- --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex\
- --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \
- --with-jpeg --with-curl=/usr --enable-gd-native-ttf \
- --with-iconv-dir=/usr --enable-mbstring=all --with-gd=/usr \
- --with-png-dir=/usr --with-jpeg-dir=/usr --with-freetype-dir=/usr --with-openssl
-
make
make install
php5.4.16 安装出现 error: ‘struct gdIOCtx’ has no member named ‘data’
//./configure \
//--prefix=/usr/local/php-fcgi \
//--enable-fastcgi \
//--enable-discard-path \
//--enable-force-cgi-redirect \
//--enable-mbstring=all \
//--enable-memcache \
//--with-gd=/usr/local/gd \
//--with-zlib \
//--with-png \
//--with-jpeg \
//--with-freetype \
//--with-mysql=/usr/local/mysql \
//--with-dom
//make
//make install
cp -f php.ini-production /opt/php/lib/php/php.ini
安装 ZendGuard
可以实现对PHP应用的进行加密保护和对PHP应用的产品进行商业许可证管理,还可以为许多软件生产商、IT服务提供商提供完善的加密和安全的产品发布系统。
从PHP5.3开始如果要支持ZendGuard加密的PHP代码,必须安装Zend Guard Loader,老的zend optimizer将不被支持。Zend Optimizer(以下简称ZO)用优化代码的方法来提高php的执行速度。实现的原理是对那些在被最终执行之前由运行(Run-Time Compiler)产生的代码进行优化。
Zend Guard Loader and Zend Optimizer are free runtime applications that enable PHP to run scripts encoded by Zend Guard.
1.从Zend.com下载最新的Linux操作系统系下的Zend Guard Loader:本文用的是x86-64位的,下载的文件名称类似为:ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
2.上传至Linux服务器并解压缩,注意阅读生成目录下的README文件。全文如下(添加必要的注释).
3.拷贝库文件到指定目录 cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /opt/php/lib/
在php.ini,添加内容如下:
vim /opt/php/lib/php.ini
最后加上:
zend_extension=/opt/php/lib/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
注意路径一定要写上,刚开始没写路径,老是加载不上ZendGuardLoader.so
3.重启php解释程序,php-fpm或者spawn-fcgi或者其它的解释程序
4.(内容为),看到如下内容及证明安装成功了。

注意:with Zend Guard Loader v3.3出现表示安装成功,如果没有则安装失败。
三款免费的PHP加速器:APC、eAccelerator、XCache
PHP scripts 的缓存,对于提高 PHP 程序执行速度很有帮助,推荐使用APC。
安装 Memcache moudle
用于缓存 sql 查询,对于降低数据库压力,提升查询速度有很大好处。
下载:
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6
/usr/local/php-fcgi/bin/phpize
./configure --with-php-config=/usr/local/php-fcgi/bin/php-config
make
make install
安装 Memcached
wget -P/usr/local/src
wget -P/usr/local/src
cd /usr/local/src
tar xzf memcached-1.4.5.tar.gz
tar xvzf libevent-1.4.8-stable.tar.gz
cd libevent-1.4.8-stable
./configure --prefix=/opt/libevent
make
make install
cd memcached-repcached
./configure --prefix=/opt/memcached --build=i686-pc-linux-gnu --with-libevent=/opt/libevent --enable-64bit
make
make install
=== 设定lib path ===
在/etc/ld.so.conf.d 目录下新增一个文件 libevent.conf ,将开始安装在/opt/libevent 中的libevent 库加入,文件内容如下:
/opt/libevent/lib
或在/etc/profile中加入
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/libevent/lib
退出后重新登录系统生效.
=== 启动 ===
下面,我们来启动一个Memcached的服务器端:
#bash /opt/memcached/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid
* -d 以守护程序(daemon)方式运行 memcached;
* -U UDP 协议的端口,默认11211,如果设置为0,代表UDP 协议关闭
* -m 设置 memcached 可以使用的内存大小,单位为 M;
* -l 设置监听的 IP 地址,如果是本机的话,通常可以不设置此参数;
* -p 设置TCP 协议监听的端口,默认为 11211,所以也可以不设置此参数;
* -P 将memcached 的进程pid 放入一个文件中
* -s 设置Linux 下socks 文件路径
* -c 配置最大数量的连接数,默认为1024
* -M 当内存耗尽时,向客户端返回错误信息,而不是从cache 中移除旧的Item 来插入新的Item
* -u 指定用户,默认不能用root用户启动,如果当前用户是root,需要用这个参数来指定;
* -t number of threads to use, default 4
安装 Linghttpd's spawn-fcgi
用 Lighttpd 的 spawn-fcgi 来管理 PHP FastCGI 进程。
下载 Lighttpd:
yum -y install pcre-devel
(debian: apt-get -y install libpcre3-dev)
tar zxvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure
make;
cp -a src/spawn-fcgi /usr/local/php-fcgi/bin/
完整的启动脚本以及参数配置文件示例:
spawn-fcgi.zip
如果spawn-fcgi不能在你的系统上正常系统,可以考虑使用使另一个CGI程序PHP-FPM,它的执行效率同样非常好,甚至有些时候优于spawn-fcgi,参考:
修改文件上传限制
1.实现修改php.ini生效,在域名目录下,上传一个.htaccess这样的文件,文件规则附上如下:
AddHandler phpini-cgi .php .htm
Action phpini-cgi /cgi-bin/php5-custom-ini.cgi
2.在cgi-bin目录下,上传一个php.ini和php5-custom-ini.cgi这两个文件,其中php-custom-ini.cgi文件中附下如下:
#!/bin/sh
export PHP_FCGI_CHILDREN=3 exec /usr/local/php-fcgi/bin/ php-cgi -c /usr/local/php-fcgi/bin/ php.ini
3.修改php5-custom-ini.cgi的权限为755,这样php.ini的设置就会生效.
4.修改php.ini中的选项,打开php.ini,找到upload_max_filesize=2M,我们把它改成upload_max_filesize = 8M,保存后,就样就可以成功的改成8M了.
安装 Nginx
下载:
tar zxvf nginx-1.0.2.tar.gz
cd nginx-1.0.2
./configure --user=nobody --group=nobody \
--with-http_ssl_module --with-http_gzip_static_module \
--with-http_dav_module --with-http_realip_module \
--with-http_stub_status_module --prefix=/opt/httpd
//--http-client-body-temp-path=/var/tmp/nginx/client \
//--http-proxy-temp-path=/var/tmp/nginx/proxy \
//--http-fastcgi-temp-path=/var/tmp/nginx/fcgi
make
make install
配置 PHP
vi /usr/local/php-fcgi/etc/php.ini
# 最大执行时间
max_execution_time = 5
# 打开全局变量兼容老程序
register_globals = On
# 默认编码
default_charset = "gbk"
# 扩展模块的目录
extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20020429"
extension = "soap.so"
one.soap.wsdl_cache_ttl=86400
# 关闭 mysql 持久连接。高访问量下会把数据库可用连接用完。
mysql.allow_persistent = Off
# 降低连接超时时间
mysql.connect_timeout = 10
# session 文件存储目录,这里为两级目录,需要手动创建。
session.save_path = "2;/tmpfs/phpsession"
# session 过期时间设为一小时。
session.gc_maxlifetime = 3600
# 关闭
session.bug_compat_42 = 0
session.bug_compat_warn = 0
# 开启 memcache
[memcache]
extension=memcache.so
[mbstring]
;extension=php_mbstring.so
改成
extension=php_mbstring.so
PHP配置:屏蔽了一些虽然正规但会有偶然突然显示出错的代码 error_reporting = E_ALL改为error_reporting = E_ALL & ~E_NOTICE
修改display_errors 值为 off
配置 Nginx
建立相应目录
mkdir /var/log/nginx
cd /usr/local/nginx
mv logs conf/vhosts
cd conf
vi nginx.conf
- # 运行 Nginx 的用户
- user nobody nobody;
- # Nginx 的进程数
- worker_processes 8;
-
- # 错误日志
- error_log /var/log/nginx/error.log;
-
- # pid 文件
- pid /var/run/nginx.pid;
-
- events {
- # 使用 epoll(For Linux Kernel 2.6+) 提升 Nginx 性能。
- use epoll;
- # 最大连接数
- worker_connections 4096;
- }
-
-
- http {
- # 包含 mime types 的配置文件
- include conf/mime.types;
- # 默认类型
- default_type application/octet-stream;
-
- # 定义 temp 的路径
- client_body_temp_path /tmpfs/nginx/client_body_temp;
- proxy_temp_path /tmpfs/nginx/proxy_temp;
- fastcgi_temp_path /tmpfs/nginx/fastcgi_temp;
-
- # 如果 server_name 定义的域名过多,需要增大这个值
- server_names_hash_bucket_size 128;
-
- # 定义主访问日志格式,因开启了 gzip,加入了 $gzip_ratio
- log_format main '$remote_addr - $remote_user [$time_local] $request '
- '"$status" $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$gzip_ratio"';
-
- # 默认的访问日志存放文件
- access_log /var/log/nginx/access.log main;
-
- # Linux Kernel 2.4+ 可通过调用内核级 sendfile() 来提高性能
- sendfile on;
-
- # FreeBSD 或基于 TCP_CORK 的 Linux 系统可使用
- tcp_nopush on;
-
- # 只在 keep-alive 连接状态中使用
- tcp_nodelay on;
-
- # 设置保持连接超时时间 和 header 超时时间(单位:秒)
- keepalive_timeout 60 15;
-
- # 开启 gzip
- gzip on;
- # 压缩级别 1-9,9 为最高压缩级别
- gzip_comp_level 9;
- # 回送给客户端最小的 gzip 压缩大小
- gzip_min_length 1100;
- # 设置 gzip 缓存的大小,默认是 4-8k 之间
- gzip_buffers 4 8k;
- # gzip http 版本
- gzip_http_version 1.1;
- # 需要使用 gzip 压缩的文件类型
- gzip_types text/javascript text/plain application/x-javascript text/css application/xml;
-
client_max_body_size 50m; #客户端上传文件限制
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 6000;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
-
- # 定义默认主机
- server {
- # 监听端口
- listen 80 default;
- # 匹配所有域名
-
server_name _ *;
location / { -
# 根目录路径
root /home/www;
# 默认首页
index index.php index.htm;
}
# 执行 php 程序文件的设置
location ~ \.php$ {
root /home/www;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
# 对于以下文件不记录访问日志
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
}
}
-
- # 包含其它虚拟主机的配置
- include conf/vhosts/*.conf;
- }
vi fcgi.conf
- fastcgi_pass 127.0.0.1:10080;
-
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx;
-
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
-
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param REQUEST_URI $request_uri;
- fastcgi_param DOCUMENT_URI $document_uri;
- fastcgi_param DOCUMENT_ROOT $document_root;
- fastcgi_param SERVER_PROTOCOL $server_protocol;
-
- fastcgi_param REMOTE_ADDR $remote_addr;
- fastcgi_param REMOTE_PORT $remote_port;
- fastcgi_param SERVER_ADDR $server_addr;
- fastcgi_param SERVER_PORT $server_port;
- fastcgi_param SERVER_NAME $server_name;
-
- # PHP only, required if PHP was built with --enable-force-cgi-redirect
- fastcgi_param REDIRECT_STATUS 200;
再来配置 Discuz! 论坛和 SupeSite/X-Space 的虚拟主机
vi vhosts/main.conf
- server {
- listen 80;
- # 分论坛可使用子域名
- server_name bbs.domain.com *.bbs.domain.com;
- index index.php;
- root /home/www/bbs;
- # 和 Apache Rewrite 规则很相似
- rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1;
- rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2;
- rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2;
- rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?action=viewpro&$1=$2;
- rewrite ^/tag-(.+)\.html$ /tag.php?name=$1;
- location ~ .*\.php?$ {
- include conf/fcgi.conf;
- }
- location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
- access_log off;
- }
- }
-
- server {
- listen 80;
- server_name blog.domain.com;
- index index.php;
- root /home/www/blog;
- rewrite ^([0-9]+)/spacelist(.*)$ index.php?$1/action_spacelist$2;
- rewrite ^([0-9]+)/viewspace_(.+)$ index.php?$1/action_viewspace_itemid_$2;
- rewrite ^([0-9]+)/viewbbs_(.+)$ index.php?$1/action_viewbbs_tid_$2;
- rewrite ^([0-9]+)/(.*)$ index.php?$1/$2;
- rewrite ^([0-9]+)$ index.php?$1;
- rewrite ^action_(.+)$ index.php?action_$1;
- rewrite ^category_(.+)$ index.php?action_category_catid_$1;
- rewrite ^itemlist_(.+)$ index.php?action_itemlist_catid_$1;
- rewrite ^viewnews_(.+)$ index.php?action_viewnews_itemid_$1;
- rewrite ^viewthread_(.+)$ index.php?action_viewthread_tid_$1;
- rewrite ^index([\.a-zA-Z0-9]*)$ index.php;
- rewrite ^html/([0-9]+)/viewnews_itemid_([0-9]+)\.html$ index.php?action_viewnews_itemid_$2;
-
- rewrite ^/([0-9]+)/spacelist(.+)$ /index.php?uid/$1/action/spacelist/type$2;
- rewrite ^/([0-9]+)/viewspace(.+)$ /index.php?uid/$1/action/viewspace/itemid$2;
- rewrite ^/([0-9]+)/viewbbs(.+)$ /index.php?uid/$1/action/viewbbs/tid$2;
- rewrite ^/([0-9]+)/(.*)$ /index.php?uid/$1/$2;
- rewrite ^/([0-9]+)$ /index.php?uid/$1;
-
- rewrite ^/action(.+)$ /index.php?action$1;
- rewrite ^/category(.+)$ /index.php?action/category/catid$1;
- rewrite ^/viewnews(.+)$ /index.php?action/viewnews/itemid$1;
- rewrite ^/viewthread(.+)$ /index.php?action/viewthread/tid$1;
- rewrite ^/mygroup(.+)$ /index.php?action/mygroup/gid$1;
- # 归档目录的默认首页设置
- location /archiver/ {
- index index.html;
- }
- location ~ .*\.php?$ {
- include conf/fcgi.conf;
- }
- location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
- access_log off;
- }
- }
用 tmpfs 提升性能
mkdir /tmpfs
在 /etc/fstab 中加入
tmpfs /tmpfs tmpfs size=256m,mode=1777 0 0
mount -a
创建相关目录
vi /usr/local/sbin/mkdir.sh
mkdir /tmpfs/nginx
chown -R nobody:nobody /tmpfs/nginx
chmod -R 1777 /tmpfs/nginx
mkdir /tmpfs/eaccelerator
chown -R nobody:nobody /tmpfs/eaccelerator
chmod -R 1777 /tmpfs/eaccelerator
I="0 1 2 3 4 5 6 7 8 9 a b c d e f"
for acm in $I;
do
for x in $I;
do
mkdir -p /tmpfs/phpsession/$acm/$x;
done;
done
chown -R nobody:nobody /tmpfs/phpsession
chmod -R 1777 /tmpfs/phpsession
chmod +x /usr/local/sbin/mkdir.sh
mkdir.sh
启动 PHP 和 Nginx
/usr/local/php-fcgi/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 32 -u nobody -g nobody -f /usr/local/php-fcgi/bin/php-cgi
监听在 127.0.0.1 的 10080 端口并开启 32 个进程,使用和 Nginx 一样的 nobody 用户。(PHP4 的执行程序是 php)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启 PHP 进程可以先 killall php 再启动。
重启 Nginx
kill -HUP `cat /var/run/nginx.pid`
#测试PHP连接MYSQL
mysql.php:
mysql_connect("localhost", "username", "password") or die(mysql_error());
echo "Connected to MySQL
";
mysql_select_db("testdb") or die(mysql_error());
echo "Connected to Database";
echo "
";
phpinfo();
?>
清除超过一小时没有被访问到的 eAccelerator 缓存文件和创建时间超过一小时的 php session 文件,防止占满空间。
vi /etc/crontab
0 * * * * root find /tmpfs/eaccelerator -type f -amin +60 -exec rm {} \;
0 * * * * root find /tmpfs/phpsession -type f -cmin +60 -exec rm {} \;
增加开机自启动脚本
nginx.txt
touch /etc/init.d/nginx
#将nginx.txt的文件内容拷贝到 /etc/init.d/nginx中,保存。
chkconfig nginx on
touch /ec/sysconfig/nginx
##拷贝以下内容到 /etc/sysconfig/nginx 文件中保存
# Configuration file for the nginx service
# set this to the location of the nginx configuration file
NGINX_CONF_FILE=/opt/httpd/conf/nginx.conf
##拷贝以上内容到 /etc/sysconfig/nginx 文件中保存
service nginx start/stop
vi /etc/rc.local
/usr/local/sbin/mkdir.sh
/usr/local/php-fcgi/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 32 -u nobody -g nobody -f /usr/local/php-fcgi/bin/php-cgi
ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL'
=> 2
即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以需要修改
nginx.conf文件。
-
server
-
{
-
listen 80;
-
server_name
-
index index.html index.htm index.php index.shtml;
-
root /data2/www/
-
-
location / {
-
if (!-e $request_filename){
-
rewrite ^(.*)$ /index.php?s=/$1 last; #rewrite模式
-
rewrite ^(.*)$ /index.php/$1 last; #pathinfo模式 任选其一
-
}
-
}
-
-
-
location ~ \.php {
-
-
fastcgi_pass 127.0.0.1:9000;
-
fastcgi_split_path_info ^(.+\.php)(.*)$;
-
fastcgi_param PATH_INFO $fastcgi_path_info;
-
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
include fastcgi_params;
-
fastcgi_connect_timeout 300;
-
fastcgi_send_timeout 300;
-
fastcgi_read_timeout 300;
-
}
-
-
- }
重启Nginx以后, 这样的URL都可以正确访问了。
还有一个地方需要注意的是,Nginx配置文件里 if 和后面的括号之间要有一个空格,不然会报nginx: [emerg] unknown directive "if"错误。
如果是多个项目,布署项目时要把项目布署到目录里,如后台的项目放到Admin目录里,那么在nginx的rewrite里再写一条
-
location /admin/ {
root /usr/local/apache2/htdocs/miaohr_new/miaohr_new/Trunk/;
if (!-e $request_filename) {
rewrite ^/admin/(.*)$ /admin/index.php?s=$1 last;
rewrite ^/admin/(.*)$ /admin/index.php/$1 last;
break;
}
} -
其它参考:
APPNODE 同时安装控制中心和受控端
INSTALL_AGENT=1 bash -c "$(curl -sS )"
Apache kafka 工作原理介绍
https://www.ibm.com/developerworks/cn/opensource/os-cn-kafka/index.html
bash -c "$(curl )"