实验一:
postfix and mysql
环境: selinux 须要是关闭的。iptables关闭的
首先,须要安装图形界面的建立数据库
假设你当前的机子IP为: 192.168.0.58
步骤:
(1)在192.168.0.58机子上:
yum install php php-server mysql mysql-server php-mysql -y
(2) cd /var/www/html
lftp 192.168.0.254
cd pub/docs
get phpMyAdmin-2.11.3-all-languages.tar.bz2
(此处是在所在环境服务器上下载,也能够去网站上下载更高的版本)
tar jxf phpMyAdmin-2.11.3-all-languages.tar.bz2
mv phpMyAdmin-2.11.3-all-languages myadmin
cd myadmin
cp config.sample.inc.php config.inc.php
(config.inc.php是配置文件,须要修改里面的东西,上面更名字的是将名字改短那样你进去的时候不至于写那么长的名字了)
vi config.inc.php
$cfg['blowfish_secret'] = 'sushan'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
(3)在192.168.0.58机子上将appache打开:
/etc/init.d/httpd start
(4)打开浏览器输入网址:
http://192,168.0.58/myadmin
而后以root省份密码为空的方式登陆服务器,
(5)登陆以后,首先你建立一个数据库sushan,而后建立一个表sushanshan,设置四个字段。
username,password,domain,mailbox,假设你设置的类型全为:VARCHAR,长度为:25,25,15,30(仅供参考)
而后插入:
username : test@westos.org
password : sushan
domain : westos.org
mailbox : westos.org/sushan/
而后执行以后。(注意啦注意啦。。。。在这里的westos.org/sushan/后面的‘ / ’ 千万省不得啊。。。不然。。。。没法建立。)
(6)postconf -n查看生效的postfix选项。postfix -d 显示默认的选项
postconf -m
要显示 mysql 才能将postfix和mysql结合。
useradd -u 600 vmail
postfix -e inet_interfaces = all
postfix -e virtual_alias_maps=mysql:/etc/postfix/mysql-alias.cf
postfix -e virtual_gid_maps=static:600
postfix -e virtual_mailbox_base=/home/vmail/
postfix -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-domains.cf
postfix -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-mailboxs.cf
postfix -e virtual_uid_maps=static:600
编辑完以后:
/etc/init.d/postfix restart
(7) mysql
mysql> grant all on sushan.* to vmail@localhost identified by 'vmail';
flush privileges;
( grant all on sushan.* to vmail@localhost identified by 'vmail';对sushan这个数据库里面的全部表拥有因此的全限,这个用户名字为vmail,登陆本地,登陆时候的密码为 vmail)
测试: mysql -uroot -pvmail sushan (写上数据库名字就会直接进入的是数据库sushan)查看是否能够登陆的进去。来查看以上设置是否生效。
(8)
vi /etc/postfix/mysql-alias.cf
hosts=localhost(默认是本地)
user = vmail(在受权用户的时候设置的虚拟用户名称)
password = vmail(这个是在受权mysql用户的时候设置的进入密码)
dbname = sushan(数据库的名字)
table = sushanshan(数据库中表的名字)
select_field = username
where_field = username
vi /etc/postfix/mysql-domains.cf
hosts=localhost(默认是本地)
user = vmail(在受权用户的时候设置的虚拟用户名称)
password = vmail(这个是在受权mysql用户的时候设置的进入密码)
dbname = sushan(数据库的名字)
table = sushanshan(数据库中表的名字)
select_field = domain
where_field = domain
vi /etc/postfix/mysql-mailboxs.cf
hosts=localhost(默认是本地)
user = vmail(在受权用户的时候设置的虚拟用户名称)
password = vmail(这个是在受权mysql用户的时候设置的进入密码)
dbname = sushan(数据库的名字)
table = sushanshan(数据库中表的名字)
select_field = mailbox
where_field = username
(9)编辑完上述文件后你要检查下你的配置文件是否正确。
测试: postmap -q "test@westos.org" mysql:/etc/postfix/mysql-alias.cf
会显示以下:test@westos.org
postmap -q "test@westos.org" mysql:/etc/postfix/mysql-mailboxs.cf
westos.org/sushan/
postmap -q "westos.org" mysql:/etc/postfix/mysql-domains.cf
westos.org
显示以上信息,说明正确。
(10)
最终测试:
/etc/init.d/postfix restart
/etc/init.d/mysqld restart
ll /home/vmail/(正常是不会有什么非定制的文件的)
mail test@westos.org
Subject: test
tests
test
EOT
此时:cd /home/vmail/(此目录的设置在:virtual_mailbox_base=/home/vmail/中设置的)
ls
会显示 westos.org
cd westos.org/sushan/
ls
会有 cur new tmp 这几个文件夹
cd new
ls
cat 。。。。。。。。。
便可查看你发的邮件信息的。
实验二:
(1)添加数据库中的:
插入: username : sushan@linux.org
password : sushan
domain : linux.org
mailbox : linux.org/sushanlinux/
(2)
此时检查下你的配置文件是否正确。
测试: postmap -q "sushan@westos.org" mysql:/etc/postfix/mysql-alias.cf
sushan@linux.org
postmap -q "sushan@linux.org" mysql:/etc/postfix/mysql-mailboxs.cf
linux.org/sushanlinux/
postmap -q "linux.org" mysql:/etc/postfix/mysql-domains.cf
linux.org
显示以上信息,说明正确。
(3)mail sushan@linux.org
cd /home/vmail
cd linux.org/sushanlinux/
ls
显示 sushan 目录。
cd sushan
ls
cur new tmp
cd new
cat。。。。。。。。查看。
pwd
/home/vmail/linux.org/sushan/new php