Xây Dựng Mail Server Postfix Và Quản Lý Email Bằng Php Mysql

6
Trang chủ Thiết kế web Đăng ký tên miền Dịch vụ hosting Cho thuê máy chủ Quản trị nội dung Chia sẻ kiến thức Hỗ trợ Xây dựng mail server postfix và quản lý email bằng php mysql updated on 20150113 Trước đây thuonghieuweb đã có một bài viết hướng dẫn triển khai mail server đơn giản trên hệ điều hành linux, sử dụng các user của hệ điều hành làm email account. Nay thuonghieuweb tiếp tục phát triển hướng này và chia sẻ cách để có thể quản lý được nhiều tên miền nhiều email trên một server. Để tìm hiểu từ gốc đến ngọn các bạn có thể tham khảo bài viết này để biết cách hình thành một mail server nguyên thủy là như thế nào, tuy nhiên nếu muốn học theo kiểu stepbystep thì vẫn có thể bắt đầu ngay với bài viết này và chịu khó theo đúng từng bước của bài viết là xong. Chuẩn bị: Bạn cần có một máy chủ hoặc một VPS cài đặt hệ điều hành Centos 5.x trở lên Giả định là bạn đã biết về webserver và đã cài đặt sẵn các ứng dụng apache, php, mysql phpmyadmin lên server này nếu như bạn chưa có các ứng dụng này, hãy tham khảo bài viết này để cài đặt chúng. Bước 1: Thiết lập hostname Đầu tiên chúng ta cần kiểm tra hostname của máy chủ vì hostname này sẽ dùng cho một số thiết lập hệ thống sau này. Để kiểm tra hostname của linux, chúng ta dùng lệnh sau # hostname f Để thay đổi hostname, chúng ta chỉnh sửa dòng HOSTNAME trong file /etc/sysconfig/network. Ngoài ra ta cũng cần định nghĩa hostname gắn với ip của máy chủ này trong file /etc/hosts. Việc định nghĩa hostname trong file /etc/hosts sẽ giúp server có thể diễn dịch các hostname dùng để test mà không cần phải định nghĩa các bản ghi trên DNS server. Bước 2: Kiểm tra và update yum, repo Trước hết chúng ta update công cụ cài đặt yum bằng lệnh sau # yum y update Ngoài ra chúng ta cũng cần kiểm tra trong repo của hệ điều hành đã có dòng lệnh exclude=postfix* như hình dưới đây hay chưa bằng lệnh sau: # vi /etc/yum.repos.d/CentOSBase.repo Nếu chưa có thì thêm dòng này vào để quá trình download và cài đặt sẽ lấy bản postfix hỗ trợ mysql. Xem chi tiết... THUÊ HOSTING TẶNG WEBSITE 1G lưu trữ 30G lưu lượng PHP/MySQL Miễn phí thiết kế website 120.000 đ/tháng EMAIL CHO DOANH NGHIỆP Không giới hạn số hòm thư Sử dụng IP quốc tế riêng Không bị black list Không giới hạn dung lượng mail 200.000 đ/tháng QUẢNG CÁO TUYỂN DỤNG Công ty cổ phần truyền thông số VDATA cần tuyển gấp 2 coder PHP. Yêu cầu biết về PHP, MySQL. Ưu tiên các bạn biết về hệ thống, phần cứng, hệ điều hành linux, email services, chăm chỉ, cần cù, trung thực. Lương theo mức độ đáp ứng công việc. Nộp hồ sơ qua email [email protected]. Tìm hiểu thông tin qua số điện thoại 098984 8886. Hỗ trợ trực tuyến tại hoặc gọi hotline 0989848886

description

Xây Dựng Mail Server Postfix Và Quản Lý Email Bằng Php Mysql

Transcript of Xây Dựng Mail Server Postfix Và Quản Lý Email Bằng Php Mysql

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 1/6

    Trangch Thitkweb ngktnmin Dchvhosting Chothumych Quntrnidung Chiaskinthc Htr

    Xydngmailserverpostfixvqunlemailbngphpmysqlupdatedon20150113

    Trcythuonghieuwebcmtbivithngdntrinkhaimailserverngintrnhiuhnhlinux,sdngccusercahiuhnhlmemailaccount.Naythuonghieuwebtiptcphttrinhngnyvchiascchcthqunlcnhiutnminnhiuemailtrnmtserver.

    tmhiutgcnngnccbncththamkhobivitnybitcchhnhthnhmtmailservernguynthylnhthno,tuynhinnumunhctheokiustepbystepthvncthbtungayvibivitnyvchukhtheongtngbccabivitlxong.

    Chunb:

    BncncmtmychhocmtVPScithiuhnhCentos5.xtrlnGinhlbnbitvwebservervcitsnccngdngapache,php,mysqlvphpmyadminlnservernynunhbnchacccngdngny,hythamkhobivitnycitchng.

    Bc1:Thitlphostnameutinchngtacnkimtrahostnamecamychvhostnamenysdngchomtsthitlphthngsauny.kimtrahostnamecalinux,chngtadnglnhsau

    #hostnamef

    thayihostname,chngtachnhsadngHOSTNAMEtrongfile/etc/sysconfig/network.

    Ngoiratacngcnnhnghahostnamegnviipcamychnytrongfile/etc/hosts.Vicnhnghahostnametrongfile/etc/hostssgipservercthdindchcchostnamedngtestmkhngcnphinhnghaccbnghitrnDNSserver.

    Bc2:Kimtravupdateyum,repo

    Trchtchngtaupdatecngccityumbnglnhsau

    #yumyupdate

    Ngoirachngtacngcnkimtratrongrepocahiuhnhcdnglnhexclude=postfix*nhhnhdiyhaychabnglnhsau:

    #vi/etc/yum.repos.d/CentOSBase.repo

    Nuchacththmdngnyvoqutrnhdownloadvcitslybnpostfixhtrmysql.

    Xemchitit...

    THUHOSTINGTNGWEBSITE

    1Glutr

    30Glulng

    PHP/MySQL

    Minphthitkwebsite

    120.000/thngEMAILCHODOANHNGHIP

    Khnggiihnshmth

    SdngIPquctring

    Khngbblacklist

    Khnggiihndunglngmail

    200.000/thngQUNGCOTUYNDNG

    CngtycphntruynthngsVDATAcn tuyn gp 2 coder PHP. Yu cubit v PHP,MySQL.u tin cc bnbit v h thng, phn cng, h iuhnh linux, email services, chm ch,cnc,trungthc.Lngtheomcp ng cng vic. Np h s quaemail [email protected]. Tm hiuthng tin qua s in thoi 0989848886.

    Htrtrctuynti hocgihotline0989848886

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 2/6

    Bc3:Kimtravcitccgimysqldevel,cyrussasl,dovecot,postfix

    Khibncitmysqlcththiumtsgiphnmmcnthitktnipostfixvimysqllmysqldevelvcyrussaslvvychngtacnkimtrabngcclnhsau

    #rpmqa|grepmysql(kimtraxemcccgidchvnoikmvimysqlccit)#rpmqa|grepsasl(kimtraxemgicyrussaslccitcha)#rpmqa|grepdovecot#rpmqa|greppostfix

    NuccgitrncthOK,cnnuchacchngtadnglnhsaucitnglotccginy

    #yumyinstallmysqlmysqldeveldovecotcyrussasl

    Chngtacngcndnglnhsauykimtraxempostfixccitcngmodulemysqlhaycha

    #postfixm

    NunhnthymodulemysqlthOK,cnnukhngthy,chngtadnglnhyumremovepostfixgbbnpostfixcvcilibnmibnglnhsau

    #yumenablerepo=centosplusinstallpostfix

    Bc4.Gbccdchvcxungtvtchtkhingchopostfix,dovecot

    HiuhnhCentoscsnmtsdchvnhsendmail,exim...chngtacnkimtravttccdchvnyitrnhxungtvipostfixbngcchsau

    #servicesendmailstatus#servicesendmailstop#chkconfigsendmailoff

    Saubtccdchvmicitbc3ln

    #servicemysqlstart#servicedovecotstart#servicepostfixstart#chkconfigmysqlon#chkconfigdovecoton#chkconfigpostfixon

    Bc5:tmtkhuchouserrootcacsdliumysql

    Bncnlurng,ngaysaukhicitmysql,csdliunycsnmtusercquynticao.luserroot,trngtnviuserrootcahthngnhngkhclcpasswordbngtrng.Vvyphingaylptctmtkhuchousernybnglnhsau:

    #mysql_secure_installation

    Khithchinlnhtrnbnsnhnc4cuhinhsau:

    Setrootpassword?[Y/n](tmtkhuchoroot)Removeanonymoususers?[Y/n](Xabuservdanh)Disallowrootloginremotely?[Y/n](Khngchophprootngnhptxa)Removetestdatabaseandaccesstoit?[Y/n](Xabdatabasetest)

    BnnntrliYchoc4cuhitrnbtcclhngbomtcamysql.

    Bc6:Todatabasemailserverluccthngsdomain,emailaccounto.

    Chngtadnglunuserrootvatmtkhutrnthchincclnhtodatabasevtabletdnglnhnhsau.Hocnubnciphpmyadminthcththaotctodatabasevtabletrngiaodinweb.

    #mysqlurootp

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 3/6

    saukhigmtkhubnscvokhuvcdnglnhcamysqlvidunhcnhsau:

    mysql>

    Bnglnh

    mysql>CREATEDATABASEmail

    tomtdatabasetnlmail.Sautomtusercquynthaotctrndatabasenybnglnhsau:

    mysql>USEmailmysql>GRANTSELECT,INSERT,UPDATE,DELETEONmail.*TO"mail_admin"@"localhost"IDENTIFIEDBY"123#abc"mysql>FLUSHPRIVILEGES

    Trong123#abclmtkhucausermail_admin.Bnnnghilimtkhunyvsaunsbmhatrongcsdliu,khngcnnhncdngplaintextna.

    Lu:cclnhcamysqluphiktthcbngduchmphy()ccthamsinmvmutrnltybin,bncthttndatabase,vuser,mtkhutheothchcamnh,tuynhinnutestchngtanndngthngnhtcctnnytrnhphisainhiuccbcsau.

    Bc7:tocctablequnldomainvusero.

    Chngtacnto4tableldomains,forwarding,transports,vusers.tableforwardingvtransportdngchoccchcnngmrngsaunycaemailnhforward,relay...Trongbivitnychacpnccchcnngnncthkhngcntocctableny.Chcnctabledomainsvusersl.

    mysql>CREATETABLEdomains(domainvarchar(50)NOTNULL,PRIMARYKEY(domain))mysql>CREATETABLEforwardings(sourcevarchar(80)NOTNULL,destinationTEXTNOTNULL,PRIMARYKEY(source))mysql>CREATETABLEtransport(domainvarchar(128)NOTNULLdefault"",transportvarchar(128)NOTNULLdefault"",UNIQUEKEYdomain(domain))mysql>CREATETABLEusers(emailvarchar(80)NOTNULL,passwordvarchar(20)NOTNULL,PRIMARYKEY(email))mysql>exit

    Lucclnhtrncththchintrongphpmyadminnuccbncitgidchvny.

    Bc8:Thitlpachipchomysqlserver#vi/etc/my.cnf

    thmvomtdngnhsau:

    bindaddress=127.0.0.1

    Ghilivkhinglidchvmysql

    #servicemysqlrestart

    Bc9:Toccfilecuhnhchopostfix

    Chngtacnto4filecuhnhpostfixbitcchqueryvocsdliu,lyraccgitrnhdomain,forwarding,emailaccount...Ccbndownloadc4fileysauuploadlnthmc/etc/postfix/,mravsaccthamsuser,passwordvdbnamenhvatotrn.

    Sauthitlppermissionsvownershipchoccfilenybngcclnhsau

    #chmodo=/etc/postfix/mysqlvirtual_*.cf#chgrppostfix/etc/postfix/mysqlvirtual_*.cf

    cthnhnemail,chngtacntomtuservgroupctnlvmail.Ccvirtualmailboxescaccemailaccountctorasauny,sclutrtrongthmchomecauserny(/home/vmail)

    #groupaddg5000vmail#useraddgvmailu5000vmaild/home/vmailm

    Bc10:Cuhnhpostfix.

    Ccbntifileconfig.shnyv,sauuploadvothmc/etc/postfix/vsadngutincafilechongvihostnamecaccbn,chmodsang755vchyfilentaddccdngtrongconfig.shvofilemain.cfcapostfix.

    #vi/etc/postfix/config.sh#chmod755/etc/postfix/config.sh#/etc/postfix/config.sh

    Tiptheochngtachnhsafilemaster.cf,thmdngsauvoongiafie,mcInterfacestononPostfix

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 4/6

    software

    dovecotunixnnpipeflags=DRhuuser=vmail:vmailargv=/usr/libexec/dovecot/deliverf${sender}d${recipient}

    Khinglidchvpostfix

    #servicepostfixrestart

    Bc11:Cuhnhdovecot

    Ccbntifilecuhnhdovecot.confmiyv,sauuploadln/etc.Lu,nnbackuplimtbncafiledovecot.confctrckhifilemiln.Mfiledovecot.confravsadngpostmaster_address=postmaster@thuonghieuweb.comvitnmincabn.

    Sauto1filedovecotsql.confmcvodatabasenhsau:

    #vi/etc/dovecotsql.conf

    driver=mysqlconnect=host=127.0.0.1dbname=mailuser=mail_adminpassword=123#abcdefault_pass_scheme=CRYPTpassword_query=SELECTemailasuser,passwordFROMusersWHEREemail="%u"

    Gnquyntruycpchofilenynhsau

    #chgrpdovecot/etc/dovecotsql.conf#chmodo=/etc/dovecotsql.conf

    Khinglidovecot

    #servicedovecotrestart

    Bc12.Kimtraktqucaccbctrn

    Kimtralogmbodchvdovecotchyvkoclig

    #tailf/var/log/maillog

    Nuc2dngsaulok(xemthmhnhchp):Dovecotv1.0.7startingup:mysql:Connectedto127.0.0.1(mail)

    KimtradchvPOP3glnhtelnetlocalhostpop3vnuthythngbo+OKDovecotreadylc

    #telnetlocalhostpop3

    Trying127.0.0.1...Connectedtolocalhost.localdomain.Escapecharacteris"^]".+OKDovecotready.

    Gquitthot.

    Bc13.Toaliasvkimtrashotngcapostfix

    Mfilealiasesvthmmtdnggnbdanhchorootnhsau

    #vi/etc/aliases

    thmdng:

    root:mail_admin

    Sauchylialiasvkhinglipostfix

    #newaliases

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 5/6

    #servicepostfixrestart

    Kimtradchvpostfixbnglnhsau

    #telnetlocalhost25

    Saukimtratheohnhsau,nuthygingnhhnhnylok

    Bc14:Btutoccdomainvemailaccount

    Sauccbctrncthcoinhphnohavktnipostfixvidatabasexongchngtacthtoccdomainvemailgnvidomaincri.Bctoemailaccountnycthdngphpmyadminhocvitmtscriptphpto,qunlemailchonchuynnghip.y,vimcchtestchngtasdngdnglnhtomtdomaintnlmailtest.comvmtemailtnlhai@mailtest.com.

    Trctin,chngtakhaibotnminnyvofilehostsgilpmtbnghiDNS

    #vi/etc/hosts

    Thmdngsau

    127.0.0.1mailtest.com

    Saubtukhaibodomainnyviusertesttrongcsdliu

    #mysqlurootpmysql>USEmailmysql>INSERTINTOdomains(domain)VALUES("mailtest.com")mysql>INSERTINTOusers(email,password)VALUES("[email protected]",ENCRYPT("123456"))mysql>quit

    accountmailnycthtruycpImaphayPop3thtaphigi1mail(welcomemessage)chouserbngmttinchgimailsnccalinux,hyglnhnhsau

    #mails"xinchao"[email protected]

    Gnidungemailngaysaulnhtrn,saubmCtrlD2ln(lnthnhtnhiccthmachcc,lnth2ktthcvgimail)

    Sauvothmc/home/vmailkimtra,numithOKbnsnhnthythmcmailtest.comvtrongmailtest.comlicthmchaichaccemailcahai@mailtest.com.Tmlinubnvocngdnny/home/vmail/mailtest.com/hai/Maildir/newvthymtfilethdchnhlemailvacgibngtinchnitrnvnhvypostfixhotngtt.

    Bc15:Checkmailthcsvioutlook

    cthcheckmailtmtmytnhbtkdngoutlook,bncnphicmtdomainvcquyntrbnghichodomainny.Gisbncdomainlthuonghieuweb.com,hytrccbnghicnthitchoemailtimyachcamychnitrn(bnghiAvbnghiMX)victrbnghikhngcpntrongny.Bnhylmsaosaukhitrbnghibnsphipingthnhcngnachmail.thuonghieuweb.comvthylnctrnipcamychny.

    Saubnlplibc14(nhngbquaonsafilehostsvtrtnmintDNSserverri)[email protected].

    Moutlooktrnmycabnvkhaibomtaccountminhhnhsau:

  • 17/6/2015 Xydngmailserverpostfixvqunlemailbngphpmysql

    http://thuonghieuweb.com/content/xaydungmailserverpostfixvaquanlyemailbangphpmysql.html 6/6

    Xemthm...

    Cclnhlinuxthngdng(phn2)HngdnciApache,PHP,MySQLtrnCentOSKhcphclikhnggimailthngbochousercaDirectAdminNngcpPHP5.1.xlnPHP5.3.28MtslnhqunlMySQLbnnnbitBomtwebsitebngcuhnhapacheMtsththutivilinuxCclnhLinuxthngdngToccnhtuyntnhtrongCentosHngdncuhnhdchvftpchoCentosXllieximdeadbutsubsyslockedvqunlmailqueueeximNgnchnspamtcchostingtrongDirectAdminHngdncitmailservertrnlinuxMtslnhthngdngqunlmailserverpostfixLmthnoghostubuntuHngdncuhnhcardmngchoubuntuHngdncuhnhcardmngchoCentosHngdnxllimysqlvphpmyadminCutrcthmcchuncalinuxHngdnxlliconnectiontostorageserverfailedkhidngmailcadirectadmin8bctoemailgnvitnmincngtyminphtrnlive.comBomtcchostingsdngapachevphpHngdncitsquirrelmailtrnmailserverpostfixChngDDOSviiptables

    Saukhikhaiboccthamsnhhnhtrn,bmvotestaccountsettingnuc2bcgi,nhnmailuxanhlOK.cnnukhnghyxemthngbolilgcthkimtrali.

    Outlooklmvicrtttvihthngmailpostfixohanytuynhintrongmtstrnghp,chnghnicngtcxa,chngtacncheckmailbngwebmailthcncitthmmtdchvna.HngdncitwebmailctrongbivitHngdncitdchvsquirrelmailgnvipostfix,ccbncthtiptctmhiuthm.

    Chcccbnthnhcng

    0

    BnquynthucvVnphng:Tng4,Tonh65l5,nLII,HongVnTh,HongMai,HNiinthoi(04)39909643Hotline:0989848886Email:[email protected]:www.thuongthieuweb.com

    cbovbnquynbi

    +1usongoogleplus

    1Chias Gi