在Debian上安装freeswitch
<h1 id="在debian上安装freeswitch">在Debian上安装freeswitch</h1><p><strong>说明:</strong></p>
<ul>
<li>首次发表日期:2024-08-12</li>
<li>参考文档:
<ul>
<li>https://medium.com/@jogikrunal9477/ultimate-guide-to-installing-freeswitch-on-ubuntu-22-04-lts-3745ef6a6bd6</li>
<li>https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Installation/Linux/Deprecated-Installation-Instructions/Debian-Post-Install-Tasks_13172868/</li>
<li>https://blog.csdn.net/qq_36369267/article/details/131564019</li>
</ul>
</li>
</ul>
<h2 id="安装系统依赖">安装系统依赖</h2>
<p>查看系统版本:</p>
<pre><code class="language-bash">cat /etc/issue
</code></pre>
<pre><code>Debian GNU/Linux 12 \n \l
</code></pre>
<p>安装系统依赖:</p>
<p>参考 https://medium.com/@jogikrunal9477/ultimate-guide-to-installing-freeswitch-on-ubuntu-22-04-lts-3745ef6a6bd6</p>
<pre><code class="language-bash">sudo apt update
sudo apt-get install build-essential automake autoconf git-core wget libtool cmake pkg-config uuid-dev
sudo apt-get install libncurses5-dev libtiff-dev libjpeg-dev zlib1g-dev libssl-dev libsqlite3-dev
sudo apt-get install libpcre3-dev libspeexdsp-dev libspeex-dev libcurl4-openssl-dev libopus-dev libpq5 libpq-dev unixodbc-dev libldns-dev libedit-dev yasm liblua5.2-dev liblua5.2-0 libxml2-dev lua5.2 lua5.2-doc libtiff5-dev libsndfile1-dev unzip sngrep libreadline-dev ntpdate
sudo apt install python3 python3-venv python3-pip python3-distutils python3-dev
sudo apt install libavformat-dev libswscale-dev
</code></pre>
<h2 id="构建和安装依赖库">构建和安装依赖库</h2>
<h3 id="libks">libks</h3>
<ul>
<li>https://github.com/signalwire/libks</li>
</ul>
<pre><code class="language-bash">git clone -b v2.0.6 https://github.com/signalwire/libks.git
cd libks
cmake . -DCMAKE_BUILD_TYPE=Release
make -j 32
sudo make install
</code></pre>
<p>注意:可能需要注释掉<code>CMakeList.txt</code>中<code>Generate a Debian compliant changelog</code>的部分</p>
<h3 id="singalwire-c">singalwire-c</h3>
<ul>
<li>https://github.com/signalwire/signalwire-c</li>
</ul>
<pre><code class="language-bash">git clone -b v2.0.0 https://github.com/signalwire/signalwire-c.git
cd signalwire-c
cmake . -DCMAKE_BUILD_TYPE=Release
make -j 32
sudo make install
</code></pre>
<h3 id="spansdp">spansdp</h3>
<p>参考: https://blog.csdn.net/qq_36369267/article/details/131564019</p>
<pre><code class="language-bash">git clone https://github.com/freeswitch/spandsp.git
cd spandsp/
git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4
./bootstrap.sh -j
./configure
make -j 32
sudo make install
</code></pre>
<h3 id="sofia-sip">sofia-sip</h3>
<pre><code class="language-bash">git clone -b v1.13.17 https://github.com/freeswitch/sofia-sip.git
cd sofia-sip
./bootstrap.sh -j
./configure
make -j 32
sudo make install
</code></pre>
<h2 id="安装-freeswitch">安装 freeswitch</h2>
<pre><code class="language-bash">wget https://files.freeswitch.org/freeswitch-releases/freeswitch-1.10.12.-release.tar.gz
tar -xvf freeswitch-1.10.12.-release.tar.gz
cd freeswitch-1.10.12.-release
./configure --enable-core-odbc-support --enable-core-pgsql-support --with-python3=/usr/bin/python3
make -j 32
sudo make install
</code></pre>
<p>注意:</p>
<ul>
<li>源码打包为tar.gz前已经执行了<code>bootstrap.sh</code>了,所以不需要执行bootstrap.sh</li>
<li>如果使用较老的freeswitch版本和python3.10,可能需要修改configure文件,见: https://github.com/signalwire/freeswitch/issues/1479 和 https://github.com/alpinelinux/aports/commit/6a6cfc5ce576f1dc93b84b81718e9da1ddef626d</li>
</ul>
<p>安装声音文件:</p>
<pre><code class="language-bash"># 标准
sudo make sounds-install
sudo make moh-install
# 高清
sudo make cd-sounds-install
sudo make cd-moh-install
</code></pre>
<p>配置软链接:</p>
<pre><code class="language-bash">sudo ln -sf /usr/local/freeswitch/bin/freeswitch /usr/bin/
sudo ln -sf /usr/local/freeswitch/bin/fs_cli /usr/bin
sudo ln -s /usr/local/freeswitch/conf /etc/freeswitch
</code></pre>
<p>安装mod_python3:</p>
<pre><code class="language-shell">cd src/mod/languages/mod_python3/
make -j 32
sudo make install
# 安装完成后在/usr/local/freeswitch/mod 可以看到mod_python3.so和mod_python3.la文件
</code></pre>
<p>设置权限:</p>
<p>参考: https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Installation/Linux/Deprecated-Installation-Instructions/Debian-Post-Install-Tasks_13172868#set-owner-and-permissions</p>
<pre><code class="language-bash">sudo groupadd freeswitch
sudo usermod -a -G freeswitch $USER # 需要登出再登录使得权限生效
sudo adduser --quiet --system --home /usr/local/freeswitch --gecos 'FreeSWITCH open source softswitch' --ingroup freeswitch freeswitch --disabled-password
sudo chown -R freeswitch:freeswitch /usr/local/freeswitch/
sudo chmod -R 770 /usr/local/freeswitch/
sudo chmod -R 750 /usr/local/freeswitch/bin/
</code></pre>
<h2 id="运行">运行</h2>
<pre><code class="language-bash">freeswitch
</code></pre>
<p>其中</p>
<ul>
<li><code>/etc/freeswitch/</code>文件夹下存放配置文件</li>
<li><code>/usr/local/freeswitch/db</code>存放可能用到的sqlite数据库文件,如<code>core.db</code></li>
</ul>
<p>检查进程查看freeswitch是否在运行:</p>
<pre><code class="language-bash">ps aux | grep freeswitch
</code></pre>
<p>查看freeswitch监听的IP地址:</p>
<pre><code class="language-bash">netstat -an | grep 5060
</code></pre>
<p>停止freeswitch:</p>
<pre><code class="language-bash"># freeswitch 控制台
shutdown
# 终端
freeswitch -stop
</code></pre>
<p>后台启动(Deamon服务):</p>
<pre><code class="language-bash">freeswitch -nc
</code></pre>
<p>客户端连接:</p>
<pre><code class="language-bash">fs_cli
</code></pre>
<p>查看帮助:</p>
<pre><code class="language-bash">freeswitch -help
</code></pre>
<h2 id="配置为系统服务开机启动">配置为系统服务(开机启动)</h2>
<p>创建service文件:</p>
<pre><code class="language-bash">sudo vi /etc/systemd/system/freeswitch.service
</code></pre>
<p>粘贴如下内容:</p>
<pre><code class="language-yaml">
Description=FreeSWITCH
Wants=network-online.target
Requires=network.target local-fs.target
After=network.target network-online.target local-fs.target
Type=forking
PIDFile=/usr/local/freeswitch/run/freeswitch.pid
Environment="DAEMON_OPTS=-nonat"
Environment="USER=freeswitch"
Environment="GROUP=freeswitch"
EnvironmentFile=-/etc/default/freeswitch
ExecStartPre=/bin/chown -R ${USER}:${GROUP} /usr/local/freeswitch
ExecStart=/usr/local/freeswitch/bin/freeswitch -u ${USER} -g ${GROUP} -ncwait ${DAEMON_OPTS}
TimeoutSec=45s
Restart=always
WantedBy=multi-user.target
</code></pre>
<p>Reload systemd daemon:</p>
<pre><code class="language-bash">sudo systemctl daemon-reload
</code></pre>
<p>开启和启动服务:</p>
<pre><code>sudo systemctl enable freeswitch.service
sudo systemctl start freeswitch.service
</code></pre>
<p>查看服务状态:</p>
<pre><code>sudo systemctl status freeswitch.service
</code></pre>
<h2 id="wsl端口转发">WSL端口转发</h2>
<p>参考:</p>
<ul>
<li>https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc776297(v=ws.10)</li>
<li>https://blog.csdn.net/u013600225/article/details/52088196</li>
</ul>
<p>本次测试的debian是在WSL下安装的,故需要配置端口转发</p>
<p>首先,获取debian的ip地址(powershell)</p>
<pre><code class="language-shell">wsl ifconfig eth0
</code></pre>
<p>powershell管理员模式下添加端口映射:</p>
<pre><code class="language-shell"># 添加配置: 本机监听5060端口,当有socket连接到5060端口时,本机就连接到172.26.90.29的connectport=5060端口,本机的5060端口可以接受的连接地址为"*",使用的协议为tcp,当前仅支持传输控制协议 (TCP)。
netsh interface portproxy add v4tov4 listenport=5060 connectaddress=172.26.90.29 connectport=5060 listenaddress=* protocol=tcp
</code></pre>
<p>查看所有映射</p>
<pre><code class="language-shell">netsh interface portproxy show all
</code></pre>
<p>删除映射</p>
<pre><code class="language-shell">netsh interface portproxy delete v4tov4 listenaddress=* listenport=5060
</code></pre>
<blockquote>
<p>注意:使用软电话(eyebeam和Linphone)时,需要将协议改为tcp</p>
</blockquote>
<p>可能需要打开防火墙,允许5060端口(不确定是否需要):</p>
<pre><code class="language-shell"># add inbound rule(添加入站规则)
netsh advfirewall firewall add rule name= "WSL freeswitch" dir=in action=allow protocol=TCP localport=5060
# add outbound rule(添加出站规则)
netsh advfirewall firewall add rule name= "WSL freeswitch" dir=out action=allow protocol=TCP localport=5060
# reset(删除规则)
netsh advfirewall firewall delete rule name="WSL freeswitch"
</code></pre><br><br>
来源:https://www.cnblogs.com/shizidushu/p/18354678
頁:
[1]