ads

วันศุกร์ที่ 10 กรกฎาคม พ.ศ. 2558

MailCatcher สำหรับทดสอบ internal SMTP

MailCatcher สำหรับทดสอบ SMTP internal 

ต้องลง lib สำหรับใช้คำสั่ง gem ให้ได้เสียก่อน
#yum install rubygems
#yum groupinstall -y development
# gem install mailcatcher
** จะฟ้อง error ต้องการ i18n ให้ทำตาม link นี้
https://cleanclouds.wordpress.com/2014/12/20/error-error-installing-rails-i18n-requires-ruby-version-1-9-3/
# yum groupinstall -y development
# curl -L get.rvm.io | bash -s stable
จะฟ้อง
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.26.5.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.5/1.26.5.tar.gz.asc'!
try downloading the signatures:
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
สั่ง
# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
# curl -L get.rvm.io | bash -s stable
# source /etc/profile.d/rvm.sh
รอจนเสร็จตามด้วย เพื่อลง ruby
# rvm install 1.9.3
เมื่อเสร็จจะมีข้อความบอก ทดสอบดูเวอร์ชั่น ruby ว่าถูกต้องไหม
# ruby --version
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
ระบบ mailcatcher จะทำงานเป็น deamon ตาม lib ของ ruby

เมื่อพร้อมกลับมา install mailcatcher ได้แล้ว
# gem install mailcatcher
แล้วก็รอไป (นานมากกก)
หากเราจะทำการทดสอบด้วยการส่งเมล์ผ่านะโค๊ด PHP ให้เราเข้าไปแก้ configure ของ php.ini ในส่วนของ mail option เสียก่อน ดังนี้
# vi /etc/php.ini

smtp_port = 1025
sendmail_from = me@example.com
sendmail_path = /usr/local/rvm/gems/ruby-1.9.3-p551/bin/catchmail --smtp-ip 0.0.0.0 --smtp-port 1025 -f me@example.com

แล้วทำากร restart httpd หนึ่งรอบ
# /etc/init.d/httpd restart
เมื่อเรียบร้อยแล้วทำการ start การทำงาน ของ MailCatcher
# mailcatcher --http-ip 0.0.0.0 --smtp-port 1025
จะมีข้อความบอกว่า mailcatcher สตาร์ทและทำงานแล้ว
webbrowser ของ server ip นั้นและตามด้วยพอร์? 1080
ส่วน smtp ตั้งเป็น port 1025
เมือเข้าไป http://ipaddress:1080/ จะพบ browser แสดงเมล์ที่ส่งผ่าน smtp ที่เราทดสอบ
ต่อไปสร้างโค๊ด php ทดสอบในการส่งว่าจะเข้าหรือไม่ดังนี้
# vi mail.php
<?php $headers = 'From: webmaster@example.com'; mail('nobody@example.com', 'Test email using PHP', 'This is a test email message', $headers, '-fwebmaster@example.com'); ?>

แล้วทำการสั่งเพื่อทดสอบดู
# php mail.php
และกด refresh ดูหน้า http://ipaddress:1080/ จะเห็นว่า MailCatcher เก็บเมล์นั้นได้แล้ว


วันศุกร์ที่ 3 กรกฎาคม พ.ศ. 2558

ติดตั้ง jira & confluence ให้รองรับ SSL ผ่าน port 433 ทั้งคู่

ติดตั้ง jira & confluence ให้รองรับ SSL ผ่าน  port 433 ทั้งคู่

- ติดตั้ง mod_ssl ให้ apache รองรับการทำงานของ ssl
#  yum install mod_ssl

สร้าง dir เพื่อเก็บ key ที่เราได้มาใช้งาน
# mkdir -p /etc/httpd/ssl/
นำ key และ cert มาเก็บไว้ทีนี่
-rw-r--r-- 1 root root 1674 Jun 23 13:55 DigiCertCA.crt
-rw-r--r-- 1 root root 1900 Jun 23 13:55 star_YourDomain_co_th.crt
-rw-r--r-- 1 root root 1704 Jun 23 13:55 star_YourDomain_co_th.key

stop service ทุกอย่างก่อน
# /etc/init.d/jira stop
# /etc/init.d/confluence stop
# /etc/init.d/httpd stop

แก้ไฟล์คอนฟิกของ jira  ที่ /usr/atlassian/jira/conf/server.xml   ดังนี้

<?xml version="1.0" encoding="utf-8"?>
<Server port="8005" shutdown="SHUTDOWN">
    <!--APR library loader. Documentation at /docs/apr.html -->
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
    <Listener className="org.apache.catalina.core.JasperListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
    <Service name="Catalina">
        <Connector port="8080"
                   maxThreads="150"
                   minSpareThreads="25"
                   connectionTimeout="20000"
                   enableLookups="false"
                   maxHttpHeaderSize="8192"
                   protocol="HTTP/1.1"
                   useBodyEncodingForURI="true"
                   redirectPort="8443"
                   acceptCount="100"
                        scheme="https"
                        proxyName="jira.YourDomain.co.th"
                        proxyPort="443"

                   disableUploadTimeout="true"/>
        <Engine name="Catalina" defaultHost="localhost">
            <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
                <Context path="" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">


แก้ไขไฟล์คอนฟิก ของ confluence  ที่  /usr/atlassian/confluence/conf/server.xml  ดังนี้

<Server port="8000" shutdown="SHUTDOWN" debug="0">    <Service name="Tomcat-Standalone">        <Connector port="8090" connectionTimeout="20000" redirectPort="8443"                maxThreads="200" minSpareThreads="10"                enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" proxyName="wiki.YourDomain.co.th" proxyPort="443" scheme="https" />
            <Engine name="Standalone" defaultHost="localhost" debug="0">            <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="false">                <Context path="" docBase="../confluence" debug="0" reloadable="false" useHttpOnly="true">                    <!-- Logger is deprecated in Tomcat 5.5. Logging configuration for Confluence is specified in confluence/WEB-INF/classes/log4j.properties -->                    <Manager pathname="" />                </Context>            </Host>
        </Engine>
    </Service></Server>


แก้ไขไฟล์ httpd.conf  ที่   /etc/httpd/conf/httpd.conf   ดังนี้

Listen 80 443
NameVirtualHost *:443
NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin itinfrasystem@YourDomain.co.th
        ServerName jira.YourDomain.co.th
        RewriteEngine On
        RewriteRule ^/(.*)      https://%{HTTP_HOST}/$1 [R]
</VirtualHost>
<VirtualHost *:443>
        ServerAdmin itinfrasystem@YourDomain.co.th
        ServerName jira.YourDomain.co.th
        SSLEngine On
        SSLCertificateKeyFile /etc/httpd/ssl/star_YourDomain_co_th.key
        SSLCertificateFile /etc/httpd/ssl/star_YourDomain_co_th.crt
 ####### JIRA is running on port 8080/443 local on localhost
        ProxyRequests Off
        ProxyPreserveHost On
        SSLProxyEngine on
        ProxyPass / http://localhost:8080/ connectiontimeout=5 timeout=300
        ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin itinfrasystem@YourDomain.co.th
        ServerName wiki.YourDomain.co.th
        RewriteEngine On
        RewriteRule ^/(.*)      https://%{HTTP_HOST}/$1 [R]
</VirtualHost>
<VirtualHost *:443>
        ServerAdmin itinfrasystem@YourDomain.co.th
        ServerName wiki.YourDomain.co.th
        SSLEngine On
        SSLCertificateKeyFile /etc/httpd/ssl/star_YourDomain_co_th.key
        SSLCertificateFile /etc/httpd/ssl/star_YourDomain_co_th.crt
 ####### WIKI is running on port 8090/443 local on localhost
        ProxyRequests Off
        ProxyPreserveHost On
        SSLProxyEngine on
        ProxyPass / http://localhost:8090/ connectiontimeout=5 timeout=300
        ProxyPassReverse / http://localhost:8090/
</VirtualHost>

ทดสอบค่า configure ดู
# /etc/init.d/httpd configtest

ทำการ start service ทังหมดแล้วทดสอบใช้งานดู
# /etc/init.d/jira start
# /etc/init.d/confluence start
#  /etc/init.d/httpd start

เมือ service สตาร์ทผ่านหมด  รันผ่าน ssl port 443 ได้ครบ   เข้าไปเปลี่ยน system url ด้วย
jira = login > ฟันเฟือง system > Edit settings
ที่ Server Base URL http://jira.YourDomain.co.th  เป็น https://jira.YourDomain.co.th

confluence = login > ฟันเฟือง Gerneral configure > Edit
ที่ Server Base URL http://wiki.YourDomain.co.th   ไปเป็น  https://wiki.YourDomain.co.th