脚本搜集来自Rocky Linux 9安装Asterisk 20和freepbx 17脚本
#!/bin/bash#Preparacion de ambiente de RockyLinuxecho "Deshabilitar SELINUX /etc/selinux/config "sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/configecho "Establecer nombre de maquina"
hostnamectl set-hostname asterisk.localecho "Instalar repositorio de paquetes adicionales"
/usr/bin/dnf -y install epel-release/usr/bin/dnf -y update ca-certificates/usr/bin/dnf makecacheecho "Habilitar repositorio de herramientas adicionales de desarrollo Code Ready Builder"
/usr/bin/dnf config-manager --set-enabled crb
/usr/bin/dnf group -y install "Development Tools"
/usr/bin/dnf -y install git wget htop initscripts svn chkconfig mlocate nano#Instalar PHP 8.3
/usr/bin/dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
/usr/bin/dnf module reset php
/usr/bin/dnf module install php:remi-8.3 -y/usr/bin/dnf install httpd @php wget ncurses-devel sendmail sendmail-cf newt-devel libxml2-devel libtiff-devel gtk2-devel subversion kernel-devel git crontabs cronie cronie-anacron wget vim php-xml sqlite-devel net-tools gnutls-devel unixODBC php php-cli php-gd php-curl php-zip php-mbstring php-pear php-cgi php-common php-curl php-mbstring php-gd php-mysqlnd php-gettext php-bcmath php-zip php-xml php-json php-process php-snmp nodejs sox -yecho "Instalacion de BD"
dnf install mariadb-server unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel mariadb-connector-odbc -yecho "Actualizar sistema operativo"
/usr/bin/dnf -y updatesystemctl start mariadb
systemctl enable mariadb#/usr/bin/mysql_secure_installationecho "Realizando hardenizacion de MYSQL"mysql -sfu root <<EOS
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;
EOS#Instalacion de Asteriskecho "Instalando Asterisk"echo "Configurando BD"mysql -u root -ppassword -e "CREATE DATABASE asterisk;"
mysql -u root -ppassword -e "CREATE USER 'asterisk'@'%' IDENTIFIED BY 'password';"
mysql -u root -ppassword -e "CREATE DATABASE asterisk;"
mysql -u root -ppassword -e "GRANT ALL PRIVILEGES ON asterisk.* TO 'asterisk'@'%';"#exitodbcinst -q -d#/etc/odbc.iniecho "[asterisk-connector]
Description = MySQL connection to 'asterisk' database
Driver = MariaDB
Database = asterisk
Server = localhost
Port = 3306
Socket = /var/lib/mysql/mysql.sock" > /etc/odbc.ini#isql -v asterisk-connector asterisk password
#quitecho "Bajando archivos fuente"mkdir /opt/asterisk/
cd /opt/asterisk/
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz
tar -xvf asterisk-20-current.tar.gz
cd /opt/asterisk/asterisk-20.*echo "Configurando instalacion"/opt/asterisk/asterisk-20.*/contrib/scripts/get_mp3_source.sh
/opt/asterisk/asterisk-20.*/contrib/scripts/install_prereq install
/opt/asterisk/asterisk-20.*/configure --libdir=/usr/lib64 --with-jansson-bundled=yes#make menuselect
#Habilitar app_macro
make menuselect.makeopts
menuselect/menuselect --enable app_macro menuselect.makeoptsecho "Compilando binarios"make
make install
make basic-pbx
make configecho "Configurando usuarios y permisos"groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
chown -R asterisk:asterisk /etc/asterisk /var/{lib,log,spool}/asterisk /usr/lib64/asterisk
restorecon -vr {/etc/asterisk,/var/lib/asterisk,/var/log/asterisk,/var/spool/asterisk}sed -i 's/#AST_USER="asterisk"/AST_USER="asterisk"/g' /etc/sysconfig/asterisk
sed -i 's/#AST_GROUP="asterisk"/AST_GROUP="asterisk"/g' /etc/sysconfig/asterisksed -i 's/;runuser = asterisk/runuser = asterisk/g' /etc/asterisk/asterisk.conf
sed -i 's/;rungroup = asterisk/rungroup = asterisk/g' /etc/asterisk/asterisk.confecho '[directories](!)' >> /etc/asterisk/asterisk.conf
echo "astetcdir => /etc/asterisk" >> /etc/asterisk/asterisk.conf
echo "astmoddir => /usr/lib/asterisk/modules" >> /etc/asterisk/asterisk.conf
echo "astvarlibdir => /var/lib/asterisk" >> /etc/asterisk/asterisk.conf
echo "astdbdir => /var/lib/asterisk" >> /etc/asterisk/asterisk.conf
echo "astkeydir => /var/lib/asterisk" >> /etc/asterisk/asterisk.conf
echo "astdatadir => /var/lib/asterisk" >> /etc/asterisk/asterisk.conf
echo "astagidir => /var/lib/asterisk/agi-bin" >> /etc/asterisk/asterisk.conf
echo "astspooldir => /var/spool/asterisk" >> /etc/asterisk/asterisk.conf
echo "astrundir => /var/run/asterisk" >> /etc/asterisk/asterisk.conf
echo "astlogdir => /var/log/asterisk" >> /etc/asterisk/asterisk.conf
echo "astsbindir => /usr/sbin" >> /etc/asterisk/asterisk.confsetenforce 0echo "Configurando firewall"firewall-cmd --zone=public --add-service sip --permanent
firewall-cmd --zone=public --add-port=10000-20000/udp --permanentsystemctl enable asterisksystemctl start asterisk#Instalacion de FREEPBXecho "Instalacion de FREEPBX"echo "Bajando archivos fuente"mkdir -p /opt/freepbx
cd /opt/freepbx/
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-17.0-latest-EDGE.tgz
tar -xvf freepbx-*.tgz
cd freepbxecho "Instalando dependencias"echo "Configurando usuarios y permisos"chown -R asterisk:asterisk /var/www/*sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php.ini
sed -i 's/\(^memory_limit = \).*/\1256M/' /etc/php.ini
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/httpd/conf/httpd.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
sed -i 's/\(^user = \).*/\1asterisk/' /etc/php-fpm.d/www.conf
sed -i 's/\(^group = \).*/\1asterisk/' /etc/php-fpm.d/www.confsed -i 's/\(^listen.acl_users = apache,nginx\).*/\1,asterisk/' /etc/php-fpm.d/www.confecho "Habilitando servicios"systemctl enable httpd
systemctl start httpd
firewall-cmd --add-service={http,https} --permanent
firewall-cmd --reloadecho "Instalando FreePBX desde el instalador"/opt/freepbx/freepbx/install -n --dbuser root --dbpass passwordecho "FreePBX Instalado"IPADRESS=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1)echo "Reiniciando, favor de ir a la interfaz web en tu navegador para usar FreePBX. http://$IPADRESS "
echo "Rebooting, please go to web interface in your browser to start using FreePBX. http://$IPADRESS "reboot
脚本项目地址:
https://gist.github.com/mafairnet/87c9afddda60518f26e83b28fd8bb6ca
电子书参考资料:
www.freepbx.cn
www.asterisk.org.cn
https://www.wilivm.com/blog/almalinux-vs-rocky-linux-key-differences/