MySql Trigger - Basic

Trigger คือการแทรกการกระทำ (Method/Function) ลงไว้ใน Database โดยสามารถใส่เงื่อนไขต่างๆได้เหมือนกับภาษาโปรแกรมทั่วไปครับ โดยเมื่อเกิด Query ใน Mysql แล้วตัว Database จะทำการไล่ Check ว่ามี Trigger ไหนตรงตามเงื่อนไขบ้าง และเรียกใช้งาน

การใช้ Trigger เป็นเหมือนดาบสองคม มีทั้งข้อดีแล้วข้อเสียครับ จะแจกแจงคร่าวๆเท่าที่พอนึกออกไว้ให้ครับ

+ ดูดีมีชาติตระกูล เร็ว (เร็วกว่าที่ส่งข้อมูลไปๆมาๆระหว่าง Mysql กับ Php/Server-side script อื่นๆ)

+ ทำบางอย่างที่ทำด้วยโค้ด Server-side script มาตราฐานไม่ได้ หรือไม่สะดวกนัก โดยการ Hook เข้าไปในระบบของ DB เลย

- Debug ยาก ยิ่งมีภาษาเพิ่มเข้ามาอีก ยิ่งเพิ่มความปวดหัว

- ยึดติดกับ Platform เนื่องจาก Trigger ไม่มีมาตราฐานชัดเจน ทำให้เมื่อย้ายไปใช้ตัวอื่นจะต้องศึกษาใหม่

Replacement

จริงๆ ในหลายๆกรณีก็ไม่จำเป็นต้องใช้ Trigger เช่นการ Update Table ที่เป็น Foreign key โดยสามารถใช้คำสั่ง Cascade ช่วยได้

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

Mysql Trigger พื้นฐาน

หน้าตาตัวอย่าง TriggerCREATE TRIGGER trigger_name BEFORE UPDATE ON table_name FOR EACH ROW BEGIN IF NEW.dirty=0 OR NEW.dirty=1 THEN SET NEW.dirty=1; ELSE SET NEW.dirty=0; END IF; END;

  • CREATE TRIGGER trigger_name คำสั่งสร้าง Trigger
  • BEFORE UPDATE Event หลักๆที่เราสามารถ Hook trigger ของเราเข้าไปได้ ได้แก่ INSERT, UPDATE, DELETE โดยสามารถเลือกว่าจะทำการ Hook ก่อนหรือหลัง (BEFORE / AFTER) Query เหล่านั้นได้
  • ON table_name เลือก Table ที่ต้องการให้ Trigger ทำงาน
  • หมายถึงข้อมูลเก่าก่อนที่จะเกิดการรัน Query นั้นๆ
  • นอกจากนี้ยังสามารถแทรก Query มาตราฐาน (INSERT,UPDATE,DELETE และอื่นๆ) ลงใน Trigger ได้เลยอีกด้วย ซึ่งเราสามารถนำตัวแปร ROW,OLD,NEW มาใช้งานได้เช่นกัน

สร้าง Trigger บน phpMyAdmin

ถ้าได้ลองเอาโค้ดตัวอย่างไปลอง Run ใน phpMyAdmin จะพบว่าไม่สามารถทำงานได้ ด้วย Error ที่อ่านไม่ค่อยจะเข้าใจนัก

เหตุผลphpMyAdmin ไม่สามารถ Run คำสั่งนี้ได้ เนื่องจากเกิดการสับสนเรื่อง Delimiter ของ Mysql กับ คำสั่งใน Trigger

วิธีการแก้ไข แก้ได้ด้วยการ เปลี่ยน Delimiter เป็นตัวอักษรอื่นแทน semicolon “;” ตามรูป

เปลี่ยน Delimiter ใน phpMyAdmin

ในตัวอย่างเปลี่ยนเป็น ;; แทนครับ โดยถ้าหากเราต้องการสั่งให้ phpMyAdmin ทำงานหลายๆ Query พร้อมกันก็ให้ใส่ ;; แทน ;

credit:http://blog.levelup.in.th/2009/06/29/mysql-trigger-basicmysql-trigger-basic/

  • Comments Off
InstallingBigBlueButton

How to install BigBlueButton like a real developer. :-)

These instructions will walk through how to install BigBlueButton from source onto Ubuntu. If you are using CentOS, seeInstallingBigBlueButtonCentOS. In most cases, you’ll want to install from packages, but if you want to really understand how BigBlueButton is setup, the following steps will show you how to install each component.

To start, you’ll need a computer running Ubuntu — either a physical machine or a virtual machine (VM). The easiest way to start with a VM images is to download a Ubuntu VM image from http://www.vmware.com/appliances/directory/va/147323/download and start it in VMWare Player

The only prerequisite is that your Ubuntu machine has a network connection.

  • To start, check if you have a network connection
  •  > ping www.google.com
    
    If you get an error saying yout eth0 is not connected, then fix it by:
    
      Check if it is using eth1 
    
    root@ubuntu904server:/usr/local# ifconfig -a
    eth1      Link encap:Ethernet  HWaddr 00:0c:29:dd:b4:51
              inet addr:192.168.0.154  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fedd:b451/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:4080349 errors:0 dropped:0 overruns:0 frame:0
              TX packets:3932137 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:1216680270 (1.2 GB)  TX bytes:822963271 (822.9 MB)
              Interrupt:19 Base address:0×2000
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:12938 errors:0 dropped:0 overruns:0 frame:0
              TX packets:12938 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:40299608 (40.2 MB)  TX bytes:40299608 (40.2 MB)
    
    root@ubuntu904server:/usr/local# vi /etc/udev/rules.d/70-persistent-net.rules
    Swap the two entries by eidting “NAME=eth1″ to “NAME=eth0″ and vice versa.
    
    Reboot your machine. 
    Check if you manage to connect to the internet. 
    If you are running on a Virtual Machine, make sure the VM’s network adapter is using a Bridged connection instead of NAT. 
    On the VMWare player this is enabled in the Devices menu at the top.
    
    More info can be found here http://ubuntuforums.org/showthread.php?t=221768
  • Once you have interner connection, update and upgrade.
  •   > sudo apt-get update
      > sudo apt-get upgrade
  • Install Java 6
  •  > apt-get install openjdk-6-jre-headless
  • Install MySQL
  •  > apt-get install mysql-server
  • Install Tomcat
  •   > apt-cache search tomcat
    
      > apt-get install tomcat6
  • Confirm that tomcat is running
  •   http://<YOUR IP>:8080/
  • Install swftools
  •   > apt-get install swftools
  • Install ImageMagick
  •   > apt-get install imagemagick
  • Install Nginx
  •   > apt-get install nginx
  • Install ActiveMQ
  •   > cd opt
      > wget http://apache.mirror.rafal.ca/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz
      > tar zxvf apache-activemq-5.2.0-bin.tar.gz
    
      Start ActiveMQ
      > /opt/apache-activemq-5.2.0/bin/activemq
  • Modify tomcat6 account
  •  > vi /etc/passwd
    
     Modify tomcat6 entry to this
      tomcat6:x:106:113::/usr/share/tomcat6:/bin/bash
  • Install red5
  •   > cd opt
      > wget http://build.xuggle.com/job/red5_jdk6_stable/131/artifact/workingcopy/red5-0.8.RC3-build-hudson-red5_jdk6_stable-131.tar.gz
      > tar zxvf red5-0.8.RC3-build-hudson-red5_jdk6_stable-131.tar.gz
      > mv red5-0.8.RC3-build-hudson-red5_jdk6_stable-131 red5-0.8
    
      Start red5 as tomcat6 user
      > sudo su -l tomcat6
      > red5.sh
  • Install oflaDemo
  • http://192.168.0.154:5080/
    
    Click on “Click here to install demos” and then choose oflaDemo java 6.
    
    http://192.168.0.154:5080/demos/
    
    http://192.168.0.154:5080/demos/ofla_demo.html
    
    Edit rtmp://192.168.0.154/oflaDemo and click connect
    
    You would see a list of available videos. Select one to play.
  • Prepare to install Asterisk
  • Some info found here http://godson.in/how-to-install-asterisk-on-ubuntu
    
     > apt-get install build-essential
     > apt-get install linux-headers-`uname -r`
     > apt-get install libssl-dev
     > apt-get install ncurses-dev
     > apt-get install libnewt-dev
     > apt-get install zlib1g-dev
     > apt-get install bison
  • Install Dahdi

You may have to find out what the newest version is. Go here

 > cd /usr/local/src
 > wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.2.0.2+2.2.0.tar.gz
 > tar zxvf dahdi-linux-complete-2.2.0.1+2.2.0.tar.gz
 > cd dahdi-linux-complete-2.2.0.1+2.2.0
 > make all
 > make install
 > make config
  • Install Asterisk
  •   > cd /usr/local/src
      > wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.4.25.tar.gz
      > tar zxvf asterisk-1.4.25.tar.gz
      > cd asterisk-1.4.25
      > more README
      > ./configure
      > make
      > make install
      > make samples
      > make config
  • Modify Extensions
  • cd /tmp/
    wget http://bigbluebutton.googlecode.com/files/asterisk-extensions.conf
    cat asterisk-extensions.conf >> /etc/asterisk/extensions.conf 
  • Create SIP account
  • wget http://bigbluebutton.googlecode.com/files/asterisk-sip.conf
    cat asterisk-sip.conf >> /etc/asterisk/sip.conf
  • Create SIP Accounts to be used by Red5Phone
  • wget http://bigbluebutton.googlecode.com/files/asterisk-create-sip-accounts.sh
    chmod a+x asterisk-create-sip-accounts.sh
    ./asterisk-create-sip-accounts.sh
  • Test your SIP account
  •  Download Zoiper from here http://www.zoiper.com/zwin.php
    
     After installing Zoiper, start it and create a SIP account using the echotest user above.
    
     Then dial 600. You should be connected to the “Echo” application.
  • Create AMI account
  •  > vi /etc/asterisk/manager.conf
    
     Modify “enabled” to yes
    
    [general]
    
    enabled = yes
    
      Add the following at the bottom of the file
    
    ; BigBlueButton: Enable Red5 to connect
    [bbb]
    secret = secret
    permit = 0.0.0.0/0.0.0.0
    read = system,call,log,verbose,command,agent,user
    write = system,call,log,verbose,command,agent,user
  • Configure Nginx
  •  > vi /etc/nginx/sites-available/bigbluebutton
    
     Paste the following into the file and edit server_name with you IP.
    
    server {
         listen   80;
         server_name  192.168.0.136;
    
         access_log  /var/log/nginx/bigbluebutton.access.log;
    
          location ~ (/open/|/close/|/idle/|/send/) {
              proxy_pass         http://127.0.0.1:8088;
              proxy_redirect     off;
              proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    
              client_max_body_size       10m;
              client_body_buffer_size    128k;
    
              proxy_connect_timeout      90;
              proxy_send_timeout         90;
              proxy_read_timeout         90;
    
              proxy_buffering            off;
          }
    
           location /deskshare {
               proxy_pass         http://127.0.0.1:5080;
               proxy_redirect     default;
               proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
               client_max_body_size       10m;
               client_body_buffer_size    128k;
               proxy_connect_timeout      90;
               proxy_send_timeout         90;
               proxy_read_timeout         90;
               proxy_buffer_size          4k;
               proxy_buffers              4 32k;
               proxy_busy_buffers_size    64k;
               proxy_temp_file_write_size 64k;
               include    fastcgi_params;
           }
    
           location /bigbluebutton {
               proxy_pass         http://127.0.0.1:8080;
               proxy_redirect     default;
               proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    
               client_max_body_size       10m;
               client_body_buffer_size    128k;
    
               proxy_connect_timeout      90;
               proxy_send_timeout         90;
               proxy_read_timeout         90;
    
               proxy_buffer_size          4k;
               proxy_buffers              4 32k;
               proxy_busy_buffers_size    64k;
               proxy_temp_file_write_size 64k;
    
               include    fastcgi_params;
           }
    
            location / {
              root   /var/www/bigbluebutton-default;
              index  index.html index.htm;
            }
    
            location /client {
                    root    /var/www/bigbluebutton;
                    index  index.html index.htm;
            }
    
            #error_page  404  /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                    root   /var/www/nginx-default;
            }
    }
  • Enable the bigbluebutton nginx config
  • > ln -s /etc/nginx/sites-available/bigbluebutton /etc/nginx/sites-enabled/bigbluebutton
  • Download BigBlueButton
  •  > mkdir /home/user/temp
     > cd /home/user/temp
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Apps/ws/dist/bigbluebutton-apps-0.5.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Apps-Deskshare/ws/dist/webapps/deskshare.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Client/ws/client.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Web/ws/bigbluebutton-0.1.war
     > wget http://www.bigbluebutton.org/hudson/job/BBB-Trunk-Config/ws/web//*zip*/web.zip
     > wget http://www.bigbluebutton.org/hudson/job/bbb-trunk-apps-sip/ws/dist/webapps/sip.tar.gz
     > wget http://www.bigbluebutton.org/hudson/job/bbb-trunk-apps-video/ws/dist/webapps/video.tar.gz
  • Disable Security settings for TOMCAT6
  •   > vi /etc/default/tomcat6
    
      Edit and uncomment #TOMCAT6_SECURITY=yes to
    
      TOMCAT6_SECURITY=no
  • setup the database
  •  > mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 33
    Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
    
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
    
    mysql> create database bigbluebutton_dev;
    Query OK, 1 row affected (0.05 sec)
    
    mysql> grant all on bigbluebutton_dev.* to ‘bbb’@‘localhost’ identified by ’secret’;
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> commit;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
  • Install BigBlueButton Web
  •  > cd /var/lib/tomcat6/webapps
     > cp /home/user/temp/bigbluebutton-0.1.war ./bigbluebutton.war
  • Determine PDF2SWF, CONVERT and GS applications
  •   Make a note of where pdf2swf is installed
      > which pdf2swf
    
      You should see something like
      /usr/bin/pdf2swf
    
      Make a note of where the convert application is installed
      > which convert
    
      You shoud see something like.
      /usr/bin/convert
    
      Note where GhostScript is installed
      > which gs
    
      You shoud see something like.
      /usr/bin/gs
  • Edit bbb-web properties
  •  > vi /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
    
    Change the following:
     - swfToolsDir to the directory where pdf2swf is located
     - imageMagickDir to the directory where convert is located
     - ghostScriptExec to point to the gs application
     - change bigbluebutton.web.serverURL=http://<YOUR IP>
    
    Your bigbluebutton.properties should resemble something like this
    
    #
    # These are the default properites for BigBlueButton Web application
    
    dataSource.url=jdbc:mysql://localhost/bigbluebutton_dev
    dataSource.username=bbb
    dataSource.password=secret
    
    swfToolsDir=/usr/bin
    imageMagickDir=/usr/bin
    presentationDir=/var/bigbluebutton
    ghostScriptExec=/usr/bin/gs
    
    beans.presentationService.swfToolsDir=${swfToolsDir}
    beans.presentationService.imageMagickDir=${imageMagickDir}
    beans.presentationService.presentationDir=${presentationDir}
    
    # Use fullpath to ghostscript executable since the exec names are different
    # for each platform.
    beans.presentationService.ghostScriptExec=${ghostScriptExec}
    
    #
    # This URL needs to reference the host running the tomcat server
    bigbluebutton.web.serverURL=http://192.168.0.154
    
    # This is a workaround for a problem converting PDF files, referenced at
    # http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/c2e264ca76534ce0?pli=1
    noPdfMarkWorkaround=/etc/bigbluebutton/nopdfmark.ps
    beans.presentationService.noPdfMarkWorkaround=${noPdfMarkWorkaround}
  • Restart Tomcat6
  •  > /etc/init.d/tomcat6 restart
  • Check if database tables were created
  •  > mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 56
    Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
    
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
    
    mysql> use bigbluebutton_dev;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +—————————–+
    | Tables_in_bigbluebutton_dev |
    +—————————–+
    | account                     |
    | account_conference          |
    | account_user                |
    | conference                  |
    | permission                  |
    | role                        |
    | role_permission_rel         |
    | scheduled_session           |
    | user                        |
    | user_permission_rel         |
    | user_role_rel               |
    | voice_conference_bridge     |
    +—————————–+
    12 rows in set (0.00 sec)
    
    mysql> select * from user;
    +—-+———+———————+———–+———————+——————————————+—————-+
    | id | version | date_created        | full_name | last_updated        | password_hash                            | username       |
    +—-+———+———————+———–+———————+——————————————+—————-+
    |  1 |       0 | 2009-06-29 09:51:17 | Admin     | 2009-06-29 09:51:17 | d033e22ae348aeb5660fc2140aec35850c4da997 | admin@test.com |
    +—-+———+———————+———–+———————+——————————————+—————-+
    1 row in set (0.02 sec)
    
    mysql>
  • Create the Presentation Upload directory
  •  > mkdir /var/bigbluebutton
     > chown -R tomcat6:adm /var/bigbluebutton
     > chmod -R 777 /var/bigbluebutton
  • Install bbb-apps
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/bigbluebutton-apps-0.5.tar.gz ./
    
     > tar zxvf bigbluebutton-apps-0.5.tar.gz
     >  mv webapps/bigbluebutton ./
     > rm -rf bigbluebutton-apps-0.5.tar.gz webapps/
  • Edit BigBlueButton Apps properties
  •  > vi /opt/red5-0.8/webapps/bigbluebutton/WEB-INF/bigbluebutton.properties
    
    # Location for recordings
    recordingsDirectory=/var/bigbluebutton
    
    # These properties are for Asterisk Management Interface (AMI)
    ami.host=127.0.0.1
    ami.port=5038
    ami.username=bbb
    ami.password=secret
  • Uncommet RTMPT section of /opt/red5-0.8/conf/red5-core.xml
  • Install Xuggler
  •  Goto http://www.xuggle.com/xuggler/downloads/
    
      > cd /usr/local
      >  wget http://com.xuggle.s3.amazonaws.com/xuggler/xuggler-3.1.FINAL/xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
    
      > chmod a+x xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
      > ./xuggle-xuggler.3.1.818-i686-pc-linux-gnu.sh
  • Put Xuggler into PATH
  •   >  vi /etc/profile
    
     Add the following at the bottom of the file
    
    export XUGGLE_HOME=/usr/local/xuggler
    export LD_LIBRARY_PATH=$XUGGLE_HOME/lib:$LD_LIBRARY_PATH
    export PATH=$XUGGLE_HOME/bin:$PATH
  • Install Desk Share App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/deskshare.tar.gz ./
     > tar zxvf deskshare.tar.gz
     >  rm deskshare.tar.gz
  • Install Video App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/video.tar.gz ./
     > tar zxvf video.tar.gz
     >  rm video.tar.gz
  • Install Voice App
  •  > cd /opt/red5-0.8/webapps
     > cp /home/user/temp/sip.tar.gz ./
     > tar zxvf sip.tar.gz
     >  rm sip.tar.gz
    
     Edit /opt/red5-0.8/webapps/sip/WEB-INF/bigbluebutton-sip.properties
    
     Point sip.server.host to the IP of your Asterisk installation
    
     sip.server.host=192.168.0.177
  • Install BigBlueButton Client
  •   > cd /var/www
      > mkdir bigbluebutton
      > cd bigbluebutton
      > cp /home/user/temp/client.tar.gz ./
      > tar zxvf client.tar.gz
      > rm client.tar.gz
  • Modify BBB client config in /var/www/bigbluebutton/client/conf/config.xml
  •  - Change the uri to your IP address
     - Change host=“conf/join-mock.xml” to host=“http://<YOUR IP:PORT>/bigbluebutton/conference-session/enter”
    
    <?xml version=“1.0″ ?>
    <config>
        <version>0.4</version>
        <porttest host=”192.168.0.136″ application=”video”/>
            <modules>
    
                    <module name=“VideoModule” url=“VideoModule.swf”
                            uri=“rtmp://192.168.0.136/video”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ChatModule” url=“ChatModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            loadNextModule=“PresentationModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ViewersModule” url=“ViewersModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            host=“conf/join-mock.xml”
                            onAppInitEvent=“LOAD” loadNextModule=“ChatModule”
                            onAppStartEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“ListenersModule” url=“ListenersModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            recordingHost=“http://192.168.0.136″
                            loadNextModule=“DeskShareModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
                    <module name=“PresentationModule” url=“PresentationModule.swf”
                            uri=“rtmp://192.168.0.136/bigbluebutton”
                            host=“http://192.168.0.136″
                            loadNextModule=“ListenersModule”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                    />
    
                    <module name=“DeskShareModule” url=“DeskShareModule.swf”
                            uri=“rtmp://192.168.0.136/deskShare”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                            loadNextModule=“PhoneModule”
                    />
    
                    <module name=“PhoneModule” url=“PhoneModule.swf”
                            uri=“rtmp://192.168.0.136/sip”
                            onUserJoinedEvent=“START”
                            onUserLogoutEvent=“STOP”
                            loadNextModule=“VideoModule”
                    />
            </modules>
    </config>
  • Install bbb-default pages
  •   > cd /var/www/
      > cp /home/user/temp/web.zip ./
      > apt-get install unzip
      > unzip -dc web.zip
      > mv c/web ./bigbluebutton-default
      > rm -rf c
  • Restart server apps
  •  * Start ActiveMQ
     * Start Red5 as tomcat6 user
     * Restart Tomcat
     * Restart Asterisk 
  • Try out BigBlueButton
  •  Go to http://<YOUR-IP> which should display the bbb web page.
    
     To use voice conference, using your zoiper, dial 1500 which will prompt you for the conference number.

BigBlueButton-dev letting everyone know that you are a real developer and you have installed BigBlueButton from source. :-)

  • Comments Off

MRTG on Ubuntu Server

Lets start by installing the goods. Then we will get into the meat of things.

apt-get install snmpd mrtg apache2

When installing MRTG it will ask if you want to only make /etc/mrtg.cfg readable by the MRTG user. In my case, this will be an internal server only, and I do not need to worry about security, so I am going to select NO. If you choose YES, the steps in this tutorial may not work. I have not tested this. However, keep in mind if security is a concern, you may want to go this route and keep MRTG contained in a non-root user environment.

Assuming that you want to monitor your networking equipment with MRTG, you need to set up the snmp community on the piece of equipment. Usually its just a matter of enabling snmp, and the default community will be public. If you change the default community to another name, make sure you remember the name for later.

Now lets set up MRTG to read the data.
With Ubuntu server, MRTG will automatically set up /var/www/mrtg. In other distrobutions, it will set it up in a different area, so you will need to change the ‘WorkDir:’ variable in the following scenario to the directory where MRTG is installed.

I’m going to create an /etc/mrtg directory rather then move the mrtg.cfg file within /etc/ This will make it less confusing in the future.

mkdir /etc/mrtg

mv /etc/mrtg.cfg /etc/mrtg/

Now we run the cfgmaker command to get things up and running:

cfgmaker –global ‘WorkDir:/var/www/mrtg’ –global ‘Options[_]: bits,growright’ –output /etc/mrtg/mrtg.cfg public@<yourrouterip>

We need to make sure the following lines are correct in /etc/mrtg/mrtg.cfg If they are not there, add them.

EnableIPv6: no
RunAsDaemon: Yes
Interval: 5
Logdir: /var/log/mrtg

Now run:

indexmaker –output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

Which will build the index so you can view the output.

Then I run this command to set an environmental variable

env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

and open http://localhost/mrtg/index.html

You should now see an output graph.

crontab -e
0,5,10,15,20,25,30,35,40,45,50,55 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –logging /var/log/mrtg.log

Let cron pick up stats for an hour or so. After a while, you will see that your graphs are picking up data about your bandwidth.

Here is mine with several cisco 2811 routers configured to show bandwidth.

SNMP and MRTG can monitor much more then bandwidth. For instance you can monitor disk usage, processing use, and more on your servers. There is plenty of documenation on the subject, which leans towards going in and adding snmpd to the servers you want to monitor, setting it up, and then going back and executing the cfgmaker and indexmaker command again so that the new hardware will show up on the page. Because the output of these files is an html page, you can also skin the page and make it look nicer, or embed it into your favorite CMS.

I encourage you to play around with MRTG, because it is the foundation program for a lot of software suites that monitor traffic. One of those, we will talk about next time. Until then, keep hackin.

  • Comments Off

A fax server with IAXmodem and Hylafax

The IAXmodem application emulates a faxmodem, which may be operated by a fax application of the administrator’s choosing. We’ll use the popular Hylafax. For simplicity and consistency, the installation platform will be the same Debian Linux and Asterisk 1.4 we have used for the other examples (see the section called “Installing Asterisk 1.4.x on Debian Linux 4.0 (Etch)”).
Installing IAXmodem

IAXmodem simulates a faxmodem and makes it available to Asterisk via IAX2. All the steps in this chapter must be performed as the root user.

To install IAXmodem, we need some additional Debian packages, which may be installed with the command apt-get -y install g++ libtiff-tools libtiff4 libtiff4-dev.

debian:~# apt-get -y install g++ libtiff-tools libtiff4 libtiff4-dev
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Die folgenden zusätzlichen Pakete werden installiert:
g++ libjpeg62 libjpeg62-dev libtiffxx0 zlib1g-dev

[...]

Richte zlib1g-dev ein (1.2.2-4.sarge.2) …
Richte libtiff4-dev ein (3.7.2-7) …

debian:~#

We switch into the appropriate directory with cd /usr/src to install the IAXmodem source code:

debian:~# cd /usr/src
debian:/usr/src#

The sources for IAXmodem can be downloaded with any typical web browser from http://iaxmodem.sourceforge.net (the version used in this example is 0.3.0). After downloading the archive, copy it to /usr/src and unpack it with tar -xvzf iaxmodem-0.3.0.tar.gz.

debian:/usr/src# tar -xvzf iaxmodem-0.3.0.tar.gz
iaxmodem-0.3.0/
iaxmodem-0.3.0/iaxmodem.c
iaxmodem-0.3.0/iaxmodem.init.debian
iaxmodem-0.3.0/Makefile.in
iaxmodem-0.3.0/CHANGES
iaxmodem-0.3.0/lib/
iaxmodem-0.3.0/lib/spandsp/
iaxmodem-0.3.0/lib/spandsp/Makefile.am

[...]

iaxmodem-0.3.0/TODO
iaxmodem-0.3.0/FAQ
iaxmodem-0.3.0/build
iaxmodem-0.3.0/iaxmodem.init.fedora
debian:/usr/src#

Change into the unpacked directory with cd iaxmodem-0.3.0:

debian:/usr/src# cd iaxmodem-0.3.0
debian:/usr/src/iaxmodem-0.3.0#

Now compile the sources with ./configure && make:

debian:/usr/src/iaxmodem-0.3.0# ./configure && make
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for gawk… no
checking for mawk… mawk
checking whether make sets $(MAKE)… yes
checking for gcc… gcc

[...]

cc -DMODEMVER=\”0.3.0\” -DDSPVER=\”spandsp-0.0.3-snapshot-20070223+\” -D
IAXVER=\”libiax2-0.2.3-CVS-20060222+\” -Wall -g -DSTATICLIBS -DUSE_UNIX9
8_PTY -std=c99 -Ilib/libiax2/src -Ilib/spandsp/src -c iaxmodem.c
cc -DMODEMVER=\”0.3.0\” -DDSPVER=\”spandsp-0.0.3-snapshot-20070223+\” -D
IAXVER=\”libiax2-0.2.3-CVS-20060222+\” -Wall -g -DSTATICLIBS -DUSE_UNIX9
8_PTY -std=c99 -Ilib/libiax2/src -Ilib/spandsp/src iaxmodem.o lib/spand
sp/src/.libs/libspandsp.a lib/libiax2/src/.libs/libiax.a -o iaxmodem -lm
-lutil -ltiff

[...]

debian:/usr/src/iaxmodem-0.3.0#

Copy the resulting binary into /usr/bin with cp iaxmodem /usr/bin/:

debian:/usr/src/iaxmodem-0.3.0# cp iaxmodem /usr/bin/
debian:/usr/src/iaxmodem-0.3.0#

Now we can configure the modem. IAXmodem expects to find configuration files in /etc/iaxmodem. Create it with mkdir /etc/iaxmodem:

debian:/usr/src/iaxmodem-0.3.0# mkdir /etc/iaxmodem
debian:/usr/src/iaxmodem-0.3.0#

Create the configuration file with touch /etc/iaxmodem/ttyIAX0:

debian:/usr/src/iaxmodem-0.3.0# touch /etc/iaxmodem/ttyIAX0
debian:/usr/src/iaxmodem-0.3.0#

This file must contain the following parameters:

device
The device node to be created in /dev. This is the device Hylafax uses to connect to IAXmodem. You can choose any name you like, but we prefer to adhere to the convention and so choose a device name appropriate for a serial interface, ttyIAX0.
owner
This is the owner of the device (in the form user:group). It is best to use the same user and group under which Hylafax runs.
port
The port that IAXmodem listens on. Asterisk uses 4569 to listen for IAX2 connections, so you must choose something else, e.g. 4570.
refresh
This sets how long IAXmodem waits between registrations with Asterisk. If this number is 0, the modem does not register at all.
server
IP address of the server running Asterisk. If this is on the same machine as IAXmodem, use the localhost address 127.0.0.1.
peername
The name under which IAXmodem registers with Asterisk.
secret
The password used for Asterisk registration.
codec
The codec used by IAXmodem. Allowed codecs are alaw, ulaw and slinear. Compressed codecs are not appropriate for faxing; fax transmissions are themselves compressed and don’t tolerate further compression; moreover, most compressed codecs are lossy and a fax transmission will not tolerate losses. This is one of the major reasons why faxing over VoIP remains problematic.

Using an appropriate editor (e.g. vi) we write the following configuration in the file /etc/iaxmodem/ttyIAX0:

device /dev/ttyIAX0
owner uucp:uucp
mode 660
port 4570
refresh 50
server 127.0.0.1
peername iaxmodem
secret password
codec alaw

IAXmodem is now configured and can be started. The best way to do this is with init. Add a line to start IAXmodem to /etc/inittab with echo “IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0″ >> /etc/inittab:

debian:/usr/src/iaxmodem-0.3.0# echo “IA00:23:respawn:/usr/bin/iaxmodem
ttyIAX0″ >> /etc/inittab
debian:/usr/src/iaxmodem-0.3.0#

The device name ttyIAX0 is the same device name as specified in /etc/iaxmodem.

To receive faxes, we need a getty that listens for connections on the IAXmodem. This is accomplished through an additional entry in /etc/inittab. Add it with echo “mo00:23:respawn:/usr/sbin/faxgetty ttyIAX0″ >> /etc/inittab.

mo00:23:respawn:/usr/local/sbin/faxgetty ttyIAX0

Create a log directory for IAXmodem with mkdir /var/log/iaxmodem/ and the log files with touch /var/log/iaxmodem/ttyIAX0 and touch /var/log/iaxmodem/iaxmodem.

debian:/usr/src/iaxmodem-0.3.0# mkdir /var/log/iaxmodem/
debian:/usr/src/iaxmodem-0.3.0# touch /var/log/iaxmodem/ttyIAX0
debian:/usr/src/iaxmodem-0.3.0# touch /var/log/iaxmodem/iaxmodem
debian:/usr/src/iaxmodem-0.3.0#

To make sure everything will start as expected at boot time, reboot the system with shutdown -r now.

debian:/usr/src/iaxmodem-0.3.0# shutdown -r now

Broadcast message from root@debian (pts/1) (Sat May 5 00:15:49 2007):

The system is going down for reboot NOW!
debian:/usr/src/iaxmodem-0.3.0#

Installing Hylafax

We’ll install Hylafax from the Debian Repository to simplify installation. Do this with apt-get -y install hylafax-server . Dependencies are automatically resolved:

debian:~# apt-get install -y hylafax-server
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Die folgenden zusätzlichen Pakete werden installiert:
enscript gs-common gs-esp hylafax-client libcupsimage2 libcupsys2 mail
x metamail psmisc
Vorgeschlagene Pakete:
gv postscript-viewer lpr gs-pdfencrypt gs-cjk-resource mgetty-viewfax
hylafax-doc mgetty cupsys-common
Empfohlene Pakete:
psfontmgr netpbm transfig
Die folgenden NEUEN Pakete werden installiert:
enscript gs-common gs-esp hylafax-client hylafax-server libcupsimage2
libcupsys2 mailx metamail psmisc

[...]

Update /var/spool/hylafax/status/any.info.

HylaFAX configuration parameters are:

[1] Init script starts faxq: yes
[2] Init script starts hfaxd yes
[3] Start old protocol: no
[4] Start paging protocol: no
Are these ok [yes]?
Modem support functions written to /var/spool/hylafax/etc/setup.modem.
Configuration parameters written to /var/spool/hylafax/etc/setup.cache.

Restarting HylaFAX server processes.

Should I restart the HylaFAX server processes [yes]?
You do not appear to have any modems configured for use. Modems are
configured for use with HylaFAX with the faxaddmodem(8) command.
Do you want to run faxaddmodem to configure a modem [yes]?
Done verifying system setup.
Updating /etc/hylafax/setup.cache from /var/spool/hylafax/etc/setup.cach
e.
Updating /etc/hylafax/setup.modem from /var/spool/hylafax/etc/setup.mode
m.apt-get -y install hylafax-server
/var/spool/hylafax
Starting HylaFAX: faxq hfaxd faxgetty.

debian:~#

The next step is the configuration of the fax server. Do this with faxsetup:

debian:/usr/src/hylafax-4.3.4# faxsetup

[...]

Update /var/spool/hylafax/status/any.info.

HylaFAX configuration parameters are:

[1] Init script starts faxq: yes
[2] Init script starts hfaxd yes
[3] Start old protocol: no
[4] Start paging protocol: no

Are these ok [yes]?

Simply press Enter after the following 2-3 questions.

You have a HylaFAX scheduler process running. faxq will be
restarted shortly, as soon as some other work has been completed.
Can I terminate this faxq process (4048) [yes]?
Should I restart the HylaFAX server processes [yes]?

/etc/init.d/hylafax start
Not starting HylaFAX daemons since they are already running.

[...]

Modems are configured for use with HylaFAX with the faxaddmodem(8) comma
nd.
Do you want to run faxaddmodem to configure a modem [yes]?

We confirm restart of the server processes with yes and are asked if we want to install a modem. Our IAXmodem is already set up so we can proceed and confirm again with yes.

Specify the modem and confirm with Enter.

Serial port that modem is connected to [ttyS0]? ttyIAX0

Ok, time to setup a configuration file for the modem. The manual
page config(5) may be useful during this process. Also be aware
that at any time you can safely interrupt this procedure.

Reading scheduler config file /var/spool/hylafax/etc/config.

Many questions follow, but only a few of them are really important.[44]This is where you set international dialing codes, the fax number, country and area code, and the CSID (Call Subscriber ID) which is printed on the top line of the fax page on the receiver’s end. Confirm with yes.

No existing configuration, let’s do this from scratch.

Country code [1]? 1
Area code []? 403
Phone number of fax modem [+1.999.555.1212]? +1 888 555 4091
Local identification string (for TSI/CIG) ["NothingSetup"]?
Long distance dialing prefix [1]? 1
International dialing prefix [011]? 011
Dial string rules file (relative to /var/spool/hylafax) [etc/dialrules]?

Tracing during normal server operation [1]?
Tracing during send and receive sessions [11]?
Protection mode for received facsimile [0600]?
Protection mode for session logs [0600]?
Protection mode for ttyIAX0 [0600]?
Rings to wait before answering [1]?
Modem speaker volume [off]?
Command line arguments to getty program ["-h %l dx_%s"]?
Pathname of TSI access control list file (relative to /var/spool/hylafax
) [""]?
Pathname of Caller-ID access control list file (relative to /var/spool/h
ylafax) [""]?
Tag line font file (relative to /var/spool/hylafax) [etc/lutRS18.pcf]?
Tag line format string ["From %%l|%c|Page %%P of %%T"]?
Time before purging a stale UUCP lock file (secs) [30]?
Hold UUCP lockfile during inbound data calls [Yes]?
Hold UUCP lockfile during inbound voice calls [Yes]?
Percent good lines to accept during copy quality checking [95]?
Max consecutive bad lines to accept during copy quality checking [5]?
Max number of pages to accept in a received facsimile [25]?
Syslog facility name for ServerTracing messages [daemon]?
Set UID to 0 to manipulate CLOCAL [""]?
Use available priority job scheduling mechanism [""]?

A confirmation page follows where you can double-check your entries:

The non-default server configuration parameters are:

CountryCode: 1
AreaCode: 403
FAXNumber: +1 888 555 4091
LongDistancePrefix: 0
InternationalPrefix: 00
DialStringRules: etc/dialrules
SessionTracing: 11
RingsBeforeAnswer: 1
SpeakerVolume: off
GettyArgs: “-h %l dx_%s”
LocalIdentifier: “NothingSetup”
TagLineFont: etc/lutRS18.pcf
TagLineFormat: “From %%l|%c|Page %%P of %%T”
MaxRecvPages: 25

Are these ok [yes]?

Answering yes brings us to modem detection:

Now we are going to probe the tty port to figure out the type
of modem that is attached. This takes a few seconds, so be patient.
Note that if you do not have the modem cabled to the port, or the
modem is turned off, this may hang (just go and cable up the modem
or turn it on, or whatever).

Probing for best speed to talk to modem: 38400 OK.

About fax classes:

The difference between fax classes has to do with how HylaFAX interacts
with the modem and the fax protocol features that are used when sending
or receiving faxes. One class isn’t inherently better than another;
however, one probably will suit a user’s needs better than others.

Class 1 relies on HylaFAX to perform the bulk of the fax protocol.
Class 2 relies on the modem to perform the bulk of the fax protocol.
Class 2.0 is similar to Class 2 but may include more features.
Class 1.0 is similar to Class 1 but may add V.34-fax capability.
Class 2.1 is similar to Class 2.0 but adds V.34-fax capability.

HylaFAX generally will have more features when using Class 1/1.0 than
when using most modems’ Class 2 or Class 2.0 implementations. Generally
any problems encountered in Class 1/1.0 can be resolved by modifications
to HylaFAX, but usually any problems encountered in Class 2/2.0/2.1 will
require the modem manufacturer to resolve it.

If you’re unsure and your modem supports it, use Class 1.

This modem looks to have support for Class 1 and 1.0.
How should it be configured [1]?

Hmm, this looks like a Class 1 modem.
Product code (ATI0) is “spandsp”.
Other information (ATI3) is “www.soft-switch.org”.
DTE-DCE flow control scheme [default]?
Modem manufacturer is “spandsp”.
Modem model is “IAXmodem”.

Using prototype configuration file iaxmodem…

The modem configuration parameters are:

ModemResetCmds: “ATH1\nAT+VCID=1″

Are these ok [yes]?

The modem was detected and we are asked if it is a Class 1 modem, and we confirm this because it is exactly what we want. The default reset commands are also acceptable. Confirm with yes.

Answer the first question In the next dialog with no, since we don’t need to configure any further modems. The second question is confirmed with by pressing Enter, which starts the fax server.

Creating new configuration file /var/spool/hylafax/etc/config.ttyIAX0…
Creating fifo /var/spool/hylafax/FIFO.ttyIAX0 for faxgetty… done.
Done setting up the modem configuration.

[...]

Do you want to run faxaddmodem to configure another modem [yes]? no

[...]

Should I run faxmodem for each configured modem [yes]?
/usr/sbin/faxmodem ttyIAX0

Done verifying system setup.
/var/spool/hylafax

debian:~#

Hylfax is now configured for sending faxes.
Receiving faxes

Our fax solution still has to be integrated into Asterisk. To do this, we configure the IAXmodem as an IAX2 peer by adding a section to /etc/asterisk/iax.conf (see also ???):

[general]
bindport = 4569
bindaddr = 0.0.0.0
disallow=all
allow=ulaw
allow=alaw

[iaxmodem]
type=friend
secret=password
port=4570
host=dynamic
context=fax-out
disallow=all
allow=alaw

Global settings are defined in the general section. In this example we are binding the standard IAX2 port of 4569. The bindaddr defines the IP address (and thereby the interface) on which the IAX2 channel driver listens for connections; in this case, it is set to listen on all interfaces.

The IAXmodem is set to type friend, which allows both incoming and outgoing connections. The secret and port parameters match those in the IAXmodem configuration we did above, and context defines the entry context for outgoing connections.

Enter iax2 show peers in the Asterisk console to see our new IAXmodem:

*CLI> iax2 show peers
Name/Username Host Mask Port Sta
tus
iaxmodem 127.0.0.1 (D) 255.255.255.255 4570 Unm
onitored
1 iax2 peers [0 online, 0 offline, 1 unmonitored]
*CLI>

We are, of course, not done yet. Asterisk still needs an extension so that it knows what to do with an incoming fax. Our objective is to ensure that any incoming faxes are passed on to Hylafax. In this example, we assume that all faxes come in through a SIP provider. A real configuration will have to reflect the installation and account settings of the SIP provider you use; for the sake of example, a configuration in sip.conf might look like this:

[...]

[123456]
type=friend
insecure=very;
nat=yes
username=123456
fromuser=12345
fromdomain=my-voip-provider.com
secret=secret
host=my-voip-provider.com
qualify=yes
context=fax-in

[...]

The corresponding context in extensions.conf would look like this:

[fax-in]
exten => _X.,1,Dial(IAX2/iaxmodem)

Any faxes coming in will now be routed to Hylafax via IAXmodem and ultimately e-mailed to the user address defined in the faxmaster alias.
Sending faxes

The next obvious step is configuring our system to send faxes. Here, too, we need a context (this time it is [fax-out]) in extensions.conf. If IAXmodem wants to send a fax, it will automatically land in this context. If the faxes are to go out our hypothetical SIP connection 123456, the entry in extensions.conf will look like this:

[fax-out]
exten => _X.,1,Dial(SIP/123456/${EXTEN})

We can test sending of faxes with sendfax -n -d :

debian:~# sendfax -n -d 6045557977 /etc/issue.net

We should see this in the CLI:

— Accepting AUTHENTICATED call from 127.0.0.1:
> requested format = alaw,
> requested prefs = (),
> actual format = alaw,
> host prefs = (alaw),
> priority = mine
— Executing Answer(”IAX2/iaxmodem-3″, “”) in new stack
— Executing Dial(”IAX2/iaxmodem-3″, “SIP/123456/6045557977″) in new
stack
— Called 123456/6045557977
— SIP/123456-0818f630 is making progress passing it to IAX2/iaxmode
m-3
— SIP/123456-0818f630 answered IAX2/iaxmodem-3
— parse_srv: SRV mapped to host my-voip-provider.com, port 5060
== Spawn extension (fax-out, 6045557977, 2) exited non-zero on ‘IAX2/i
axmodem-3′
— Executing Hangup(”IAX2/iaxmodem-3″, “”) in new stack
== Spawn extension (fax-out, h, 1) exited non-zero on ‘IAX2/iaxmodem-3

— Hungup ‘IAX2/iaxmodem-3′

If we issue the command faxstat -s during the transmission, we will see:

debian:~# faxstat -s
HylaFAX scheduler on w077.example.com: Running
Modem ttyIAX0 (123456): Sending job 7

JID Pri S Owner Number Pages Dials TTS Status
7 127 R root 06912345678 0:1 0:12
debian:~#

Done! Now you can send and receive faxes via Asterisk using Hylafax.

The Hylafax website http://www.hylafax.org has numerous examples and how-tos that will help you integrate your Hylafax installation with your existing office intrastructure effectively.
Sending received faxes as e-mail

The following steps illustrate how we can configure Hylafax to transmit incoming faxes to a pre-defined e-mail address.[45]The recipient will receive the fax as an e-mail attachment.

To do this, the configuration file /var/spool/hylafax/etc/FaxDispatch must contain the following parameters:

SENDTO
The destination e-mail address for incoming faxes.
FILETYPE
The format of the attachment. In addition to pdf, tiff (Tagged Image File Format) and ps (Postscript™) are also acceptable options.

SENDTO=fax-incoming@company.com
FILETYPE=pdf

After the file has been saved, you must restart the fax server with /etc/init.d/hylafax restart.

debian:~# /etc/ini.d/hylafax restart
Starting HylaFAX: faxq hfaxd.
debian:~#

We can test e-mail transmission by sending ourselves a fax with sendfax -n -d

debian:~# sendfax -n -d 6045557977 /etc/issue.net

After a short time your target e-mail address should receive an e-mail in the following format:

recvq/fax000000016.tif (ftp://debian:4559/recvq/fax000000016.tif):

Sender: IAXmodem
Pages: 4
Quality: Normal
Size: North American Letter
Received: 2007:06:02 02:49:45
Time To Receive: 1:58
Signal Rate: 9600 bit/s
Data Format: 2-D MMR
Error Correct: Yes
CallID1: 2007
CallID2: IAXmodem 1
Received On: ttyIAX0
CommID: 000000033 (ftp://debian:4559/log/c000000033)

[...]

Jun 02 02:51:46.99: [ 3320]: RECV FAX: bin/faxrcvd “recvq/fax000000016.t
if” “ttyIAX0″ “000000033″ “COMREC received DCN” “2007″ “IAXmodem 1″ “ NE>” “s”
Jun 02 02:51:47.00: [ 3320]: RECV FAX: end
Jun 02 02:51:47.00: [ 3320]: SESSION END
Jun 02 02:51:47.01: [ 3320]: RECV FAX (000000033): recvq/fax000000016.ti
f from IAXmodem, route to , 4 pages in 2:08

The attachment will be a PDF file. In this example, the PDF is named fax000000016.pdf.

Now you can not only send and receive faxes, but received faxes are also received as e-mail attachments.

  • Comments Off

ข้อมูลในฮาร์ดดิสก์เริ่มเยอะขึ้นๆ ทุกวัน สงสัยต้องเขียนลงแผ่นซีดีซักหน่อย แต่ในลินุกซ์ทะเล 5.0 ไม่มีโปรแกรมสำหรับเขียนซีดีง่ายๆ เลยครับ .. เอาวะ เล่นมันถึกๆ นี่ล่ะ ใช้ mkisofs + cdrecord ก็ได้ :D .. สองโปรแกรมนี้เป็นโปรแกรมหลักที่ใช้เขียนซีดีบนลินุกซ์ ส่วนโปรแกรมที่เป็นอินเทอร์เฟซสวยๆ ใช้ง่ายๆ อย่างพวก EClipt Roaster เป็นแค่หน้ากากที่ช่วยให้ใช้งานได้ง่ายขึ้นเท่านั้นเอง และเอาเข้าจริงๆ แล้วใช้ mkisofs + cdrecord ก็ไม่ได้ยากอะไรเลย จำแค่สองคำสั่งก็ใช้ได้แล้วครับ .. ที่เราจะทำก็คือใช้โปรแกรม mkisofs สร้างอิมเมจของแผ่นซีดีก่อน แล้วจึงเอาอิมเมจที่ได้ไปเขียนลงแผ่นจริงๆ อีกทีด้วย cdrecord ..
สร้าง ISO อิมเมจ
เริ่มกันที่สร้างอิมเมจก่อน คำสั่งพื้นฐานในการสร้างอิมเมจก็คือ

[root@yggdrasil kitt]$ mkisofs -o image.iso /source/tree

mkisofs จะสร้างไฟล์ซิสเต็มและจัดโครงสร้างการจัดเก็บข้อมูลเสมือนกับว่า image.iso เป็นแผ่นซีดีแผ่นนึง แล้วก๊อปปี้ข้อมูลทั้งหมดจากไดเรคทอรี่ /source/tree ลงไป .. แต่การใช้งานจริงเรามักต้องการให้ซีดีใช้กับวินโดวส์หรือโอเอสอื่นๆ ได้ด้วย .. นอกจากนั้นอาจจะต้องการใช้ชื่อไฟล์ยาวๆ และชื่อไฟล์ภาษาไทยอีก จึงต้องระบุออพชันเพิ่มเติมเข้าไป ..อืมม.. เอาเป็นว่าจำคำสั่งนี้ไปเลยก็แล้วกันครับ:

mkisofs -V “My Label” -v -r -jcharset cp874 -o image.iso /source/tree

อธิบายสักนิด
-V “My Label” เป็นการกำหนด volume label ของแผ่น เป็น “My Label” .. เปลี่ยนข้อความตามใจชอบ แต่อย่าลืมใส่เครื่องหมายคำพูดกันไว้สักหน่อย
-v หมายถึง verbose ที่จริงไม่จำเป็นเท่าไหร่ ไม่ต้องระบุก็ได้ แต่ผมชอบให้มันแสดงข้อความเยอะๆ จะได้รู้สึกว่ามันกำลังทำงานอยู่ :P
-r ตั้ง permission เป็น public permission อันนี้ใส่กันเอาไว้ เผื่อเอาแผ่นไปใช้กับลินุกซ์หรือยูนิกซ์อื่นๆ จะได้ไม่มีปัญหาเรื่อง permission ของไฟล์..
-jcharset cp874 เป็นการกำหนดให้ใช้ Joliet ซึ่งทำให้เก็บชื่อไฟล์ได้ยาว 64 ตัวอักษร และตั้ง charset สำหรับ Joliet เป็นภาษาไทย (cp874 คือ codepage ภาษาไทย) .. ออพชันนี้ทำให้วินโดวส์แสดงชื่อไฟล์และไดเรคทอรี่ภาษาไทยได้ถูกต้อง หลังจากได้ไฟล์ image.iso แล้ว อาจจะอยากทดสอบดูก่อนเขียนลงแผ่นซีดี.. ไม่ยากๆ .. เพราะเราสร้าง image.iso เสมือนเป็นแผ่นซีดีอยู่แล้ว การทดสอบจึงทำได้โดยการเมาท์ไฟล์ image.iso ..

[root@yggdrasil kitt]# mount -o loop image.iso /mnt

คำสั่งนี้จะเมาท์ไฟล์ image.iso ไว้ที่ /mnt ออพชัน -o loop เป็นการระบุว่าเราต้องการเมาท์อิมเมจของไฟล์ซิสเต็ม .. เมาท์ได้แล้วก็ลอง ls -lR /mnt ดู .. ถ้าทุกอย่างดูเรียบร้อยดีแล้วก็ umount /mnt แล้วก็เตรียมเขียนลงแผ่นจริงๆ กันล่ะครับ
เผาแผ่นกันล่ะ
ก่อนอื่นต้องสแกนหาไดรว์ที่จะใช้เขียนเสียก่อน โดยใช้คำสั่ง:

[root@yggdrasil kitt]# cdrecord -scanbus
Cdrecord 2.0 (i686-pc-linux-gnu) Copyright (C) 1995-2002 J#rg Schilling
Using libscg version ’schily-0.7′
scsibus0:
0,0,0 0) ‘LITE-ON ‘ ‘LTR-40125S ‘ ‘ZS0N’ Removable CD-ROM
0,1,0 1) *
0,2,0 2) *
0,3,0 3) *
0,4,0 4) *
0,5,0 5) *
0,6,0 6) *
0,7,0 7) *

จากตัวอย่างจะเห็นว่าไดรว์เขียนซีดีเป็นดีไวซ์ 0,0,0 .. หมายเลขดีไวซ์นี้จะเอาไปใช้ระบุไดรว์เมื่อสั่ง cdrecord ..

[root@yggdrasil kitt]# cdrecord -v speed=32 dev=0,0,0 -data image.iso

ออพชันที่ระบุประกอบด้วย
-v หมายถึง verbose .. เช่นเคย
speed=32 หมายถึงเขียนที่ 32x แต่อัตราการเขียนจริงๆ อาจจะไม่ตรงกับค่านี้
dev=0,0,0 เป็นการระบุให้ใช้ดีไวซ์หมายเลข 0,0,0 ในการเขียนซีดี
-data image.iso เป็นการระบุให้เอาไฟล์ image.iso ไปเขียนลงซีดี

ทีนี้ก็นั่งรอ ไม่กี่นาทีก็ได้แผ่นซีดีอุ่นๆ ออกมา :)

Cdrecord 2.0 (i686-pc-linux-gnu) Copyright (C) 1995-2002 J#rg Schilling
TOC Type: 1 = CD-ROM
scsidev: ‘0,0,0′
scsibus: 0 target: 0 lun: 0
Linux sg driver version: 3.1.24
Using libscg version ’schily-0.7′
atapi: 1
Device type : Removable CD-ROM
Version : 0
Response Format: 2
Capabilities :
Vendor_info : ‘LITE-ON ‘
Identifikation : ‘LTR-40125S ‘
Revision : ‘ZS0N’
Device seems to be: Generic mmc CD-RW.
Using generic SCSI-3/mmc CD-R driver (mmc_cdr).
Driver flags : MMC-3 SWABAUDIO BURNFREE FORCESPEED
Supported modes: TAO PACKET SAO SAO/R96P SAO/R96R RAW/R16 RAW/R96P RAW/R96R
Drive buf size : 1422080 = 1388 KB
FIFO size : 4194304 = 4096 KB
Track 01: data 676 MB
Total size: 776 MB (76:56.77) = 346258 sectors
Lout start: 777 MB (76:58/58) = 346258 sectors
Current Secsize: 2048
ATIP info from disk:
Indicated writing power: 7
Is not unrestricted
Is not erasable
ATIP start of lead in: -11597 (97:27/28)
ATIP start of lead out: 359849 (79:59/74)
Disk type: Short strategy type (Phthalocyanine or similar)
Manuf. index: 20
Manufacturer: Princo Corporation
Blocks total: 359849 Blocks current: 359849 Blocks remaining: 13591
Forcespeed is OFF.
Starting to write CD/DVD at speed 32 in real TAO mode for single session.
Last chance to quit, starting real write 0 seconds. Operation starts.
Waiting for reader process to fill input buffer … input buffer ready.
BURN-Free is ON.
Turning BURN-Free off
Performing OPC…
Starting new track at sector: 0
Track 01: 676 of 676 MB written (fifo 100%) [buf 98%] 32.9x.
Track 01: Total bytes read/written: 709132288/709132288 (346256 sectors).
Writing time: 177.016s
Average write speed 27.3x.
Min drive buffer fill was 97%
Fixating…
Fixating time: 26.745s
cdrecord: fifo had 11170 puts and 11170 gets.
cdrecord: fifo was 0 times empty and 6789 times full, min fill was 51%.

สำหรับใครที่มีเครื่องเร็วพอ จะเขียนซีดีจากข้อมูลในไดเรคทอรีโดยไม่ต้องสร้างอิมเมจก็ได้ โดยสั่ง

[root@yggdrasil kitt]# mkisofs -V “My Label” -v -r -jcharset cp874 /source/tree
| cdrecord -v fs=8m speed=36 dev=0,0,0 -

จะเห็นว่าเราไม่ได้ระบุ -o image.iso ใน mkisofs กรณีนี้ mkisofs จะส่งเอาท์พุตออก stdout แทน เราจึง pipe เข้าไปเป็นอินพุตของ cdrecord ได้โดยระบุออพชัน - (อยู่ท้ายบรรทัด) ซึ่งเป็นการกำหนดให้ cdrecord รับอินพุตจาก stdin … ส่วนออพชัน fs=8m เป็นการกำหนดขนาดของบัฟเฟอร์ในการเขียนซีดีให้มีขนาดเป็น 8 MB (ถ้าไม่ระบุจะเป็น 4 MB) .. ตามเอกสารของ cdrecord บอกไว้ว่าบัฟเฟอร์ควรมีขนาด 4 - 32 MB และแนะนำว่าขนาดอย่างน้อยควรจะเท่ากับบัฟเฟอร์ของไดรว์เขียนซีดี และอย่างมากไม่เกินครึ่งหนึ่งของหน่วยความจำของเครื่อง .. โดยทั่วไป 8 MB ก็เพียงพอแล้วครับ สำหรับการก๊อปปี้ซีดีจากแผ่นนึงไปอีกแผ่นนึง ทำได้โดยสร้างอิมเมจของแผ่นต้นฉบับ ด้วยคำสั่ง

[root@yggdrasil kitt]# dd if=/dev/cdrom of=image.iso bs=1k

จากนั้นก็เอา image.iso ไปเขียนลงซีดีด้วย cdrecord หรือกรณีที่มีไดรว์สองตัวจะก๊อปแผ่นโดยไม่ทำอิมเมจก็ได้เหมือนกัน สมมติว่า /dev/hdd เป็นไดรว์ที่ใส่แผ่นต้นฉบับ และ /dev/hdc เป็นไดรว์สำหรับเขียนแผ่นซีดี มี dev=0,0,0 ก็จะสามารถสั่งให้ก๊อปปี้แผ่นได้โดยใช้คำสั่ง

[root@yggdrasil kitt]# dd if=/dev/hdd bs=1k | cdrecord -v fs=8m speed=36 dev=0,0,0 -

  • Comments Off

debian 4 uptime 21 วัน Memory 98%

ลองสั่ง free -m แล้วเอามาแปะไว้ให้ช่วยกันวิเคราะห์ได้ครับ

แต่อาการปกติของ Cache Proxy Server คือ ใช้ RAM ในการทำ Hot Object ครับ ลองตรวจสอบขนาด cache_dir ดูครับ ถ้าตั้งไว้เยอะมาก ก็จำเป็นต้องใช้ RAM เยอะด้วยเช่นกัน แต่ถ้ากังวลเรื่อง RAM ไม่คืนนี่ ลอง

# sync
# echo 1 > /proc/sys/vm/drop_caches

แล้วลอง free -m อีกทีครับ น่าจะเห็น RAM กลับมาบ้าง :P
บางทีเราอาจจะกังวลมากไปครับ ตอนนี้ผมใช้ AMD Athlon X2 4000+ กับ RAM 4GB ทำ Squid Cache Proxy ใช้ไปสักพักใหญ่ (ระบบใหญ่ครับ ผู้ใช้ 100+ คน) ก็เหลือ RAM ไม่ถึง 25 MB เหมือนกันครับ แต่ระบบก็ทำงานได้ไม่มีปัญหาครับ ก็เผื่อ ๆ ไว้ครับ ก็ Run เจ้า สองคำสั่งข้างบนนี้ไว้ใน crontab ทุก ๆ วัน ก็มี RAM คืนมาให้สบายใจเล่น ๆ แล้วหละครับ แต่อย่าลืมว่ากระบวนการ Cache นี่ช่วยให้การทำงานของระบบมีประสิทธิภาพขึ้น เคลียร์บ่อย ๆ น่าจะไม่ใช่ทางออกที่ดี ให้ระบบจัดการตัวเอง

  • Comments Off

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 23
  • Visitors yesterday: 48
  • Visitors per day: 485
  • Max. visitors per day: 255
  • Total page views: 155,887
  • Page views of this page: 485
  • Currently online: 1
  • Max. online: 23
  • Total visitors: 33,987
  • counterStatistics