Press "Enter" to skip to content

分类: Linux

采用Linux性能监测工具dstat来分析系统资源情况

日常管理中使用需要经常查看服务器状态和性能,比如IO占用情况,及内存使用情况,硬盘,CPU等等。网络上搜罗了一下,这个dstat软件还是比较不错能满足日常分析。本人采用的是X64系统,在CentOS6.2系统下采用yum进行安装dstat软件
默认情况它会收集 cpu、disk、net、paging、system 数据,一秒钟收集一次

[root@kiccleaf ~]# dstat  #运行命令是否已经安装
-bash: dstat: command not found   #没有找到此命令
[root@kiccleaf ~]# yum install dstat   #进行安装
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                            | 3.7 kB     00:00     
extras                                          | 3.5 kB     00:00     
updates                                         | 3.5 kB     00:00     
updates/primary_db                              | 654 kB     00:02     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dstat.noarch 0:0.7.0-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================
 Package       Arch           Version               Repository    Size
=======================================================================
Installing:
 dstat         noarch         0.7.0-1.el6           base         144 k

Transaction Summary
=======================================================================
Install       1 Package(s)

Total download size: 144 k
Installed size: 660 k
Is this ok [y/N]: y  #输入y进行安装
Downloading Packages:
dstat-0.7.0-1.el6.noarch.rpm                    | 144 kB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : dstat-0.7.0-1.el6.noarch                            1/1 

Installed:
  dstat.noarch 0:0.7.0-1.el6                                           

Complete!
[root@kiccleaf ~]# dstat -d   #查看硬盘IO操作
-dsk/total-
 read  writ
 861k   90k
   0     0 
   0    68k
4096B 1216k
   0   112k
[root@kiccleaf ~]# dstat -h   #查看帮助文档
Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics

Dstat options:
  -c, --cpu              enable cpu stats 显示CPU情况
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats 显示磁盘情况
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats 显示内存情况
  -n, --net              enable network stats 显示网络情况
     -N eth1,total          include eth1 and total 可以指定网络接口
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats 显示swap情况
     -S swap1,total         include swap1 and total 可以指定多个swap
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats

  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats 报告IPC消息队列和信号量的使用情况
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats

  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins

  -a, --all              equals -cdngy (default) 使用-cdngy 缺省的就是这样显示
  -f, --full             automatically expand -C, -D, -I, -N and -S lists 使用 -C, -D, -I, -N and -S 显示
  -v, --vmstat           equals -pmgdsc -D total 使用-pmgdsc -D 显示

  --bw, --blackonwhite   change colors for white background terminal
  --float                force float values on screen
  --integer              force integer values on screen
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers 只显示一次表头以后就不显示了,使用重定向写入文件时很有用
  --noupdate             disable intermediate updates
  --output file          write CSV output to file

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

较为长用的命令,来观察系统运行情况
#如果你想10秒收集一次,就输入: dstat -cdlmnpsy 10

[root@kiccleaf ~]# dstat -cdlmnpsy
----total-cpu-usage---- -dsk/total- ---load-avg--- ------memory-usage----- -net/total- ---procs--- ----swap--- ---system--
usr sys idl wai hiq siq| read  writ| 1m   5m  15m | used  buff  cach  free| recv  send|run blk new| used  free| int   csw 
  0   0  99   0   0   0| 104k   14k|   0    0    0|66.9M 8332k 81.5M  837M|   0     0 |  0   0 1.3|   0  2016M|  65    44 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B 1354B|  0   0   0|   0  2016M|  28    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  24    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  27    18 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M| 552B  522B|  0   0   0|   0  2016M|  28    23 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M|  60B  522B|  0   0   0|   0  2016M|  26    17 
  0   0 100   0   0   0|   0     0 |   0    0    0|66.9M 8332k 81.5M  837M| 491B  522B|  0   0   0|   0  2016M|  31    17

统计CPU,IO ,network,system load

[root@kiccleaf ~]# dstat -cndymlp -N total -D total 5 25
----total-cpu-usage---- -net/total- -dsk/total- ---system-- ------memory-usage----- ---load-avg--- ---procs---
usr sys idl wai hiq siq| recv  send| read  writ| int   csw | used  buff  cach  free| 1m   5m  15m |run blk new
  0   0  99   0   0   0|   0     0 |  96k   13k|  62    42 |66.8M 8332k 81.5M  837M|   0    0    0|  0   0 1.2
  0   0 100   0   0   0| 218B  636B|   0     0 |  27    19 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0
  0   0 100   0   0   0| 242B  477B|   0     0 |  29    18 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0
  0   0 100   0   0   0| 324B  479B|   0     0 |  28    18 |66.9M 8332k 81.5M  837M|   0    0    0|  0   0   0

统计网卡1的信息

[root@kiccleaf ~]# dstat -cdnsil -D hda -N eth1
Module dstat_disk24old failed to load. (No suitable block devices found to monitor)
Module dstat_net failed to load. (No suitable network interfaces found to monitor)
----total-cpu-usage---- ----swap--- ----interrupts--- ---load-avg---
usr sys idl wai hiq siq| used  free|  17    18    19 | 1m   5m  15m 
  0   0  99   0   0   0|   0  2016M|   4     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     4 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     3 |   0    0    0
  0   0 100   0   0   0|   0  2016M|   0     0     4 |   0    0    0

内存使用情况

[root@kiccleaf ~]# dstat -vmstat
Terminal width too small, trimming output.
---procs--- ------memory-usage----- ---paging-- -dsk/total- ---system-- ----total-cpu-usage---- ------memory-usage----- ----swap--- ----system---- ----total-cpu-usage---->
run blk new| used  buff  cach  free|  in   out | read  writ| int   csw |usr sys idl wai hiq siq| used  buff  cach  free| used  free|  date/time   |usr sys idl wai hiq siq>
0.0   0 1.1|66.8M 8332k 81.5M  837M|   0     0 |  88k   12k|  59    40 |  0   0  99   0   0   0|66.8M 8332k 81.5M  837M|   0  2016M|05-01 21:52:57|  0   0  99   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0    12k|  40    27 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:52:58|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  31    21 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:52:59|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  28    16 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:53:00|  0   0 100   0   0   0>
  0   0   0|66.8M 8340k 81.5M  837M|   0     0 |   0     0 |  36    19 |  0   0 100   0   0   0|66.8M 8340k 81.5M  837M|   0  2016M|05-01 21:53:01|  0   0 100   0   0   0>

Leave a Comment

安装CentOS系统基础配置

国内还是较多的镜像服务器的,163的速度还是不错的,所以本人一般都采用163下载更新。

最新的CentOS6.2 开机速度赞一个!强大的。
ISO下载地下:
http://mirrors.163.com/centos/6.2/isos/
有两个目录,可自己选择32位的,或是64位的,本人一般使用64位,好处地球人都知道。
i386/
x86_64/

OK,如果系统刚安装好,好么首先第一件要做的是配置好网卡

vi /etc/resolv.conf
#添加本地省份的DNS,如我在浙江杭州使用的是
nameserver 202.101.172.35
nameserver 202.101.172.47

第二步是配置好网卡IP(在CentOS6.1,6.2版本中如果选择最小安装,安装时没有配置网卡功能,需要登陆后再做修改)
DEVICE 网卡名称
HWADDR 网卡MAC地址
ONBOOT 配置启动
BOOTPROTO 配置静态化
BROADCAST 广播地址
IPADDR= ip地址
NETMASK 掩码
GATEWAY 网关

vi /etc/sysconfig/network-scripts/ifcfg-eth0
#修改或是添加
DEVICE="eth0"
HWADDR="00:0C:29:14:36:62"
ONBOOT="yes"
BOOTPROTO=static
BROADCAST=192.168.1.255
IPADDR=192.168.1.2
NETMASK=255.255.0.0
GATEWAY=192.168.1.1

第三步,关掉selinux,否则配置80,21访问时需要操作受权配置
SELINUX=enforcing 修改成 SELINUX=disabled

vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

第四步修改一下咱们的镜像下载地址

首先备份/etc/yum.repos.d/CentOS-Base.repo

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget 下载工具如果没有安装简单的可以用以下命令进行安装

yum install -y wget

下载后可以改成为CentOS-Base.repo文件
CentOS4 下载地址

wget http://mirrors.163.com/.help/CentOS4-Base-163.repo

CentOS5

wget http://mirrors.163.com/.help/CentOS5-Base-163.repo

CentOS6

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

运行yum makecache生成缓存

第五步,可以更新系统了

yum update -y

有关防火墙的配置可以参考我之前写的文章

Iptables 指南
防火墙日常操作记录
iptables防火墙配置脚本
IPTABLES配置过虑蠕虫病毒

Leave a Comment

Nginx目录自动加斜线”/”

服务器配置成Nginx后,发现子目录结尾不加“/”会造成无法访问。这是大多数人从Apache转至nginx的问题。

如:http://www.kiccleaf.com/test 就无法正常访问,而http://www.kiccleaf.com/test/ 却可以正常访问。

解决方法在nginx.conf中增加:
找到http{ 然后在里面添加

http{
…
server_name_in_redirect off;
…
}
Leave a Comment

linux 统计当前目录下文件数

查看当前目录下文件的个数

ls -l | grep "^-" | wc -l

  查看当前目录下文件的个数,包括子目录里的。

  ls -lR| grep "^-" | wc -l

  查看某目录下文件夹(目录)的个数,包括子目录里的。

  ls -lR| grep "^d" | wc -l

  简要说明:

 ls -l
  长列表输出该目录下文件信息(注意这里的文件,不同于一般的文件,可能是目录、链接、设备文件等)
  grep “^-”
  这里将长列表输出信息过滤一部分,只保留一般文件,如果只保留目录就是 ^d
  wc -l
  统计输出信息的行数,因为已经过滤得只剩一般文件了,所以统计结果就是一般文件信息的行数,又由于一行信息对应一个文件,所以也就是文件的个数

Leave a Comment

Linux各类压宿包的解压方法

01-.tar格式

解包:[root@kiccleaf ~]# tar xvf FileName.tar
打包:[root@kiccleaf ~]# tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)

02-.gz格式

解压1:[root@kiccleaf ~]# gunzip FileName.gz
解压2:[root@kiccleaf ~]# gzip -d FileName.gz
压 缩:[root@kiccleaf ~]# gzip FileName

03-.tar.gz格式

解压:[root@kiccleaf ~]# tar zxvf FileName.tar.gz
压缩:[root@kiccleaf ~]# tar zcvf FileName.tar.gz DirName

04-.bz2格式

解压1:[root@kiccleaf ~]# bzip2 -d FileName.bz2
解压2:[root@kiccleaf ~]# bunzip2 FileName.bz2
压 缩: [root@kiccleaf ~]# bzip2 -z FileName

05-.tar.bz2格式

解压:[root@kiccleaf ~]# tar jxvf FileName.tar.bz2
压缩:[root@kiccleaf ~]# tar jcvf FileName.tar.bz2 DirName

06-.bz格式

解压1:[root@kiccleaf ~]# bzip2 -d FileName.bz
解压2:[root@kiccleaf ~]# bunzip2 FileName.bz

07-.tar.bz格式

解压:[root@kiccleaf ~]# tar jxvf FileName.tar.bz

08-.Z格式

解压:[root@kiccleaf ~]# uncompress FileName.Z
压缩:[root@kiccleaf ~]# compress FileName

09-.tar.Z格式

解压:[root@kiccleaf ~]# tar Zxvf FileName.tar.Z
压缩:[root@kiccleaf ~]# tar Zcvf FileName.tar.Z DirName

10-.tgz格式

解压:[root@kiccleaf ~]# tar zxvf FileName.tgz

11-.tar.tgz格式

解压:[root@kiccleaf ~]# tar zxvf FileName.tar.tgz
压缩:[root@kiccleaf ~]# tar zcvf FileName.tar.tgz FileName

12-.zip格式

解压:[root@kiccleaf ~]# unzip FileName.zip
压缩:[root@kiccleaf ~]# zip FileName.zip DirName

13-.lha格式

解压:[root@kiccleaf ~]# lha -e FileName.lha
压缩:[root@kiccleaf ~]# lha -a FileName.lha FileName

14-.rar格式

解压:[root@kiccleaf ~]# rar a FileName.rar
压缩:[root@kiccleaf ~]# rar e FileName.rar

rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也行):

[root@kiccleaf ~]# cp rar_static /usr/bin/rar

Leave a Comment

Ubuntu 64-bit 11-10版本安装截图-强大的Linux系统

Ubuntu 64-bit 11-10版本安装截图,看样子他们在界面方面和功能方面下了很大的努力。感觉真的不错,未来我也将系统全换掉。
1.系统开启画面

2.登陆界面挻漂亮的

3.打开火狐访问网址

4.多界面效果真不错

5.系统设置和苹果有点像

6.比较强大的软件安装功能和界面展示

7.最最强大的私有云,可以免费注册得到5G的云空间

8.主文件夹,日常放置文件的集散地

9.Linux下的PPT功能

10.较强大的首页功能和软件

11.漂亮的界面与背景

12.更换背景配置,效果直接预览

13.换好后的背景图,很漂亮

14.系统自动找到需要更新的软件及补丁

15.更新中的界面

2 Comments

整理了一份VPS 安全设置

修改 SSH 默认端口

不要使用默认的 22 端口,这样很容易暴露 SSH 服务,也为暴力猜解用户名和密码留下了隐患。解决方法:将 /etc/ssh/sshd_config 中的 Port 改为其他端口。

禁止 root 帐号 SSH 登录

这样也是相当危险的,一般的做法是通过 SSH 配置文件,限制 root 帐号直接登录。
修改 /etc/ssh/sshd_config
将 PermitRootLogin 的值改为 no
这样,SSH 一律使用普通用户登录,在需要执行更高权限命令时,通过 sudo 命令,或者 su 成 root 再执行。

限制账号多重登陆

这样的做法,能让同一个账号,在同一时间内不能被多人同时登录。
实现方法:编辑 /etc/security/limits.conf
加入如下配置项即可:
* hard maxlogins 2

防 ping
# 禁止 ping
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
# 允许 ping
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

一、生成密钥对

可以使用命令行 ssh-keygen 生成(RSA/DSA 二选一):
# RSA
ssh-keygen -t rsa -b 2048 -C kiccleaf@163.com
# DSA
ssh-keygen -t dsa -C kiccleaf@163.com

当然也可以使用 putty 的 puttygen 工具生成。
SSH 登录需要 OpenSSH 格式的公钥,ssh-keygen 生成的 id_rsa.pub / id_dsa.pub 就是这种格式,如果是用 puttygen 生成,需要导出为 OpenSSH 格式。

二、添加服务端公钥
用将要使用密钥的用户登录 VPS。
cd
mkdir -p .ssh
chmod 755 .ssh

# RSA
cat id_rsa.pub >> .ssh/authorized_keys
# RSA
cat id_dsa.pub >> .ssh/authorized_keys2

chmod 644 .ssh/authorized_keys

三、配置 SSH 服务端

编辑 /etc/ssh/sshd_config,修改以下几个参数,禁止 root 账号 和 使用密码 直接登录:

PermitRootLogin no
PasswordAuthentication no

重启 SSH 服务:
/etc/init.d/sshd restart

四、配置 SSH 客户端

SecureCRT 可以直接使用 OpenSSH 格式的密钥,putty 则需要使用 puttygen 导入 id_rsa / id_dsa 再保存为 .ppk 格式的私钥。

Leave a Comment

CentOS 5.6 X86_64系统下Postfix邮件系统配置【pop3,smtp】

硬件环境:
服务器型号:IBM X336
CPU型号: Intel(R) Xeon(TM) CPU 3.80GHz *2颗
内存型号: 2G*4根
硬盘型号:SCSI 73G*2块

软件配置:
系统:CentOS5.6 x86_64
软件:Nginx1.0.4+PHP5.3.6(FPM-FCGI)+Mysql5.5.3

Linux系统最小安装,在此就不多说了。此机器主要功能是对外进行图片访问,由于公司需要邮件系统进行邮件发送和接收,考虑Qmail配置太复杂,sendmail配置也麻烦所以就选择postfix作为邮件处理系统。

1.PostFix安装配置
2.dovecot安装配置
3.防火墙配置
4.测试邮件发送

1.PostFix安装配置
第一步:首先进行安装postfix

yum -y install postfix

第二步:配置main.cf文件

[root@kiccleaf ~]# vim /etc/postfix/main.cf
myhostname = mail.kiccleaf.com
mydomain = kiccleaf.com
myorigin=$mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
relay_domains = $mydestination
mynetworks = 192.168.1.0/28, 127.0.0.0/8,60.191.49.228/24 #填写自己的公网ip
home_mailbox = Maildir/
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)  ← 找到这一行,接此行添加如下行:
smtpd_banner = $myhostname ESMTP unknow ← 添加这一行,不显示SMTP服务器的相关信息

#Add end
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 15728640

第三步:配置smtpd.conf

[root@kiccleaf ~]# vim /usr/lib64/sasl2/smtpd.conf

pwcheck_method: saslauthd
改成
pwcheck_method: auxprop

第四步:配置postfix随系统启动

[root@kiccleaf ~]# chkconfig saslauthd on
[root@kiccleaf ~]# chkconfig --list saslauthd
saslauthd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off

[root@kiccleaf ~]# chkconfig postfix on
[root@kiccleaf ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

第五步:启动postfix服务

[root@kiccleaf ~]# /etc/rc.d/init.d/saslauthd start
Starting saslauthd:                                        [  OK  ]

[root@kiccleaf ~]# /etc/rc.d/init.d/postfix start
Starting postfix:                                          [  OK  ]

第六步:对postfix进行测试

telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 kiccleaf.com ESMTP unknow
ehlo localhost
250-kiccleaf.com
250-PIPELINING
250-SIZE 15728640
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

第七步:添加配置,用户和密码

 [root@kiccleaf ~]# mkdir /data/Maildir
 [root@kiccleaf ~]# chmod 700 /data/Maildir
 [root@kiccleaf ~]# mkdir /home/leaf/Maildir
 [root@kiccleaf ~]# chmod 700 /home/leaf/Maildir
 [root@kiccleaf ~]# chown leaf. /home/leaf/Maildir
 [root@kiccleaf ~]# saslpasswd2 -u mail.kiccleaf.com -c leaf  #添加帐号leaf
 Password:          #输入密码
 Again (for verification):    #输入重复密码
 [root@kiccleaf ~]# chgrp postfix /etc/sasldb2
 [root@kiccleaf ~]# chmod 640 /etc/sasldb2
 [root@kiccleaf ~]# alternatives --config mta

There are 2 programs which provide 'mta'.

Selection Command
 -----------------------------------------------
 *+ 1 /usr/sbin/sendmail.sendmail
 2 /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2      #选择postfix作为邮件服务
 

2.接下去安装pop3接收服务dovecot
第一步:dovecot服务安装

yum -y install dovecot

第二步:编辑dovecot.conf文件

找到#protocols = imap imaps pop3 pop3s行添加或是修改:
protocols = imap pop3
老版本CentOS5.5版本是以default_mail_env作为配置
mail_location = maildir:~/Maildir

第三步:配置dovecot随系统启动

[root@kiccleaf ~]# chkconfig dovecot on
[root@kiccleaf ~]# chkconfig --list dovecot
dovecot        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

第四步:启动dovecot服务

[root@kiccleaf ~]# /etc/rc.d/init.d/dovecot start
Starting Dovecot Imap:                                     [  OK  ]

第五步:对dovecot进行测试

telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
quit
+OK Logging out
Connection closed by foreign host.

3.防火墙配置

[root@kiccleaf ~]# vim /etc/sysconfig/iptables
#添加以下三个端口25,110,143
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

#重启防火墙
[root@kiccleaf ~]# service iptables restart
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
Applying iptables firewall rules:                          [  OK  ]
Loading additional iptables modules: ip_conntrack_netbios_n[  OK  ]
#查看监听端口列表
[root@kiccleaf ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:2188                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:58008               0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 192.168.1.9:22           192.168.1.22:2850           ESTABLISHED

4.测试邮件发送
为了方便Foxmail作为客户端进行配置,填写ip为pop3,smtp,填写帐号名称及密码,进行发送测试,在此用php编写简要的发送代码进行测试。

<?php
$to      = '53045936@qq.com';
$subject = 'the subject test';
$message = 'hello!测试用例!';
$headers = 'From: leaf@kiccleaf.com' . "\r\n" .
'Reply-To:  leaf@kiccleaf.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

至此邮件系统的发送和接收都已经配置完成

2 Comments

postfix 删除队列中的所有邮件

邮件系统被其他人非法利用转发,所以队列中太多垃圾邮件
删除所有队列中的邮件

先执行mailq命令查看邮件队列
[root@kiccleaf ]# mailq
B0B1E511DC7*    5260 Mon Aug  1 15:18:14  rztdmmcrfn@yahoo.com
                                         macrothere@yahoo.com.tw
                                         lock90460@yahoo.com.tw
                                         liuhsinni@yahoo.com.tw
ACB765D7A8B*     344 Wed Aug  3 02:59:13  bnuga@ms54.hinet.net
                                         a560909a@yahoo.com.tw
                                         a7115968@yahoo.com.tw
#我们发现有很多这样的垃圾邮件在队列中,可以采用Crtl+C进行终止列表
#执行邮件删除操作命令,记住参数ALL一定要大写
[root@kiccleaf ]# postsuper -d ALL
postsuper: Deleted: 148468 messages
#总共删除了148468条数据
Leave a Comment

CentOS 5.6 X86_64系统下Vsftpd.conf配置

安装方式可以直接用光盘安装时自带的vsftp或是采用yum,也可以采用源码编译。安装过程就不讲了。直接配置文件
首先操作备份文件及创建一个vsftpd.conf文件

[root@kiccleaf]# adduser leaf
[root@kiccleaf]# passwd leaf
Changing password for user leaf.
New UNIX password: #输入新密码
Retype new UNIX password: #输入重复密码
passwd: all authentication tokens updated successfully.

[root@kiccleaf]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
[root@kiccleaf]# vim /etc/vsftpd/vsftpd.conf

vsftpd.conf配置文件内容如下:

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
chroot_list_enable=Yes
userlist_enable=Yes
userlist_deny=No
pasv_enable=YES
pasv_min_port=65000
pasv_max_port=65100
use_localtime=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/user_list

添加leaf用户至user_list文件中,使leaf用户可以登陆ftp

[root@kiccleaf]# echo leaf >> /etc/vsftpd/user_list  #添加leaf用户可以登陆的ftp
[root@kiccleaf]#  service vsftpd restart  #重启vsftpd
Leave a Comment