Category Archives: Linux

进程管理及作业控制

 
Linux是一个多任务的操作系统,系统上同时运行着多个进程,正在执行的一个或多个相关进程称为一个作业。使用作业控制,用户可以同时运行多个作业,并在需要时在作业之间进行切换。本章详细介绍进程管理及作业控制的命令,包括启动进程、查看进程、调度作业的命令。

Continue reading

限制apache2的连接数

在debian下安装:
#apt-get install libapache-mod-limitipconn
 
不知道安装到什么地方了
 find / -name mod_limitipconn.so
/usr/lib/apache/1.3/mod_limitipconn.so
居然在1.3的目录下,复制到apache2的目录中
cp /usr/lib/apache/1.3/mod_limitipconn.so /usr/lib/apache2/modules/
 
修改apache2配置文件
nano /etc/apache2/httpd.conf
在最下面添加

ExtendedStatus On
LoadModule limitipconn_module modules/mod_limitipconn.so

重新启动/etc/init.d/apache2 restart
失败。。。
屏蔽LoadModule limitipconn_module modules/mod_limitipconn.so
正常
看来这个mod不直接支持apache2。。。。。。。
 
不过在官方的确写了安装方法,但是需要重新编译:(
 
Installation
The instructions below are written for Apache 2.0.39 since that’s what I had when I wrote the module, but they will also work with any later version of Apache 2.0.
Instructions for statically compiling mod_limitipconn into httpd:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
./configure –with-module=aaa:../mod_limitipconn-0.22/mod_limitipconn.c
make
make install
Instructions for building as a Dynamic Shared Object (DSO):
 
tar xzvf mod_limitipconn-0.22.tar.gz
cd mod_limitipconn-0.22
make install
Instructions for building static httpd with proxy tracking:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff
./buildconf
./configure –enable-forward –with-module=aaa:../mod_limitipconn-0.22/mod_limitipconn.c
make
make install
Instructions for building DSO with proxy tracking:
 
tar xzvf httpd-2.0.39.tar.gz
tar xzvf mod_limitipconn-0.22.tar.gz
cd httpd-2.0.39
patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff
./buildconf
./configure –enable-forward
make
make install
cd ../mod_limitipconn-0.22
PATH=/usr/local/apache2/bin:$PATH make install

修改apache最大连接数

# prefork MPM
# StartServers ……… number of server processes to start
# MinSpareServers …… minimum number of server processes which are kept spare
# MaxSpareServers …… maximum number of server processes which are kept spare
# MaxClients ……….. maximum number of server processes allowed to start
# MaxRequestsPerChild .. maximum number of requests a server process serves
<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients          20
MaxRequestsPerChild  0
</IfModule>
 
# pthread MPM
# StartServers ……… initial  number of server processes to start
# MaxClients ……….. maximum  number of server processes allowed to start
# MinSpareThreads …… minimum  number of worker threads which are kept spare
# MaxSpareThreads …… maximum  number of worker threads which are kept spare
# ThreadsPerChild …… constant number of worker threads in each server process
# MaxRequestsPerChild .. maximum  number of requests a server process serves
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>
 
 
注意,如果不知道自己的apache2使用哪种工作模式,最简单的方法,先restart一下apache2,然后netstat -t 看看有几个apache2的进程,然后对比一下就可以了
ps:
apache2默认最大256连接,如果需要更大,自己手动编译

用 Logwatch 工具监控 Linux 系统 Log 日志

如果要想迅速的得到 Linux 环境中的日志报告信息, Logwatch 是一个很好的工具.
在debian上安装非常简单,只需要
#sudo apt-get install logwatch
查看昨天的信息,使用下面的命令就可以了。结果包括启动信息,登陆信息,磁盘使用状况等。
#logwatch –print
单独查看某项服务的信息,比如ssh,使用
#logwatch –service  sshd –print
具体使用可以
#logwatch –help
Usage: /usr/sbin/logwatch [–detail <level>] [–logfile <name>]
   [–print] [–mailto <addr>] [–archives] [–range <range>] [–debug <level>]
   [–save <filename>] [–help] [–version] [–service <name>]
   [–numeric] [–output <output_type>]
   [–splithosts] [–multiemail]
 
–detail <level>: Report Detail Level – High, Med, Low or any #.
–logfile <name>: *Name of a logfile definition to report on.
–service <name>: *Name of a service definition to report on.
–print: Display report to stdout.
–mailto <addr>: Mail report to <addr>.
–archives: Use archived log files too.
–save <filename>: Save to <filename>.
–range <range>: Date range: Yesterday, Today, All, Help
                             where help will describe additional options
–numeric: Display ddresses numerically rather than symbolically and numerically
           (saves  a  nameserver address-to-name lookup).
–debug <level>: Debug Level – High, Med, Low or any #.
–splithosts: Create a report for each host in syslog.
–multiemail: Send each host report in a separate email.  Ignored if
              not using –splithosts.
–output <output type>: Report Format – mail, html-embed, html or unformatted#.
–version: Displays current version.
–help: This message.
* = Switch can be specified multiple times…

但是每天ssh到服务器上使用太不方便,还好logwatch提供了mail功能
#nano /etc/logwatch/conf/logwatch.conf
修改下面的root为你自己的邮件地址
MailTo = root
同时,因为我们需要了解服务器的详细信息,所以,修改下面的
Detail = 是细节度,推荐 10 ,即最高

chkrootkit

这个程序是设计用来检查许多广为人知的rootkit 的
安装
 
#apt-get install chkrootkit
 
运行
[root@jd chkrootkit-0.34]# chkrootkit
ROOTDIR is `/’
Checking `amd’… not found
Checking `basename’… not infected
Checking `biff’… not found
Checking `chfn’… not infected
Checking `chsh’… not infected
Checking `cron’… not infected
Checking `date’… not infected
Checking `du’… not infected
Checking `dirname’… not infected
Checking `echo’… not infected
Checking `egrep’… not infected
Checking `env’… not infected
Checking `find’… not infected
[…]