第一步,安装系统依赖

sudo apt install curl wget git subversion build-essential autoconf automake libtool libncurses5 libncurses5-dev make libjpeg-dev libtool libtool-bin libsqlite3-dev libpcre3-dev libspeexdsp-dev libldns-dev libedit-dev yasm liblua5.2-dev libopus-dev cmake libtiff-dev  libcodec2-dev libcodec2-dev portaudio19-dev libmagickcore-dev libmp3lame-dev libmpg123-dev libshout3-dev libvlc-dev libpq-dev libmariadb-dev libldap2-dev erlang librabbitmq-dev libsmpp34-dev libyaml-dev libmongoc-dev libopencv-dev  libmemcached-dev libavformat-dev  libh2o-dev libsoundtouch-dev libhiredis-dev libopus-dev  autoconf automake devscripts gawk gettext libcurl4-openssl-dev libdb-dev libedit-dev libgdbm-dev libldns-dev libncurses5-dev libopus-dev libopus-ocaml libpcre3-dev libperl-dev libpq-dev libspeex-dev libspeexdsp-dev libssl-dev libtiff5-dev libtool libtool-bin libvorbis0a libogg0 libsqlite3-dev libogg-dev libvorbis-dev portaudio19-dev libshout3-dev libmpg123-dev libmp3lame-dev yasm libbsd-dev flite flite1-dev libflite1 liblua5.2-0 liblua5.2-dev lua5.2 luarocks libsndfile-dev -y

第二步,把gcc g++ 降级到gcc 10

sudo apt install gcc-10 g++-10 cpp-10 -y 
sudo ln -s /usr/bin/gcc-10 /usr/bin/gcc 
sudo ln -s /usr/bin/g++-10 /usr/bin/g++

第三步,安装openssl1.1.1
原因是Ubuntu22默认是OpenSSL3了,libks只支持openssl1.1.1,所以如果需要编译libks的话,就需要安装这个.

mkdir -p ~/opt/openssl 
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate -P ~/opt/openssl/
tar -xzvf ~/opt/openssl/openssl-1.1.1q.tar.gz -C ~/opt/openssl/ 
cd ~/opt/openssl/openssl-1.1.1q
./config
make 
sudo make install
sudo cp /usr/local/bin/openssl /usr/bin/openssl

第四步,安装Spandsp

cd ~/opt
git clone https://github.com/freeswitch/spandsp ~/opt/spandsp
git reset --hard 67d2455efe02e7ff0d897f3fd5636fed4d54549e 

这个是解决常量未定义问题的.error: ‘V18_MODE_5BIT_4545’ undeclared

cd ~/opt/spandsp
./bootstrap.sh
./configure
make
sudo make install 

第五步,安装Sofia-sip (SIP User-Agent library)

cd ~/opt
git clone https://github.com/freeswitch/sofia-sip.git ~/opt/sofia-sip
cd ~/opt/sofia-sip
./bootstrap.sh
./configure
make
sudo make install 

第六步,安装freeswitch

cd ~/opt
git clone https://github.com/signalwire/freeswitch.git -b v1.10 ~/opt/freeswitch

这个源码也可以在官网下载
https://files.freeswitch.org/releases/freeswitch/
https://files.freeswitch.org/releases/freeswitch/freeswitch-1.10.10.-release.tar.xz

cd ~/opt/freeswitch

禁用二个模块

vi ~/opt/freeswitch/modules.conf

注释掉mod_verto和mod_signalwire,在上面的文件中,找到对应行,在行首加上#号即可.如果需要安装这二个模块,也可以编译安装,见后面.

./bootstrap.sh -j
CFLAGS=-Wno-error ./configure --prefix=/usr/local/freeswitch --enable-core-pgsql-support --enable-zrtp
make
sudo make install

然后运行

sudo /usr/local/freeswitch/bin/freeswitch -nc

也可以建立符号连接,

sudo ln -s /usr/local/freeswitch/bin/freeswitch /usr/bin/freeswitch
sudo ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli

   
启动FreeSwitch服务器,

sudo freeswitch -nc

启动FreeSwitch客户端,

fs_cli

补充:
安装libks

cd ~/opt
git clone https://github.com/signalwire/libks.git
cd libks
cmake .
make
sudo make install

安装signalwire

cd ~/opt
git clone https://github.com/signalwire/signalwire-c.git
cd signalwire-c
cmake .
make
sudo make install

将上述补充模块安装完成后,再编译freeswitch功能.

参考:
https://soufianebouchaa.medium.com/freeswitch-ci-cd-on-ubuntu-22-04-debian-11-part-1-75fb1be97316
https://blog.csdn.net/weixin_43805407/article/details/130692942
https://blog.csdn.net/szkbsgy/article/details/126431526
https://github.com/signalwire/freeswitch/issues/2158
https://blog.csdn.net/qq_36369267/article/details/131564019
https://files.freeswitch.org/releases/freeswitch/

查看freeswitch监听端口

sudo netstat -natp |grep freeswitch

结果:

tcp        0      0 192.168.4.122:5066      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp        0      0 192.168.4.122:5060      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp        0      0 192.168.4.122:5080      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp        0      0 192.168.4.122:7443      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp        0      0 192.168.4.122:8081      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp        0      0 192.168.4.122:8082      0.0.0.0:*               LISTEN      133967/freeswitch   
tcp6       0      0 ::1:8081                :::*                    LISTEN      133967/freeswitch   
tcp6       0      0 ::1:8082                :::*                    LISTEN      133967/freeswitch   
tcp6       0      0 :::8021                 :::*                    LISTEN      133967/freeswitch   
tcp6       0      0 ::1:5080                :::*                    LISTEN      133967/freeswitch   
tcp6       0      0 ::1:5060                :::*                    LISTEN      133967/freeswitch 

freeswitch添加用户密码
FreeSwitch 中默认配置了20个用户,分别是: 1000 到 1019。在 /usr/local/freeswitch/etc/freeswitch/directory/default 目录下有每个用户的XML配置文件。

ls -lh
1000.xml  1002.xml  1004.xml  1006.xml  1008.xml  1010.xml  1012.xml  1014.xml  1016.xml  1018.xml  brian.xml    example.com.xml
1001.xml  1003.xml  1005.xml  1007.xml  1009.xml  1011.xml  1013.xml  1015.xml  1017.xml  1019.xml  default.xml  skinny-example.xml

随便找个文件看看里面的内容

cat 1000.xml 

<include>
  <user id="1000">
    <params>
      <param name="password" value="$${default_password}"/>
      <param name="vm-password" value="1000"/>
    </params>
    <variables>
      <variable name="toll_allow" value="domestic,international,local"/>
      <variable name="accountcode" value="1000"/>
      <variable name="user_context" value="default"/>
      <variable name="effective_caller_id_name" value="Extension 1000"/>
      <variable name="effective_caller_id_number" value="1000"/>
      <variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
      <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
      <variable name="callgroup" value="techsupport"/>
    </variables>
  </user>
</include>

要修改密码的话,直接将$${default_password}修改为明文密码就可以了.

若想新添加一个用户,可以通过如下步骤进行:

(1)在/usr/local/freeswitch/etc/freeswitch/directory/default/增加一个用户配置文件.如下所示:

<include>
  <user id="1020">
    <params>
      <param name="password" value="$${default_password}"/>
      <param name="vm-password" value="1020"/>
    </params>
    <variables>
      <variable name="toll_allow" value="domestic,international,local"/>
      <variable name="accountcode" value="1020"/>
      <variable name="user_context" value="default"/>
      <variable name="effective_caller_id_name" value="Extension 1020"/>
      <variable name="effective_caller_id_number" value="1020"/>
      <variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
      <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
      <variable name="callgroup" value="techsupport"/>
    </variables>
  </user>
</include>

修改拨号计划,以使得其他用户可以呼到他。如下操作:

在/usr/local/freeswitch/etc/freeswitch//dialplan/default.xml中,修改如下语句:

<extension name="Local_Extension"><condition field="destination_number" expression="^(10[01][0-9])$">

为 :

<extension name="Local_Extension"><condition field="destination_number" expression="^(10[012][0-9])$">

fs_cli 中运行 reloadxml,即可生效。

来自:freeswitch常见问题(https://cloud.tencent.com/developer/article/2303645)

关闭freeswitch

sudo freeswitch -stop

freeswitch在使用jssip的时候,发现很占CPU资源,应该是服务器端进行了音视频的编解码,可以在配置文件中关闭编解码,做为一个单独的代理使用.就不会占用服务器资源了.
freeswitch 配置代理模式:
配置方式:

1、conf/sip_profiles/internal.xml 在 sip_profile 中,打开如下代码(其他不打开):

<param name="inbound-proxy-media" value="true"/>
2、dialplan/default.xml开始处的action一行之下,加上:

<action application="set" data="proxy_media=true"/>

Referenced from:https://developer.aliyun.com/article/828793

freeswitch监听的端口

8021 : Event Socket

5060 : internal profile 监听的端口

5061 : internal profile tls 监听的端口

5080 : external profile 监听的端口

5081 : external profile tls 监听的端口

5066 : WebSocket 监听的端口

7443 : WebSocket tls 监听的端口

8081 : mod_verto 监听的端口

8082 : mod_verto tls 监听的端口

freeswitch RTP 端口范围
// vi conf/autoload_config/switch.conf.xml
<param name="rtp-start-port" value="16384">
<param name="rtp-end-port" value="32768">
Referenced from:https://github.com/xiaosongfu/books/blob/master/freeswitch/%25E7%25AB%25AF%25E5%258F%25A3%25E5%258D%25A0%25E7%2594%25A8%25E6%2583%2585%25E5%2586%25B5.md

freeswitch使用webrtc的方法:

JS可以用Verto(https://github.com/roman-yerin/vertojs),Android,Windows,Linux可以用linphone的SDK(https://linphone.org/technical-corner/liblinphone)

freeswitch常用号码

9192 - Info test (prints information to the command line interface).
9193 - Video record test (records video to /tmp/testrecord.fsv)
9194 - Video playback test (plays video from /tmp/testrecord.fsv)
9195 - Echo test (5-second delay before returning echo).
9196 - Echo test (real-time).
9197 - Play milliwatt test tone.
9198 - Tetris, synthesized via tone streaming.
9664 - Test Music On Hold out (if you installed sound files).

freeswitch bypass

confsip_profilesinternal.xml中在sip_profile 中设置bypass-media模式,其他模式注释掉,

<param name="inbound-bypass-media" value="true"/>
还要在Dailplan中的default.xml的local-extension中
设置bypass-media=true

freeswitch proxy

confsip_profilesinternal.xml 在 sip_profile 中设置proxy media 模式,其他模式注释掉,

<param name="inbound-proxy-media" value="true"/>

还要在Dailplan中 ,在打电话bridge 之前

<param name="set" value="proxy_media=true"/>

sip 相关请求头
Request Method Purpose
INVITE Invite the callee into a session
OPTIONS Discover the capabilities of the receiver
BYE Terminate a call or call request
CANCEL Terminate incomplete call requests
ACK Acknowledge a successful response
REGISTER Register the current location of a user

windows 下安装配置freeswitch

下载最新版的安装包: https://files.freeswitch.org/windows/installer/x64/FreeSWITCH-1.10.10-Release-x64.msi
也可以选择自己熟悉的包:
https://files.freeswitch.org/windows/installer/x64/

安装选择完全安装.

修改配置文件

C:Program FilesFreeSWITCHconfvars.xml
将默认密码1234修改为其他的密码.
<X-PRE-PROCESS cmd="set" data="default_password=11223344"/>

局域网运行时,修改相应的IP地址,配置文件同上
<X-PRE-PROCESS cmd="stun-set" data="external_rtp_ip=stun:stun.freeswitch.org"/>
修改为
<X-PRE-PROCESS cmd="stun-set" data="external_rtp_ip=192.168.4.122"/>

<X-PRE-PROCESS cmd="stun-set" data="external_sip_ip=stun:stun.freeswitch.org"/>
修改为
<X-PRE-PROCESS cmd="stun-set" data="external_sip_ip=192.168.4.122"/>

修改C:Program FilesFreeSWITCHconfautoload_configsmodules.conf.xml
屏掉mod_signalwire,将
<load module="mod_signalwire"/>
替换为
<!-- <load module="mod_signalwire"/> -->

删除sip_profiles中与ipv6相关的文件与文件夹

运行命令,在管理员权限下运行
FreeSwitchConsole.exe -nonat

窗口出来后,按F8可提供Debug 日志显示.

查看运行是否正常执行sofia status命令.

局域网测试的拨号配置在dialplan/default.xml中的Local_Extension

下载windows下测试工个linphone
https://linphone.org/releases/windows/latest_app_win64
https://www.linphone.org/technical-corner/linphone

下载后文件如下:
Linphone-5.1.2-win64.exe

修改sip_profiles/internal.xml
<param name="apply-candidate-acl" value="wan_v4.auto"/>
<param name="apply-candidate-acl" value="localnet.auto"/>
<param name="apply-candidate-acl" value="rfc1918.auto"/>
<param name="apply-candidate-acl" value="any_v4.auto"/>
不知道有什么作用,说是可以解决acl拦截的问题,暂时未发现这样修改有优势.

在autoload_configs/vcl.conf.xml中增加了
<list name="wan.auto" default="allow">

<node type="allow" cidr="192.168.4.0/24"/>

</list>

不知道有什么使用..

error: 'V18_MODE_5BIT_4545' undeclared

修改mod_spandsp_dsp.c文件
将V18_MODE_5BIT_4545 改为 V18_MODE_WEITBRECHT_5BIT_4545
将V18_MODE_5BIT_50 改为 V18_MODE_WEITBRECHT_5BIT_4545
将v18_init函数后面加二个参数NULL,NULL

https://github.com/signalwire/freeswitch/issues/2158

ubuntu 20.04 docker 编译安装 freeswitch 1.10.10

主要参考这个网址: https://gist.github.com/cyrenity/96cc1ad7979b719b1c684f90aa0f526d

apt install --yes build-essential pkg-config uuid-dev zlib1g-dev libjpeg-dev libsqlite3-dev libcurl4-openssl-dev \
        libpcre3-dev libspeexdsp-dev libldns-dev libedit-dev libtiff5-dev yasm libopus-dev libsndfile1-dev unzip \
        libavformat-dev libswscale-dev libavresample-dev liblua5.2-dev liblua5.2-0 cmake libpq-dev \
        unixodbc-dev autoconf automake ntpdate libxml2-dev libpq-dev libpq5 sngrep

apt install -y git vim net-tools iputils-ping 

编译libks

git clone https://github.com/signalwire/libks.git /usr/local/src/libks
cd /usr/local/src/libks
cmake .
make &&  make install

编译libsignalwire

git clone https://github.com/signalwire/signalwire-c.git /usr/local/src/signalwire-c
cd /usr/local/src/signalwire-c
cmake .
make && make install

编译sofia-sip

git clone https://github.com/freeswitch/sofia-sip /usr/local/src/sofia-sip
cd /usr/local/src/sofia-sip
./bootstrap.sh 
./configure
make && make install

编译spandsp

git clone https://github.com/freeswitch/spandsp /usr/local/src/spandsp
cd /usr/local/src/spandsp
./bootstrap.sh 
./configure
make &&  make install

下载freeswitch 1.10.10,使用1.10.7编译时,会报一个找不到libks的错误,使用1.10.10就没有这个问题.

wget https://files.freeswitch.org/releases/freeswitch/freeswitch-1.10.10.-release.tar.xz
tar -zxvf freeswitch-1.10.10.-release.tar.xz
cd freeswitch-1.10.10.-release
./configure 
make && make install

可选 

make cd-sounds-install
make cd-moh-install 
ln -s /usr/local/freeswitch/conf /etc/freeswitch 
ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli 
ln -s /usr/local/freeswitch/bin/freeswitch /usr/sbin/freeswitch

到此,就可以直接运行freeswitch -nonat 来试运行一下了.

vi autoload_configs/switch.conf.xml

修改rtp port 范围

   <param name="rtp-start-port" value="63535"/>

 <param name="rtp-end-port" value="65535"/>

stun:freeswitch.org 的网址有可能经常获取不到.所以还是老实配置为固定IP地址吧.这样省事.

docker 映射的端口
0.0.0.0:5060->5060/tcp, 0.0.0.0:5066->5066/tcp, 0.0.0.0:5060->5060/udp, 0.0.0.0:5080->5080/tcp, 0.0.0.0:7443->7443/tcp, 0.0.0.0:8021->8021/tcp, 0.0.0.0:5080->5080/udp, 0.0.0.0:8081->8081/tcp, 0.0.0.0:62535-65535->62535-65535/udp

还要记得在服务器上防火墙或者安全组打开相应的端口才行.

fs_cli无法连接到freeswitch服务器

使用netstat -nat 发现没有监听8021端口

修改

/usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml

<param name="listen-ip" value="::"/>

修改为

<param name="listen-ip" value="0.0.0.0"/>

重启freeswitch即可.

freeswitch与webrtc通话配置

在conf/sip_profiles/internal.xml中添加

<param name="apply-candidate-acl" value="rfc1918.auto" />
<param name="apply-candidate-acl" value="localnet.auto" />

最后类似这样

<param name="apply-candidate-acl" value="rfc1918.auto" />
<param name="apply-candidate-acl" value="localnet.auto" />
</settings>
</profile>

fs_cli 退出命令
使用/exit 或者ctrl+d快捷键

在使用scp命令传输文件的时候,碰到了服务器上目录中包含空格的情况,对于这种情况,需要将地址加上双引号,并且空格前加入,这样才能够正确识别。

scp -r root@192.168.0.51:"/home/xxj/Documents/files/xx\ xx\ jj.tar.gz" ./

Referenced from:https://www.jianshu.com/p/11e3beb6d766

在 Ubuntu 中,我们可以找到一个诊断工具来控制错误报告,只需在应用程序启动器中搜索“诊断”,它就会出现。

然后取消选中该选项:向 Canonical 发送错误报告

从终端禁用 Appport
要禁用 apport 错误报告功能,只需打开终端并使用 nano 编辑 /etc/default/apport :

nano /etc/default/apport

将启用值更改为 0:

enabled=0

Referenced from:https://www.onitroad.com/jc/faq/disable-error-reporting-ubuntu.html

golang 获取指定uid 的用户目录

package main

import (
    "fmt"
    "os/user"
)

func main() {
    u, err := user.Current()
    if err != nil {
        fmt.Println("error")
    }
    fmt.Printf("u.Uid: %s, u.Gid: %s, u.Name: %s, u.HomeDir: %s, u.Username: %s\n",
        u.Uid, u.Gid, u.Name, u.HomeDir, u.Username)

    lu, err := user.Lookup("wohu")
    if err != nil {
        fmt.Println("error")
    }
    fmt.Printf("lu.Uid: %s, lu.Gid: %s, lu.Name: %s, lu.HomeDir: %s, lu.Username: %s\n",
        lu.Uid, lu.Gid, lu.Name, lu.HomeDir, lu.Username)

    li, err := user.LookupId("1000")
    if err != nil {
        fmt.Println("error")
    }
    fmt.Printf("li.Uid: %s, li.Gid: %s, li.Name: %s, li.HomeDir: %s, li.Username: %s\n",
        li.Uid, li.Gid, li.Name, li.HomeDir, li.Username)

    lg, err := user.LookupGroup("wohu")
    if err != nil {
        fmt.Println("error")
    }
    fmt.Printf("lg.Gid: %s, lg.Name: %s\n",
        lg.Gid, lg.Name)

    lgi, err := user.LookupGroupId("1000")
    if err != nil {
        fmt.Println("error")
    }
    fmt.Printf("lgi.Gid: %s, lgi.Name: %s\n",
        lgi.Gid, lgi.Name)

}

Referenced from:https://blog.csdn.net/wohu1104/article/details/106433469

第一步:在Ubuntu 22上安装Docker

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update
sudo apt install docker-ce
sudo systemctl status docker

设置不用sudo也能运行docker的方法

sudo usermod -aG docker ${USER}
su - ${USER}

这时运行 docker ps 应该就可以了.
参考网址:https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
第二步:运行freeswitch docker
没有轮子就造个轮子

mkdir freeswitch
cd freeswitch
vi Dockerfile

新建Dockerfile文件,输入以下内容

FROM ubuntu:latest
LABEL maintainer="Your Name <your.email@example.com>"

RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    autoconf \
    automake \
    libtool \
    libncurses5-dev \
    wget \
    libjpeg-dev \
    zlib1g-dev \
    libsqlite3-dev \
    libssl-dev \
    libcurl4-openssl-dev \
    libpcre3-dev \
    libspeexdsp-dev \
    libldns-dev \
    libedit-dev \
    libopus-dev \
    libsndfile1-dev \
    liblua5.3-dev \
    libspandsp-dev

RUN git clone https://github.com/signalwire/freeswitch.git /usr/src/freeswitch

WORKDIR /usr/src/freeswitch

RUN ./bootstrap.sh -j
RUN ./configure --prefix=/usr/local/freeswitch
RUN make && make install

ENV PATH="/usr/local/freeswitch/bin:${PATH}"

EXPOSE 5060 5061 5080 5081

CMD ["freeswitch", "-nonat"]

运行以下命令构建Docker镜像:
docker build -t freeswitch . --build-arg http_proxy=socks5://192.168.4.64:10008 --build-arg https_proxy=socks5://192.168.4.64:10008
这将会基于Dockerfile中的内容构建一个名为freeswitch的Docker镜像。这个构建docker部分的参考了这个链接:https://juejin.cn/post/7288165091979853883
但是编译不成功.太费劲了.

这个是编译成功的,手动编译freeswitch过程见链接:https://const.net.cn/760.html