GNU/Linux >> Linux の 問題 >  >> Debian

NGINX+DebianでのPlaySMSKannelSMSゲートウェイの統合

この投稿は、NGINX+DebianでのPlaySMSKannelSMSゲートウェイの統合に関するものです

PlaySMS:

PlaySMSは、無料のオープンソースSMS管理ソフトウェアであり、SMSゲートウェイおよびバルクSMSサービス用のWebインターフェイスです。この記事では、NGINXWebサーバーとMariaDBデータベースを使用してDebian10でPlaySMSを構成します。 PlaySMSWebアプリケーションとKannelSMSGatewayを実行するにはPHPが必要です。 Kannel SMS Gatewayをインストールするには、この記事を確認してください。

LAB環境ホスト情報:

PlaySMSおよびKannelサーバーのホストIP:192.168.10.38
クライアントホストIP:192.168.10.31

NGINXのインストール:

公式NGINXリポジトリからビルド済みのDebianパッケージを使用します

NGINXパッケージとリポジトリ署名キーをダウンロードしてaptプログラムのキーリングに追加します:

root@sms-gw:~# wget https://nginx.org/keys/nginx_signing.key
root@sms-gw:~# apt-key add nginx_signing.key

NGINXソースリストを追加するには、 /etc/apt/sources.list.d/nginx.listを作成します 以下の内容のファイル

deb https://nginx.org/packages/debian/ buster nginx
deb-src https://nginx.org/packages/debian/ buster nginx

リポジトリリストを更新し、NGINXをインストールします

root@sms-gw:~# apt-get update
root@sms-gw:~# apt-get install –y nginx

NGINXサービスを有効にして開始し、NGINXサーバーが稼働していることを確認します。

root@sms-gw:~# systemctl enable nginx.service
root@sms-gw:~# systemctl start nginx.service
root@sms-gw:~# netstat –lntp
root@sms-gw:~# curl -l 127.0.0.1

クライアントマシンから:

NGINXサーバーが実行され、デフォルトのページが表示されています。

PHPのインストール:

次に、PlaySMSに必要なPHP、PHP-FPM、およびその他のPHPパッケージをインストールします

root@sms-gw:~# apt-get install –y php php-fpm php-mysql php7.3-mysql php7.3-cli php7.3-common php7.3-xml php7.3-xmlrpc php7.3-mbstring php7.3-gd php7.3-curl

PHP7.3-FPMサービスを有効にして開始し、ステータスを確認します

root@sms-gw:~# systemctl enable php7.3-fpm.service
root@sms-gw:~# systemctl start php7.3-fpm.service
root@sms-gw:~# systemctl status php7.3-fpm.service

PlaySMSのNGINX構成:

/etc/nginx/fastcgi.confを作成します vimを使用して以下の内容のファイル

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

www-dataを変更します nginxへのユーザーとグループ /etc/php/7.3/fpm/pool.d/www.conf 以下の構成ディレクティブの場合

ユーザー=www-data
グループ=www-data
listen.owner =www-data
listen.group =www-data

に変更

ユーザー=nginx
グループ=nginx
listen.owner =nginx
listen.group =nginx

root@sms-gw:~# sed -i 's/www-data/nginx/g'  /etc/php/7.3/fpm/pool.d/www.conf

PlaySMSのNGINXデフォルト設定ファイルをFPM/FastCGIで実行するように置き換えます

root@sms-gw:~# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bk
root@sms-gw:~# vim /etc/nginx/conf.d/default.conf

以下の行を/etc/nginx/conf.d/default.confに追加します PlaySMSの場合

server {
   listen       80;
   root   /usr/share/nginx/html;
   index  index.php index.html index.htm;
   server_name  _;

    access_log  /var/log/nginx/playsms_access.log;
   error_log   /var/log/nginx/playsms_error.log;

    charset utf-8;

    location / {
       try_files $uri $uri/ =404;
   }

   location ~ .php {
       include fastcgi.conf;
       fastcgi_split_path_info ^(.+.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.3-fpm.sock;
       }

   location ~ /\.ht {
       deny  all;
   }
}

PHPのローカルタイムゾーンを設定する必要があります。

コメントを外してdate.timezoneを設定します [Date]の下のconfigディレクティブ /etc/php/7.3/cli/php.iniのセクション および/etc/php/7.3/fpm/php.ini タイムゾーンの現地時間を取得します。例:ニューヨークの場合、米国の構成は次のようになります

date.timezone = America/New_York

php7.3-fpmを再起動します タイムゾーン情報を変更した後のサービス。

root@sms-gw:~# systemctl restart php7.3-fpm.service

注: タイムゾーンリストについては、https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

にアクセスしてください。

NGINXルートディレクトリにテストページを配置して、NGINXでPHP構成を確認します

root@sms-gw:~# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php

http://192.168.10.38/info.phpを閲覧する クライアントマシンから

PHPは、PHP-FPMソケットを使用し、PHP情報を表示するNGINXで正しく動作します。

MariaDBのインストール:

PlaySMSのデータベースサービスが必要になります。ここではMariaDBを使用しています。

aptキーリングにMariaDBのキーをインポートする

root@sms-gw:~# apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

MariaDBのソースリストを準備します。/etc/apt/sources.list.d/MariaDB.listを作成します。 以下の行を含むファイル

# MariaDB 10.3 repository list - created 2021-12-28 18:41 UTC
# https://mariadb.org/download/
deb [arch=amd64,arm64,ppc64el] https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main
deb-src https://download.nus.edu.sg/mirror/mariadb/repo/10.3/debian buster main

リポジトリリストを更新し、MariaDBをインストールします

root@sms-gw:~# apt-get update
root@sms-gw:~# apt-get install –y mariadb-server

MariaDBのrootパスワードを指定するように求められた場合は、エスケープします。後で設定します

MariaDBサービスを有効にして開始する

root@sms-gw:~# systemctl enable mariadb.service
root@sms-gw:~# systemctl start mariadb.service

mysql_secure_installationを実行します rootパスワードおよびその他のセキュリティディレクティブを以下のように設定するコマンド

rootパスワードを設定しますか? [Y / n] Y
MariaDBのルートパスワードを設定する
匿名ユーザーを削除しますか? [Y / n] Y
rootログインをリモートで禁止しますか? [Y / n] Y
テストデータベースを削除してアクセスしますか? [Y / n] Y
そして最後に …
今すぐ特権テーブルをリロードしますか? [Y / n] Y

MariaDBでPlaySMSデータベースとユーザーを作成する

root@sms-gw:~# mysql -u root –p
MariaDB [(none)]> CREATE DATABASE playsms;
MariaDB [(none)]> CREATE USER 'playsmsuser'@'localhost' IDENTIFIED BY 'playsmsSecuredPassword';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON playsms.* TO 'playsmsuser'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

これで、MariaDBでPlaySMSの準備が整いました。

PlaySMSのインストール:

依存関係をインストールする

root@sms-gw:~# apt-get install -y zip

playsmsを追加します ユーザー

root@sms-gw:~# adduser playsms --disabled-password --home=/usr/local/playsms/

ログディレクトリを作成し、適切な権限を設定します

root@sms-gw:~# mkdir /var/log/playsms
root@sms-gw:~# chown nginx:nginx -R /var/log/playsms

playsmsに切り替えます ユーザー

root@sms-gw:~# su - playsms

最新のPlaySMS公式リリースフォームをダウンロードして解凍しますhttps://github.com/playsms/playsms/archive/refs/tags/1.4.5.tar.gz

playsms@sms-gw:~$ cd /tmp/
playsms@sms-gw:/tmp$ wget https://github.com/playsms/playsms/archive/refs/tags/1.4.5.tar.gz
playsms@sms-gw:/tmp$ mv 1.4.5.tar.gz playsms-1.4.5.tar.gz
playsms@sms-gw:/tmp$ tar -zxf playsms-1.4.5.tar.gz
playsms@sms-gw:/tmp$ cd playsms-1.4.5/

注: 1.4.5より前のバージョンのPlaySMSは使用しないでください。バージョン1.4.5で修正されたセキュリティの脆弱性があります

install.confを作成します 以下の内容のファイル

DBUSER="playsmsuser"
DBPASS="playsmsSecuredPassword"
DBNAME="playsms"
DBHOST="localhost"
DBPORT="3306"
WEBSERVERUSER="nginx"
WEBSERVERGROUP="nginx"
PATHSRC="$(pwd)"
PATHWEB="/usr/local/playsms/html"
PATHLIB="/usr/local/playsms/lib"
PATHBIN="/usr/local/playsms/bin"
PATHLOG="/var/log/playsms"
PATHCONF="/usr/local/playsms/etc"

install-playsms.shを実行します PlaySMSをインストールするファイル

インストールデータを確認し、各ステップを確認します

playsms@sms-gw:/tmp/playsms-1.4.5$ ./install-playsms.sh

playSMS Install Script for Ubuntu (Debian based)
==================================================================
WARNING:
- This install script WILL NOT upgrade currently installed playSMS
- This install script WILL REMOVE your current playSMS database
- This install script is compatible ONLY with playSMS version 1.4
- Please BACKUP before proceeding
==================================================================

You are NOT running this installation script as root
That means you need to make sure that this Linux user has
permission to create necessary directories

==================================================================

Proceed ?

When you're ready press [y/Y] or press [Control+C] to cancel Y

==================================================================

INSTALL DATA:

MySQL username      = playsmsuser
MySQL password      = playsmsSecuredPassword
MySQL database      = playsms
MySQL host          = localhost
MySQL port          = 3306

Web server user     = nginx
Web server group    = nginx

playSMS source path = /tmp/playsms-1.4.5

playSMS web path    = /usr/local/playsms/html
playSMS lib path    = /usr/local/playsms/lib
playSMS bin path    = /usr/local/playsms/bin
playSMS log path    = /var/log/playsms

playSMS conf path   = /usr/local/playsms/etc

==================================================================

Please read and confirm INSTALL DATA above

When you're ready press [y/Y] or press [Control+C] to cancel Y

==================================================================

Are you sure ?

Please read and check again the INSTALL DATA above

When you're ready press [y/Y] or press [Control+C] to cancel Y

==================================================================

Installation is in progress

DO NOT press [Control+C] until this script ends

==================================================================

Getting composer from https://getcomposer.com

Please wait while the install script downloading composer

Composer is ready in this folder

Pleas wait while composer getting and updating required packages

Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files

Composer has been installed and packages has been updated

Start................end

PLAYSMSD_CONF = /usr/local/playsms/etc/playsmsd.conf
PLAYSMS_PATH = /usr/local/playsms/html
PLAYSMS_LIB = /usr/local/playsms/lib
PLAYSMS_BIN = /usr/local/playsms/bin
PLAYSMS_LOG = /var/log/playsms
DAEMON_SLEEP = 1
ERROR_REPORTING = E_ALL ^ (E_NOTICE | E_WARNING)
IS_RUNNING =
PIDS schedule =
PIDS ratesmsd =
PIDS dlrssmsd =
PIDS recvsmsd =
PIDS sendsmsd =

playsmsd has been started
schedule at pid 21444
ratesmsd at pid 21447
dlrssmsd at pid 21450
recvsmsd at pid 21453
sendsmsd at pid 21455

playsmsd is running
schedule at pid 21444
ratesmsd at pid 21447
dlrssmsd at pid 21450
recvsmsd at pid 21453
sendsmsd at pid 21455


playSMS has been installed on your system

Your playSMS daemon script operational guide:

- To start it : playsmsd /usr/local/playsms/etc/playsmsd.conf start
- To stop it  : playsmsd /usr/local/playsms/etc/playsmsd.conf stop
- To check it : playsmsd /usr/local/playsms/etc/playsmsd.conf check

ATTENTION

=========

When message "unable to start playsmsd" occurred above, please check:
1. Possibly theres an issue with composer updates, try to run: "./composer update"
2. Manually run playsmsd, "playsmsd /usr/local/playsms/etc/playsmsd.conf start", and then "playsmsd /usr/local/playsms/etc/playsmsd.conf status"

playsmsを終了します ユーザーシェル

適切なbinを設定します およびconf /usr/local/playsms/html/plugin/feature/playsmslog/config.php内のファイルの場所

$plugin_config['playsmslog']['playsmsd']['bin'] = '/usr/local/playsms/bin/playsmsd';
$plugin_config['playsmslog']['playsmsd']['conf'] = 'https://1118798822.rsc.cdn77.org/usr/local/playsms/etc/playsmsd.conf';

また、適切な confを設定する必要があります / usr / local / playingsms / bin / playingsmsd内のファイルの場所

[ line#222の近く ]

$ PLAYSMSD_CONF =”;

$ PLAYSMSD_CONF =‘/usr/local/playsms/etc/playsmsd.conf’;

私たちのウェブサーバーのユーザー/グループはnginx 、権限の問題を回避するために、PlaySMSWebルートディレクトリのすべてのコンテンツの所有権をnginx:nginxに変更します

root@sms-gw:~# cd /usr/local/playsms/html/
root@sms-gw:/usr/local/playsms/html# chown nginx:nginx -R ./*

/etc/nginx/conf.d/default.confに新しいWebルートディレクトリを設定します PlaySMSの場合

NGINXサービスを再起動します

root@sms-gw:~# systemctl restart nginx.service

http://192.168.10.38/を閲覧する クライアントワークステーションから、デフォルトのユーザー名:admin、パスワード:admin

でログインします。

マイアカウントの下>設定 メニューデフォルトのパスワードとその他の情報を変更する

PlaySMSとKannelSMSGatwayの統合:

設定に移動します>ゲートウェイとSMSCの管理 PlaySMS管理Webポータルで、[カネルゲートウェイ]オプションの横にあるプラス(+)記号をクリックします

sendsms-userで構成したとおりにKannelGateway情報を入力します kannel.confのグループ。 参照:Kannelのインストール

注: これらの情報は、KannelとPlaySMS間の双方向HTTPAPIアクセスに関するものです。同じサーバーに両方のサービスをインストールしているため、 localhostを使用しました Bearerboxの場合、SMSとPlaySMSのURLを送信します。 KannelとPlaySMSを異なるサーバーにインストールする場合は、ホストのIPアドレス/FQDNを使用してください。

Kannel SMSCは、設定の[SMSC]タブに追加されます。>ゲートウェイとSMSCの管理

設定に移動します>主な構成カネルを設定する デフォルトのSMSC 構成を保存します。

PlaySMSからSMSを送信する:

マイアカウントに移動します>メッセージの作成 SMSを書いて送信する

カネルアクセスログ:

受信者の電話番号:

KannelからPlaySMSでSMSを受信する:

受信SMSを取得するには、PlaySMSコールバックURL get-urlを追加する必要があります sms-serviceの下 kannel.confのグループ ファイル

group = sms-service
get-url = "http://localhost/index.php?app=call&cat=gateway&plugin=kannel&access=geturl&t=%t&q=%q&a=%a&Q=%Q&smsc=kannel"

受信SMSはレポート>サンドボックスにあります PlaySMSポータルで。

設定>着信SMSのルーティングから 受信SMSの宛先/アクションを設定できます。

playsmsdを追加 systemdを使用して起動する :

systemdユニットを作成します/etc/systemd/system/playsms.service 以下の内容で

[Unit]
Description=PlaySMS
Documentation=https://playsms.org/documentation/
After=network-online.target
Wants=network-online.target

[Service]
User=playsms
Type=forking
ExecStart=/usr/local/playsms/bin/playsmsd start
ExecReload=/usr/local/playsms/bin/playsmsd restart
ExecStop=/usr/local/playsms/bin/playsmsd stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

systemdをリロードします playingsms.serviceを有効/開始します

root@sms-gw:~# systemctl daemon-reload
root@sms-gw:~# systemctl enable playsms.service
root@sms-gw:~# systemctl start playsms.service
root@sms-gw:~# systemctl status playsms.service
参照:

https://playsms.org/documentation/
https://mariadb.org/download/?t=repo-config
https://docs.nginx.com/nginx/admin-guide/installing-nginx/


Debian
  1. DebianLinuxでnginxウェブサーバーを再コンパイルする方法

  2. Nginxサーバーで504ゲートウェイのタイムアウトを修正する方法

  3. /etc/nginx/nginx.conf で getpwnam(www) が失敗しました

  1. 502 Bad Gateway ErrorNGINX[解決策]

  2. AwkパターンがNginx-vのConfigure引数と一致しないのはなぜですか?

  3. Debian 6(スクイーズ)VPSにLEMP(Nginx、MySQL、PHP)サーバーをインストールして設定する方法

  1. Debian9にMicroweberをインストールする方法

  2. nginx 504 ゲートウェイのタイムアウト

  3. nginx:[emerg] /etc/nginx/sites-enabled/example.com:3 の不明なディレクティブ