linux top us,sy,ni,id,wa,hi,si,st

SUMMARY Area Fields
The summary area fields describing CPU statistics are abbreviated.
They provide information about times spent in:
us = user mode
sy = system mode
ni = low priority user mode (nice)
id = idle task
wa = I/O waiting
hi = servicing IRQs
si = servicing soft IRQs
st = steal (time given to other DomU instances)



us: is meaning of "user CPU time"
sy: is meaning of "system CPU time"
ni: is meaning of" nice CPU time"
id: is meaning of "idle"
wa: is meaning of "iowait"
hi:is meaning of "hardware irq"
si : is meaning of "software irq"
st : is meaning of "steal time"

中文翻译为:

us 用户空间占用CPU百分比
sy 内核空间占用CPU百分比
ni 用户进程空间内改变过优先级的进程占用CPU百分比
id 空闲CPU百分比
wa 等待输入输出的CPU时间百分比
hi 硬件中断
si 软件中断
st: 实时 

nginx反向代理访问带referer的后端

防外链大都是通过检查请求中的http referer来实现的。如果通过反向代理来动态指定http referer是不是可以解决问题。

用nginx搭一个反向代理


location /get/
{
set $hostx “”;
set $addrs “”;
if ( $uri ~ “^/get/http./+([^/]+)/(.+)$”) {
set $hostx $1;
set $addrs $2;
}
resolver 127.0.0.1;
proxy_pass http://$hostx/$addrs;
proxy_set_header referer “http://$hostx“;


proxy_set_header referer 这项就是指定referer的!

 

 

Ubuntu的Windows 7桌面效果

cd ~
wget http://web.lib.sun.ac.za/ubuntu/files/help/theme/gnome/win7-setup.sh
sudo chmod +x win7-setup.sh
./win7-setup.sh


操作之前请先备份,由于不种的环境可能有一些不可预料的错误。

 

CPU资源的shell脚本

使用死循环消耗CPU资源,如果服务器是有多颗CPU,可以选择消耗多少颗CPU的资源:


#! /bin/sh
# filename killcpu.sh
for i in `seq $1`
do
echo -ne "
i=0;
while true
do
i=i+1;
done" | /bin/sh &
pid_array[$i]=$! ;
done
for i in "${pid_array[@]}"; do
echo 'kill ' $i ';';
done 


使用方法很简单,参数3表示消耗3颗CPU的资源,运行后,会有一堆 kill 命令,方便 kill 进程:
[root@test02 ~]# ./killcpu.sh 3
kill 30104 ;
kill 30106 ;
kill 30108 ;
[root@test02 ~]# top
top - 15:27:31 up 264 days, 23:39, 4 users, load average: 0.86, 0.25, 0.19
Tasks: 185 total, 5 running, 180 sleeping, 0 stopped, 0 zombie
Cpu0 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu1 : 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu2 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu3 : 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 8165004k total, 8095880k used, 69124k free, 53672k buffers
Swap: 2031608k total, 103548k used, 1928060k free, 6801364k cached

 

apache suexec和suphp的安装配置

使用suphp来执行php

1、yum安装环境

apache php 都是用Yum安装

# yum install httpd php php-cli

保证phpphp-cgi,因为suphp需要php的执行模式为cgi/fastcgi

[vnp.unscnb.com:/root]#php -v

PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)

Copyright (c) 1997-2008 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

[vnp.unscnb.com:/root]#php-cgi -v

PHP 5.2.6 (cgi-fcgi) (built: May  5 2008 10:29:53)

Copyright (c) 1997-2008 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Suphp安装

# wgethttp://www.suphp.org/download/suphp-0.7.1.tar.gz

#tar zvxf suphp-0.7.1.tar.gz

#cd suphp-0.7.1

Suphp的编译参数有2种 主要是setid-mode的区别

1、测试模式,没有任何安全所言

#./configure --prefix=/usr/local/suphp \

--sysconfdir=/usr/local/suphp/etc \

--with-apache-user=apache \

--with-setid-mode=owner \

--with-apxs=/usr/sbin/apxs \

--with-apr=/usr/bin/apr-1-config

2、生产模式使用下面的配置

#./configure --prefix=/usr/local/suphp \

--sysconfdir=/usr/local/suphp/etc \

--with-apache-user=apache \

--with-setid-mode=paranoid
\

--with-apxs=/usr/sbin/apxs \

--with-apr=/usr/bin/apr-1-config

具体2者的区别 将在后面apache配置那里说明

# make

# make install

# mkdir/usr/local/suphp/etc

#cp doc/suphp.conf-example /usr/local/suphp/etc/suphp.conf

编辑suphp.conf

# vi/usr/local/suphp/etc/suphp.conf

###########----------------------------------

[global]

;日志文件的产生路径

logfile=/var/log/httpd/suphp.log

;日志级别"info", "warn", "error", "none".

loglevel=info

;User Apache is running as

webserver_user=apache

;Path all scripts have to be in

docroot=/

;Path to chroot() to before executing script

;chroot=/mychroot

;安全选项,根据自己需要开启

;allow_file_group_writeable=false

allow_file_group_writeable=true

allow_file_others_writeable=false

;allow_directory_group_writeable=false

allow_directory_group_writeable=true

allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT

check_vhost_docroot=true

;check_vhost_docroot=false

;Send minor error messages to browser

errors_to_browser=false

;PATH environment variable

env_path=/bin:/usr/bin

;Umask to set, specify in octal notation

umask=0077

;最小uid和最下gid是指web运行的用户和组必须大于等于这个数,否则由于安全员应无法运行,这个设置根据自己来设置,一般uid=500 gid=100

min_uid=1000

min_gid=1000

[handlers]

;必须执行cgi模式的php,这个很重要

;x-httpd-php="php:/usr/bin/php"

x-httpd-php="php:/usr/bin/php-cgi"

;Handler for CGI-scripts

x-suphp-cgi="execute:!self"

##################---------------------------------------

整合apache

注销所有原先phpapache的配置选项,包括模块

# vi /etc/httpd/conf.d/suphp.conf

####--------------

LoadModule suphp_module modules/mod_suphp.so

NameVirtualHost *:80

<VirtualHost *:80>  

    ServerName 127.0.0.1

    DocumentRoot /var/www/svnadmin

DirectoryIndex index.php

 


#开启suphp引擎

suPHP_Engine on  

#指定/var/www/svnadmin的运行用户和组

suPHP_UserGroup webtest1 suphp

#指定执行的扩展名

    AddHandler x-httpd-php .php .php3 .php4 .php5  

suPHP_AddHandler x-httpd-php

#指定php的配置文件

    suPHP_ConfigPath /etc/php.ini

</VirtualHost>

###########-------------

需要注意的事项

1、假设apache设置的DocumentRoot "/var/www/html",那么/var/www的目录的所有者和组必须是root:root权限一般设置755

2、所有的虚拟主机web目录,必须放置在/var/www下,不能放置在apache设置的DocumentRoot目录下

3、假设我有一个/webserver/www/test的虚拟主机,此时/webserver/www的宿主和组必须是root:root

测试是否成功

编写index.php

<?


Phpinfo();

?>

打开web浏览发现


Server API

CGI/FastCGI


就表示成功

2、源码安装

suphp比suexec(就是原来dv3.0升php5的方法)要快一点;比suphp更快的还有suphp_mod_php;再快一些的是mpm-peruser,不过安装配置的麻烦程度也随之递增。

相比而言,suPHP速度还算可以接受(对于负载不是很大的站),配置方便,不用修改每个virtualhost的参数(就是$HOME/conf/vhost.conf),直接改apache的总conf就ok了,当然也比上面fastcgi方式下用event触发脚本来实现更加简洁。

ApacheSuexec

1yum安装

#cd /etc/yum.repos.d/
#wgethttp://centos.karan.org/kbsingh-CentOS-Extras.repo

... and setgpgcheckto0andenabledto1in the[kbs-CentOS-Testing]section:

[...]

[kbs-CentOS-Testing]

name=CentOS.Karan.Org-EL$releasever - Testing

gpgcheck=0

gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt

enabled=1

baseurl=http://centos.karan.org/el$releasever/extras/testing/$basearch/RPMS/

#yum install httpd mod_fcgid php-cli

整合apache

注销所有原先phpapache的配置选项,包括模块

php.ini的最后加上下面的语句

cgi.fix_pathinfo = 1

#groupadd web1
#useradd -s /bin/false -d /var/www/web1 -m -g web1 web1
#chmod 755 /var/www/web1

#mkdir -p /var/www/web1/web
#chown web1:web1 /var/www/web1/web

We will run PHP using suExec; suExec's document root is /var/www, as the following command shows:

# /usr/sbin/suexec -V
-D AP_DOC_ROOT="/var/www"
-D AP_GID_MIN=100
-D AP_HTTPD_USER="apache"
-D AP_LOG_EXEC="/var/log/httpd/suexec.log"
-D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
-D AP_UID_MIN=500
-D AP_USERDIR_SUFFIX="public_html"

Therefore we cannot call the PHP binary (/usr/bin/php-cgi) directly because it is located outside suExec's document root. As suExec does not allow symlinks, the only way to solve the problem is to create a wrapper script for each web site in a subdirectory of /var/www; the wrapper script will then call the PHP binary /usr/bin/php-cgi. The wrapper script must be owned by the user and group of each web site, therefore we need one wrapper script for each web site. I'm going to create the wrapper scripts in subdirectories of /var/www/php-fcgi-scripts, e.g. /var/www/php-fcgi-scripts/web1

#mkdir -p /var/www/php-fcgi-scripts/web1

#vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter


#!/bin/sh

PHPRC=/etc/

export PHPRC

export PHP_FCGI_MAX_REQUESTS=5000

export PHP_FCGI_CHILDREN=8

exec /usr/bin/php-cgi


#chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter
#chown -R web1:web1 /var/www/php-fcgi-scripts/web1

#vi /etc/httpd/conf.d/fcgid.conf

#######################--------------------------------

# This is the Apache server configuration file for providing FastCGI support

# through mod_fcgid

#

# Documentation is available at http://fastcgi.coremail.cn/doc.htm

LoadModule fcgid_module modules/mod_fcgid.so

# Use FastCGI to process .fcg .fcgi & .fpl scripts

# Don't do this if mod_fastcgi is present, as it will try to do the same thing

#<IfModule !mod_fastcgi.c>

#    AddHandler fcgid-script fcg fcgi fpl

#</IfModule>

# Sane place to put sockets and shared memory file

SocketPath run/mod_fcgid

SharememPath run/mod_fcgid/fcgid_shm

IPCConnectTimeout 10

IPCCommTimeout 20

OutputBufferSize 0

MaxRequestsPerProcess 500

#AddHandler fcgid-script .fcgi .php

NameVirtualHost *:80

<VirtualHost *:80>

  ServerName fcgi.test.com

  DocumentRoot /var/www/fcgi

    SuexecUserGroup webcgi fcgi

    PHP_Fix_Pathinfo_Enable 1

   AddHandler fcgid-script .php

    <Directory /var/www/fcgi/>

      Options +ExecCGI

      AllowOverride All

      FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php

      Order allow,deny

      Allow from all

    </Directory>

ServerSignature Off

</VirtualHost>

Q:Apache reports "SuexecUserGroup directive requires SUEXEC wrapper." warning during startup.
A:warning, 原因是错误的suEXEC权限设置。
查看 :    # ls -la /usr/sbin/suexec
应该为: -rwsr-xr-x 1 root root 12064 2008-04-17 01:15 /usr/sbin/suexec
主要是s权限即UID。如果权限和上面的不一样,修改:
# sudo chown root:root /usr/sbin/suexec
# sudo chmod 4755 /usr/sbin/suexec

本文转自centos.blog.chinaunix.net

调整DirectAdmin jail的部分命令和功能

开启sftp功能方法

在/usr/local/directadmin/custombuild/files.list添加文件列表


/usr/lib64/libnss3.so
/usr/lib64/libnss_db.so
/usr/lib64/libnss_files.so
/usr/lib64/libnss_ldap.so
/usr/lib64/libnss_nisplus.so
/usr/lib64/libnssutil3.so
/usr/lib64/libnss_compat.so
/usr/lib64/libnss_dns.so
/usr/lib64/libnss_hesiod.so
/usr/lib64/libnss_nis.so
/usr/lib64/libnssckbi.so
/lib64/libnss_compat-2.5.so
/lib64/libnss_db-2.2.so
/lib64/libnss_dns-2.5.so
/lib64/libnss_files-2.5.so
/lib64/libnss_hesiod-2.5.so
/lib64/libnss_ldap-2.5.so
/lib64/libnss_nis-2.5.so
/lib64/libnss_nisplus-2.5.so
/lib64/libnss_compat.so.2
/lib64/libnss_db.so.2
/lib64/libnss_dns.so.2
/lib64/libnss_files.so.2
/lib64/libnss_hesiod.so.2
/lib64/libnss_ldap.so.2
/lib64/libnss_nis.so.2
/lib64/libnss_nisplus.so.2
 


 然后修改/usr/local/directadmin/custombuild/jail_user.sh

找到mkdir -p $USER_HOME/usr/bin并添加代码


mkdir -p $USER_HOME/dev
mknod $USER_HOME/dev/null c 1 3
chown $1:$1 $USER_HOME/dev/null


开启子用户的wget功能,ssh命令直接执行


echo /usr/bin/wget>/usr/local/directadmin/custombuild/files.list


最后执行更新指定用户使其生效

/usr/local/directadmin/custombuild/jail_user.sh username

这样就可以在其他地方使用sftp管理了!

Nginx模块substitutions4nginx和HttpSubModule的过滤替换内容手记

模块开发者主页:http://code.google.com/p/substitutions4nginx/

执行svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only

下载:

编译安装时添加两个参数


–with-http_sub_module –add-module=/root/substitutions4nginx-read-only


sub_module用法:http://wiki.nginx.org/HttpSubModule

substitutions4nginx用法:http://code.google.com/p/substitutions4nginx/

s安装substitutions4nginx提示错误:-bash: svn: command not found

需安装subversion 安装命令yum -y install subversion

翻译substitutions4nginx参数:


g(default):替换所有匹配的字符串。
i: 执行不区分大小写的匹配。
o: 只需将第一个。
r: 该模式是作为一个正则表达式处理,默认是固定的字符串。


实际使用:


subs_filter ‘<(no?script.*?)>(.*?)<(\/no?script.*?)>’ ” gi; //替换掉全部的<noscript></noscript>
subs_filter ‘<(s?cript.*?)>(?:\s|\S)*?<(\/s?cript.*?)>’ ” gi; //替换掉全部的<script>包换中间换行</script>
subs_filter ‘<(i?frame.*?)>(.*?)<(\/i?frame.*?)>’ ” gi; //替换<iframe></iframe>


实际测试中sub_filter比subs_filter的速度要快,但如果你开启了nginx的cache速度上可以得到改善的。

测试过程发现对gzip源的内容无法实现替换的问题

可以在server段内加入 proxy_set_header Accept-Encoding "";

如果是替换中文词组则需要将nginx的配置文件保存为utf-8格式!

转自:http://www.caohuan.com/nginx-configuration-is-the-filter-to-accelerate-website.html 

linux下关闭mysql日志

如果你登录/usr/local/mysql/var/下面,你会看到很多像mysql-bin.000001这样的文件,这就是mysql生成的日志,留着也没多大的作用,可以关闭日志的生成。

输入下面命令


vim /etc/my.cnf


注释下面两个(在前面加上#)


#log-bin=mysql-bin

#binlog_format=mixed


重启mysql


service mysql restart


或者执行以下两句


sed -i 's/binlog_format=mixed/# binlog_format=mixed/g' /etc/my.cnf
sed -i 's/log-bin=mysql-bin/# log-bin=mysql-bin/g' /etc/my.cnf



 

ssh代理账户创建脚本

cat>>/bin/tunnel.sh <<EOF
#!/bin/sh
 echo ""
 echo "  ********************************************************************"
 echo "  *           welcome to SSH Tunnel , press a key to exit.           *"
 echo "  ********************************************************************"
 echo ""
 read x
 exit
EOF
chmod 755 /bin/tunnel.sh

将上面的代码运行一次,然后用下面这个添加用户设置密码即可!


useradd [用户名] -g nobody -s /bin/tunnel.sh   #添加用户
 passwd [用户名]  #设置密码。