分类目录归档:LINUX

CentOS Linux yum方式安装llmp

llmp是指用linux+lighttpd+mysql+php搭建的web环境。lighttpd是一个安全、快速、稳定、灵活的开源web服务器,官网:http://www.lighttpd.net/

一、安装epel、remi更新源
由于官方源没有lighttpd软件包,所以要用到epel源。能用yum安装就不编译了。
CentOS5.x 32bit:
http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm
CentOS5.x 64bit:
http://mirrors.ustc.edu.cn/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm
CentOS6.x 32bit:
http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-7.noarch.rpm
CentOS6.x 64bit:
http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm
为了使用较新版本的php、mysql安装remi源。
CentOS5.x:
http://rpms.famillecollet.com/enterprise/5/remi/i386/remi-release-5-8.el5.remi.noarch.rpm
CentOS6.x:
http://rpms.famillecollet.com/enterprise/6/remi/i386/remi-release-6-1.el6.remi.noarch.rpm
继续阅读CentOS Linux yum方式安装llmp

php添加XCache脚本加速

XCache是一个php的脚本加速器(opcode缓存器/优化器),功能和eAccelerator差不多。系统为CentOS6.3,环境为nginx+php-fpm。

官网:http://xcache.lighttpd.net/

1、下载安装XCache

cd /tmp
wget http://xcache.lighttpd.net/pub/Releases/3.0.0/xcache-3.0.0.tar.gz
tar -zxvf xcache-3.0.0.tar.gz
cd xcache-3.0.0
/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config --enable-xcache --enable-xcache-optimizer
make
make install

安装完后,会自动在/usr/lib/php/modules/目录内添加xcache.so模块。

选项说明:
–enable-xcache:包含XCache支持。
–enable-xcache-optimizer:启用操作码优化。

注:XCache3.0.0开始使用 extension= 来加载XCache。不再支持采用 zend_extension= 方式加载。
继续阅读php添加XCache脚本加速

nginx下discuz! x2.5伪静态设置

管理员登录到后台,选择“全局-SEO设置-URL静态化”,可以看到有“页面 标记 格式 可用”几个标题,将可用下面的方框里都选中,Rewrite兼容性选否,点击提交。
找到nginx配置文件中配置这个bbs域名的server段,在location /内添加伪静态规则。
比如原来是:

...
server {
    listen       80;
    server_name  www.aaa.com;
    access_log  /var/log/nginx/aaa.com.log  main;
    location / {
        root   /home/webroot;
        index  index.html index.htm index.php;
    }
}
...


修改后为:

...
server {
    listen       80;
    server_name  www.aaa.com;
    access_log  /var/log/nginx/aaa.com.log  main;
    location / {
        root   /home/webroot;
        index  index.html index.htm index.php;
        rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
        rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
        rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
        rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
        rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
        rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
        rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
        rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
        rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
        if (!-e $request_filename) {
	        return 404;
        }
    }
}
...

phpmyadmin提示Cannot start session without errors错误

lnmp环境,安装phpmyadmin打开时提示:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

网上找了下,说是session存放目录的问题。

打开php.ini,查找session.save_path,找到:

session.save_path = "/var/lib/php/session"

说明session目录是定义在/var/lib/php/session

经查看发现在/var/lib/php目录下没有session目录,遂建立:

cd /var/lib/php
mkdir session
chown nginx:nginx session
chmod 770 session

设置权限后,phpmyadmin就能打开了。

nginx设置虚拟目录

nginx建立虚拟目录的配置文件放在/etc/nginx/conf.d目录下。系统用的是CentOS6.3。

首先在nginx.conf中查找有没有:

include /etc/nginx/conf.d/*.conf

这一句,没有的话要加在http块内。

添加虚拟目录
比如要放两个虚拟目录:
blog.aaa.com在/home/blog.aaa目录
bbs.bbb.com在/home/bbs.bbb目录

我们把这两个虚拟目录写在一个配置文件里。

cd /etc/nginx/conf.d
vim virtualhost.conf

添加: 继续阅读nginx设置虚拟目录

小内存VPS lnmp配置优化

环境为一台256MB内存vps,系统为CentOS6.3,使用的程序版本:
nginx 1.3.8
php 5.3.18
mysql 5.5.28
安装lnmp可参考:http://www.live-in.org/archives/1257.html

一、nginx配置
编辑配置文件:

vim /etc/nginx/nginx.conf

1、
找到:

worker_processes

改为:

worker_processes 2;

nginx运行的进程数,一般设置成和CPU的核数相同。

2、
找到:

worker_rlimit_nofile

改为: 继续阅读小内存VPS lnmp配置优化

web压力测试工具siege

siege是一个开源的压力测试工具,官网:http://www.joedog.org/

1、安装siege

yum install gcc gcc-c++ make -y
cd /tmp
wget http://www.joedog.org/pub/siege/siege-2.72.tar.gz
tar -zxvf siege-2.72.tar.gz
cd siege-2.72
./configure
make
make install

2、siege使用方法形如

siege -c 20 -r 50 http://www.example.com/

-c:并发的用户数量
-r:运行测试的次数

结果说明:

Transactions:		      完成的请求数
Availability:		      成功率
Elapsed time:		      总用时
Data transferred:	      传输数据量
Response time:		      响应时间,显示网络连接的速度
Transaction rate:	      平均每秒完成请求数(重要)
Throughput:		      平均每秒传送数据数
Concurrency:		      最高并发数
Successful transactions:      成功处理次数
Failed transactions:	      失败处理次数
Longest transaction:	      最长处理请求时间
Shortest transaction:	      最短处理请求时间

参考资料:
http://www.ha97.com/4663.html

web压力测试工具ab

ab是apache自带的一款压力测试工具,安装完apache后就有了,一般在/usr/bin目录下。系统为CentOS。

1、安装apache

yum install httpd

2、ab使用方法形如

ab -c 20 -n 1000 http://www.example.com/

-c:并发数
-n:总请求数

===我蛋疼的看了源代码,这段可以跳过===
ab是如何分配并发和请求数的呢?
在test函数中,先给连接数和请求数分配内存,组http报文头、组http请求报文默认使用GET方法(最大2048个字节)
进入for循环
for (i = 0; i < concurrency; i++) {
        con[i].socknum = i;
        start_connect(&con[i]);
    }
start_connect函数里,concurrency有几个并发,就创建几个socket连接
apr_socket_create 继续阅读web压力测试工具ab 

Linux nmap命令

nmap是Linux下常用的网络工具之一,主要作用是扫描主机端口、探测操作系统和版本。这里系统是CentOS6.3。

安装非常简单:

yum install nmap

检查本机打开的端口:

nmap -v localhost

普通用户扫描主机使用如:

nmap -A -T4 scanme.nmap.org

root用户扫描主机使用如:

nmap -sT -Pn scanme.nmap.org

注:不知道为什么root用户不能使用-A选项,会报错

Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.79 seconds

常用选项:
-v:表示显示冗余(verbosity)信息,在扫描过程中显示扫描的细节
-A:激烈扫描模式,包括打开操作系统探测、版本探测、脚本扫描、路径跟踪
-T:设置时间模板,总有6个级别(0-5),级别越高,扫描速度越快
-sT:TCP扫描
-sU:UDP扫描
-Pn:将所有指定的主机视作开启的,跳过主机发现的过程

更多选项请参考nmap中文参考手册:http://nmap.org/man/zh/index.html

CentOS Linux安装aria2多线程下载工具

aria2是一个Linux下的多线程下载工具,支持HTTP/HTTPS、FTP、BitTorrent、Metalink协议。平时在linux上下载http上的东西常用如wget、curl命令,但是他们都是单线程下载的。这里系统是CentOS6.3 32bit。

aria2官方项目页面:http://aria2.sourceforge.net/

安装aria2:

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ivh rpmforge-release-0.5.2-2.el6.rf.i686.rpm
yum -y install aria2

下载举例:
1)http、ftp下载

aria2c -c -s 5 http://www.example.com/file.tar.gz

-c:断点续传
-s:使用线程数

2)bt下载

aria2c /tmp/CentOS-6.3-i386-bin-DVD1to2.torrent