A2B 與多個 Asterisk/FreePBX 連接

    版本為 13:26, 3 Oct 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    A2B 可以與多個 Asterisk 做連接,這樣的架構有以下好處:

    1. A2B 與 Asterisk 安裝在不同的主機上
    2. 各自運作的效能提升,硬體資源使用不會互相影響
    3. 如果有使用 FreePBX,它的 DB 不會與 A2B 的 DB 放在同一部主機,資料安全性較高
       

    主機的配置及架構

    總共需要兩部獨立的 Linux 主機,分別為主機 A,B。

    主機 A) A2B 主管理系統

    1. Ubuntu 12 + Asterisk 1.8.10 + A2B 1.9.4
    2. A2B 網站主程式
    3. A2B 資料庫
    4. Asterisk (不需要 FreePBX,主要用作 A2B 的 outbound/inbound trunk,並且給所有的 FreePBX 做外撥路由使用)

    用途:

    • A2B 會用到 inbound/outbound trunks
    • 所有 A2B 的 SIP account 註冊的主機

     

    主機 B) FreePBX 系統 (可連接多個 FreePBX 系統)

    1. Ubuntu 12 + Asterisk 1.8.10 + FreePBX 2.9
    2. FreePBX 資料庫
    3. Asterisk
    4. A2B 的 AGI 及 dialplans

    用途:

    • FreePBX 的 SIP account 透過 account code 也可做撥出計費。
    • 撥出時統一經由 A2B 的 outbound trunk 路由出去。

    步驟開始

    在主機A: A2B 網站)
    1. 先安裝好Asterisk & A2B 完整安裝
    2. A2B 的設定必須啟用 Real-Time 模式
      •  Asterisk 必須 1.6.2 以上版本才可支援 A2B v1.9.4
      • 修改 res_config_mysql.conf
      • 修改 extconfig.conf
    3. 確認 A2B 網站可以正常操作
    4. 設定 MySQL Server 可接收遠端 FreePBX 主機的存取
    5. 編輯 sip.conf,新增一個 SIP Outbound Trunk 用來做主要的外撥路由
    6. 編輯 extensions.conf,新增一個外撥的撥號規則,詳細如下
    7. 將 A2B 的AGI等檔案複製到 FreePBX 主機上
      • /etc/asterisk/a2billing.conf
      • /etc/asterisk/extensions_a2billing_1_6.conf
      • /usr/src/a2billing/addons/sounds
      • /var/lib/asterisk/agi-bin
        • a2billing.php
        • a2billing_monitoring.php
        • lib/
    8. 在 A2B Admin UI 新增一些資料
      • Trunk:
        • Label: ccnet
        • Add Prefix: 991 <與 extensions.conf 規則要呼應>
        • Provider TECH: SIP
        • Provider IP: <A2B 內部 IP>
    9. 設定 Inbound DID (選用)
      • 編輯 sip.conf,新增一個 SIP Inbound Trunk 用來做 DID 進線路由
      • DID 可以轉接到外部的 PSTN 號碼,外部的 SIP URI 以及其他 A2B SIP account

     

    設定 MySQL Server 可接收遠端的存取權限
    編輯 /etc/mysql/my.cnf

    將這行註解
    #bind-address           = 127.0.0.1
    

    修改資料庫權限

    mysql -uroot -p <<-END_SQL
      CREATE USER 'a2billinguser'@'%' IDENTIFIED BY 'a2billingpass';
      GRANT ALL PRIVILEGES ON mya2billing.* TO 'a2billinguser'@'%';
      flush privileges;
    END_SQL
    

    extensions.conf:

    [out-all]
    exten => _0011101XXX.,1,Noop(This is outbound call)
    exten => _0011101XXX.,n,Dial(SIP/voxbeam/${EXTEN})
    exten => _0011101XXX.,n,Hangup
    
    [from-freepbx]
    include => out-all
    
     

    Notes:

    如果來自 FreePBX 的電話,號碼開頭是 0011101 的,路由到 voxbeam,這個 prefix code 是 voxbeam 訂定的。

    sip.conf:
    1. 當遠端 FreePBX 要外撥時,會經由這進入到 A2B 主機的 Asterisk

    ;Inbound Trunks
    ; Incoming Calls from FreePBX
    [PBX1]
    type=peer
    host=<FreePBX#1 內部 IP>
    context=from-freepbx
    qualify=yes
    insecure=port,invite
    canreinvite=no
    nat=no
    

    Tips:

    當有新增其他的 FreePBX 主機時,這裡要增加新主機的 SIP 連線資訊,例如 PBX2, PBX3,...

    2. 這個連結到 SIP Provider 做 Outbound Trunk

    ;Outbound trunks
    ;this is for test
    [ccnet]
    defaultuser=070XXXXXXX
    type=friend
    secret=123456
    port=7890
    insecure=port,invite
    host=210.202.244.130
    qualify=yes
    nat=yes
    fromuser=070XXXXXXX
    context=no-incoming
    

    3. [選用] 需要做 Inbound DID 時的 Inbound Trunk

    ; Inbound Trunk for DIDs from Voxbeam
    ;Voxbeam
    [voxbeam-in-1]
    type=peer
    qualify=yes
    nat=yes
    insecure=port,invite
    host=95.211.119.240
    dtmfmode=rfc2833
    disallow=all
    context=a2billing-did
    canreinvite=no
    allow=alaw
    allow=ulaw 
    

    註:a2billing-did 是 A2Billing 內建的 dialplan。

    在主機B: FreePBX)

    流程如下:

    1. 安裝好 FreePBX & Asterisk
    2. 確認 mysql 指令可存取遠端 A2B 的 DB 資料
      1. 執行 mysql -ua2billinguser -p -h <A2B IP>
      2. telnet <A2B IP> 3306
    3. 設定 A2B AGI 及相關檔案
      • /etc/asterisk/a2billing.conf,建立連結到 /etc/a2billing.conf
      • /etc/asterisk/extensions_a2billing_1_6.conf
      • /var/lib/asterisk/agi-bin
        • a2billing.php
        • a2billing_monitoring.php
        • lib/
      • 修改以上檔案目錄權限為 asterisk 可存取
      • 安裝 A2B 語音檔
    4. FreePBX 主機不需設定 Asterisk Real-Time 模式,因為所有 A2B 的 SIP account 應該統一註冊於 A2B 主機而非 FreePBX 主機。

     

    編輯 extensions_custom.conf (註: 以 FreePBX 為例)

    加上這一行
    ;this is for A2B
    #include extensions_a2billing_1_6.conf
    

    編輯 /etc/a2billing.conf

    修改 A2B DB 的連線資訊
    [database]
    hostname = <A2B DB Host>
    ; port for postgres is 5432 by default
    port = 3306
    user = a2billinguser
    password = <DB password>
    dbname = mya2billing
    ; dbtype setting can either be mysql or postgres
    dbtype = mysql 
    ...
    ... 
    
    安裝A2B語音檔
    cd sounds/
    sh install_a2b_sounds.sh
    
    chown -R asterisk:asterisk /var/lib/asterisk/sounds/ 
    

    註: 如果預設語音檔目錄不是 /var/lib/asterisk/sounds,必須修改 script 檔。

    設置 Outbound

    編輯 extensions_custom.conf:

    ; this is for A2B
    [macro-dialout-trunk-predial-hook]
    exten => s,1,GotoIf($["${OUT_${DIAL_TRUNK}:4:4}" = "A2B/"]?custom-freepbx-a2billing,${OUTNUM},1:2)
    exten => s,2,MacroExit
    
    [custom-freepbx-a2billing]
    exten => _X.,1,DeadAGI(a2billing.php,${OUT_${DIAL_TRUNK}:8})
    exten => _X.,n,Hangup()
    

    FreePBX Admin > Trunks > Add Custom Trunk

    • Trunk Name = A2B
    • Custom Dial String = A2B/3 (註: 在 A2B 系統必須新增一個 agi-conf3 用來給 sip client 使用 )
       

    FreePBX Admin >Outbound Routes > Add

    • Route Name = Out_All
    • Dial Patterns = 44.
    • Trunk Sequence = A2B
       

    對於 FreePBX 系統上的 SIP Extension,如果撥出時要由 A2B 計費,必須填上 account code。

    Powered by MindTouch Core