Moodle 3.3.1 Fedora Nginx SELinux MariaDB

Moodle 3.3.1 Fedora Nginx SELinux MariaDB

- T N の投稿
返信数: 11

Fedora Workstation 26 をインストールする機会があったので、Nginx + SELinux + MariaDB 下で Moodle 3.3.1 をセットアップするまでの一連の流れを記録してみました。

  1. Fedora Workstation 26 のインストール
  2. Fedora Workstation 26 の初期設定
  3. 関連ソフトウェアのインストールと設定
    1. アンチウィルスソフト
    2. PHP 一式
    3. MariaDB
    4. nginx 関連ソフト
    5. TeX 関連ソフト
  4. Moodle のインストール
  5. Moodle の調整
  6. Let's Encrypt 無料サーバー証明書

評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

1. Fedora Workstation 26 のインストール

- T N の投稿
インストールディスクの作成

1. fedora で検索する。
2. Fedora Project を選ぶ。
3. WORKSTATION を「いますぐダウンロード」する。
4. インストーラーも入っているので、「64-bit 1.5 GB の Live イメージ」をクリック。
5. 「ファイルを保存する」。
6. デスクトップ(任意)を保存先にする。
7. ディスクイメージを右クリックして、「ディスクに書き込む」。

8. 空のディスクをセットしてから、「ディスクを作成」をクリックして、後は指示通り。

9. インストール先のマシンを電源を入れて素早くディスクを差し込む。

10. これ以降は、以下参照。

https://www.hiroom2.com/2017/07/12/fedora-26-ja/


評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

2. Fedora Workstation 26 の初期設定

- T N の投稿

最初はローカル端末で、

1. ssh が開いていることの確認
# firewall-cmd --list-services --zone=public
ssh mdns dhcpv6-client

2. sshd の常駐化

# systemctl enable sshd
# systemctl start sshd

以降はリモート端末で(お好みでどこらかでも)、

3. 接続許可の設定(任意)

# cd /etc
# vi hosts.deny
sshd: all
mysqld: all
# vi hosts.allow
sshd: 192.168.3.9 192.168.3.10
mysqld: 192.168.3.11
# systemctl restart sshd

4. デフォルトゾーンの確認(任意)

# firewall-cmd --get-default-zone
FedoraWorkstation

5. デフォルトゾーンを public に変更

# firewall-cmd --set-default-zone=public

6. 忘れないうちにポートを開放しておく

# firewall-cmd --permanent --add-service=http --zone=public
# firewall-cmd --permanent --add-service=https --zone=public
# firewall-cmd --reload
# firewall-cmd --list-services --zone=public

7. SELinux の状態確認

# getenforce
Enforcing

8. Apache が動いていないことの確認

# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)

9. 検索エンジンロボットの巡回を拒否する(任意)

# vi /var/www/html/robots.txt
User-Agent: *
Disallow: /

評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

3.1 アンチウィルスソフトのインストール

- T N の投稿

Moodle ではアンチウィルスプラグインとして ClamAV が第一選択となっている。

# dnf install clamav clamav-update

ウイルス定義ファイルの更新

# freshclam

3時間おきに定義ファイルの更新が行われるよう /etc/cron.d/clamav-update で設定してある。

試しにスキャンしてみる
# clamscan --infected --remove --recursive /home


お試し無害ウィルスをダウンロードして試す
# cd /tmp
# wget http://www.eicar.org/download/eicar.com
# clamscan --infected --remove --recursive ./

評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

3.3 MariaDB のインストール

- T N の投稿

# dnf install mariadb-server

# cd /etc
# cp my.cnf my.cnf.org
# vi my.cnf
[mysqld] の下に
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G
innodb_large_prefix = ON
character-set-server = utf8mb4
最下行に、
[client]
default-character-set = utf8mb4

# systemctl start mariadb
# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): リターン
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] n(そもそも /etc/hosts.* で特定の IP からしかアクセスできないようにしてある)
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

# systemctl restart mariadb
# mysql -u root -p
MariaDB [(none)]> select user,host,password from mysql.user;
MariaDB [(none)]> show databases;
MariaDB [(none)]> create database moodle default character set utf8mb4 collate utf8mb4_unicode_ci;
MariaDB [(none)]> grant all privileges on moodle.* to "moodle"@"localhost" identified by "数十桁の長いパスワード";
MariaDB [(none)]> select user,host,password from mysql.user;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show variables like 'character_set%';
+--------------------------+------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
MariaDB [(none)]> exit
評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

3.4 nginx 関連ソフトのインストール

- T N の投稿

# dnf install nginx php-fpm mod_xsendfile

# cd /etc/php-fpm.d
# cp -a www.conf www.conf.org
# vi www.conf
user = nginx
group = nginx
# cd /var/www/html
# ln -s /usr/share/nginx/html/* .
# cd /usr/share/nginx/html
# vi phpinfo.php
<?php
phpinfo();
?>

# systemctl start php-fpm
# systemctl enable php-fpm
# systemctl start nginx

ここでブラウザでアクセスして動作確認を行う。

1. http://192.168.3.7/ で「Welcome to nginx on Fedora!」が現れるか。

2. http://192.168.3.7/phpinfo.php が正しく表示されるか。

ここから moodle 用の設定
# cd /etc
# cp -a php.ini php.ini.org
# vi php.ini
max_execution_time = 90(任意)
memory_limit = -1(無制限)
post_max_size = 0(無制限)
cgi.fix_pathinfo=1
upload_max_filesize = 1024M(任意)
date.timezone = Asia/Tokyo
mbstring.language = Japanese

とりあえず、自己サーバー証明書作成

# cd /etc/nginx

# openssl genrsa 2048 > server.key

# openssl req -new -key server.key > server.csr

# openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt

# cp -a nginx.conf nginx.conf.org

# vi nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    index index.php index.html index.htm;
    root /var/www/html;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;


        location / {
        }

        location ~ [^/]\.php(/|$) {
           fastcgi_split_path_info  ^(.+\.php)(/.+)$;
           fastcgi_index            index.php;
           fastcgi_pass             unix:/run/php-fpm/www.sock;
           include                  fastcgi_params;
           fastcgi_param   PATH_INFO       $fastcgi_path_info;
           fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_read_timeout 60m;
        }

        location /dataroot/ {
            internal;
            alias /var/www/moodledata/; # ensure the path ends with /
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

    }

# Settings for a TLS enabled server.
#
     server {
         listen       443 ssl http2 default_server;
         listen       [::]:443 ssl http2 default_server;
         server_name  _;
 
         ssl_certificate "serverr.crt";
         ssl_certificate_key "server.key";
         ssl_session_cache shared:SSL:1m;
         ssl_session_timeout  10m;
         ssl_ciphers HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers on;
 
 
         location / {
         }

         location ~ [^/]\.php(/|$) {
             fastcgi_split_path_info  ^(.+\.php)(/.+)$;
             fastcgi_index            index.php;
             fastcgi_pass             unix:/run/php-fpm/www.sock;
             include                  fastcgi_params;
             fastcgi_param   PATH_INFO       $fastcgi_path_info;
             fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
             fastcgi_read_timeout 60m;
         }

         location /dataroot/ {
            internal;
            alias /var/www/moodledata/; # ensure the path ends with /
         }

 
         error_page 404 /404.html;
             location = /40x.html {
         }
 
         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
     }

}




# nginx -t

ブラウザでの確認

http://192.168.3.7/

https://192.168.3.7/

評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

3.5 TeX 関連ソフトのインストール

- T N の投稿

XyMTeX を使わないのなら、TeX のインストールは不要かも。

# dnf install texlive-scheme-full -y & 1.3 GB もあるので、バックグラウンドで流す。

# dnf install texlive-latex-bin-bin texlive-cm texlive-bxcjkjatype texlive-ipaex-type1 texlive-xymtex ImageMagick

# mktexlsr

# cd /var/www/html
# mkdir test
# cd test
# vi test.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage[whole]{bxcjkjatype}
\usepackage{xymtexpdf}
\usepackage{chemist}
\begin{document}
$\dfrac{2}{\ 3\ }$
$\text{分数}$
\\
$\sixheterov[ace]{}{}[]$
$\text{benzene ring}$
\end{document}
# latex test
# dvisvgm test
http://192.168.3.7/test/test.svg 開いて、表示を確認する。
これで OK。
# cd ..
# rm -rf test
評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

Re: 3.5 TeX 関連ソフトのインストール

- T N の投稿

訂正です。

# dnf install texlive-latex-bin-bin texlive-cm texlive-bxcjkjatype texlive-ipaex-type1 texlive-xymtex ImageMagick
  texlive-scheme-full に含まれているので。


# vi test.tex (chemfig の追加)

\documentclass{article}
\usepackage{amsmath}
\usepackage[whole]{bxcjkjatype}
\usepackage{xymtexpdf}
\usepackage{chemfig}
\RequirePackage{amsmath,amssymb,latexsym}
\begin{document}
$\text{\XyMTeX}\\$
$\sixheterov[bdf]{3s==\tetramethylenei{2==O;4==CH$_3$}{1==(yl);3D==O}}{2==CO$_2$}[]\\\\$
$\text{ChemFig}\\$
$\chemfig{[:0]*6(=-(-O([:30]-([2]=O)([:-30]-CH_3)))=(-CO_2)-=-)}\\\\\\$
$\text{\bf数式}\\$
$\displaystyle\int_0^{10}\left(\dfrac{9}{\ 17\ }x+13\right){\rm d}x$
\end{document}


/filter/tex/latex.php に倣い、

# latex --interaction=nonstopmode --halt-on-error test.tex
# dvips -q -E test.dvi -o test.ps
# dvisvgm -E test.ps -o test.svg



評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

4. Moodle 3.3.1 のインストール

- T N の投稿
# cd /tmp
# wget http://download.moodle.org/download.php/direct/stable33/moodle-latest-33.tgz
# tar xfvz moodle-latest-33.tgz

# cd /var/www/html
# cp -a /tmp/moodle .
# cd moodle
# tail version.php バージョンの確認
# cp -a config-dist.php config.php
# vi config.php
$CFG->dbtype = 'mariadb'
$CFG->dbname = 'moodle'
$CFG->dbuser = 'moodle'
$CFG->dbpass = '数十桁の長いパスワード'
$CFG->wwwroot = 'http://192.168.3.7/moodle';
$CFG->dataroot = '/var/www/moodledata'
$CFG->passwordsaltmain = '長〜〜〜い文字列'

$CFG->xsendfile = 'X-Accel-Redirect';
$CFG->xsendfilealiases = array(
'/dataroot/' => $CFG->dataroot
);

# cd /var/www
# mkdir moodledata
# chown nginx.nginx moodledata
# chcon system_u:object_r:httpd_sys_rw_content_t:s0 moodledata


# cd /var/www/html
# ls -ltrZ
# chown -R nginx:nginx moodle
# chcon -R system_u:object_r:httpd_sys_content_t:s0 moodle
# chmod go+w moodle/config.php
# chcon system_u:object_r:httpd_sys_rw_content_t:s0 moodle

http://192.168.3.7/moodle/admin にアクセス。

「Continue」をクリック。

「Check」と表示された項目のインストールと設定

# dnf install php-pecl-zip php-xmlrpc php-intl php-opcache
# dnf needs-restarting
# vi /etc/php.ini 最下行に、
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60

; Required for Moodle
opcache.use_cwd = 1
opcache.validate_timestamps = 1
opcache.save_comments = 1
opcache.enable_file_override = 0


# journalctl -f SELinux のエラーのモニタリング
別シェルを開いて、
# systemctl restart php-fpm

# setsebool -P httpd_execmem 1
# ausearch -c 'php-fpm' --raw | audit2allow -M my-phpfpm
# semodule -i my-phpfpm.pp

# systemctl restart php-fpm

"Reload" して、"Continue"

http://192.168.3.7/moodle/ にアクセスして、
Site administration▶Language packs
日本語(ja)
Install selected languager pack(s)
左上のメニューから日本語を選ぶ▶サイトホームへ行ってみる
ダッシュボード▶サイト管理▶言語管理▶言語設定
 デフォルト言語を日本語(ja)にして“変更を保存”する。

# cd /var/www/html
# chmod go-rw /var/www/html/moodle/config.php
# chmod u-w /var/www/html/moodle/config.php
# chcon system_u:object_r:httpd_sys_content_t:s0 moodle
# chcon system_u:object_r:httpd_sys_content_t:s0 /var/www/moodledata
評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

5. Moodle の調整

- T N の投稿

1. 教師にもメアドを見せないようにする。(任意)

ダッシュボード▶サイト管理▶ユーザ▶パーミッション▶ユーザポリシー
表示するユーザ固有情報 を IDナンバーに替えて、「変更を保存する」。
2. 評定のエクスポートにメアドを出さないようにする。(任意)

ダッシュボード▶サイト管理▶評定▶一般設定▼評定エクスポート–ユーザープロファイルフィールド
に替える。
その下の、カスタムプロファイルフィールドも替えて、「変更を保存する」。

3. 受験結果の解答のダウンロードでメアドがダウンロードされないようにする。(任意)
# cd /var/www/html/moodle/mod/quiz/report
# cp attemptsreport.php attemptsreport.php.org
# vi attemptsreport.php の179, 180 行目をコメントアウトする。
179: // $columns[] = 'email';
180: // $headers[] = get_string('email');

4. オンラインユーザリストでは、学生に対しては人数のみの表示とする。(任意)
ダッシュボード▶サイト管理▶ユーザ▶パーミッション▶ロールを定義する▶学生▶編集▶オンラインユーザリストを表示する
許可→禁止
「変更を保存する」

5. 複数受験の際のペナルティの一覧への追加(任意)
# cd /var/www/html/
# cp edit_question_form.php edit_question_form.php.org
# vi edit_question_form.php の412行目に 0.4000000, を挿入。
416行目に 0.2222222, を挿入
417行目に 0.1250000, を挿入。

6. 多肢選択式問題のインポート時のデフォルトを abc から 123 に変更。(任意)
# cd /var/www/html/moodle/question
# cp format.php format.php.org
# sed 's/abc/123/' format.php.org >format.php

7. 多肢選択式問題の作問時のデフォルトを abc から 123 に変更。(任意)
# cd /var/www/html/moodle/question/type/multichoice
# cp edit_multichoice_form.php edit_multichoice_form.php.org
# sed 's/abc/123/' edit_multichoice_form.php.org >edit_multichoice_form.php

8. メッセージの検索で自分自身をヒットさせる。(任意)
# cd /var/www/html/moodle/message
# cp lib.php lib.php.org
# vi lib.php
561 行目の $exceptions[] = $USER->id; をコメントアウトする。

9. メールの設定
ダッシュボード▶サイト管理▶サーバ▶メール▶送信メール設定
SMTPホスト  localhost;xxxx.yyy.zz.jp
SMTPセッション制限 3
「変更を保存する」
ダッシュボード▶サイト管理▶セキュリティ▶サイトポリシー
メール変更確認 No

10. 自動パックアップの設定(任意)
ダッシュボード▶サイト管理▶コース▶バックアップ▶自動バックアップ設定
アクティブ 有効
スケジュール 日曜日
バックアップ処理開始時刻 4:00
次より古いバックアップを削除する 120 日
バックアップ保持最小数 1
非表示コースをスキップする Yes
ユーザを含む No
ログを含む Yes
履歴を含む Yes
「変更を保存する」

11. cron の実行スケジュールの設定
# crontab -e
*/30 * * * * wget -q -O /dev/null http://192.168.3.7/moodle/admin/cron.php

12. TeX 表記法の設定(任意)
ダッシュボード▶サイト管理▶プラグイン▶フィルタ設定
MathJax → Off、しかし利用可
TeX表記法
 有効? → On
 適用先 → コンテンツおよびヘッディング
 設定
   LaTeXプリアンブル
    \usepackage{amsmath}
    \usepackage[whole]{bxcjkjatype}
    \usepackage{xymtexpdf}
    %\usepackage{mmr}
    \usepackage{chemist}
    \RequirePackage{amsmath,amssymb,latexsym}
    \def\substfont{\sffamily\bfseries}\def\thinLineWidth{0.8pt}
   latexバイナリのパス
    /usr/bin/pdftex
   出力イメージフォーマット
    SVG
  「変更を保存する」

13. ClamAV の設定
ダッシュボード▶サイト管理▶プラグイン▶アンチウイルスプラグイン▶ClamAVアンチウイルス
コマンドライン:/usr/bin/clamscan
「変更を保存する」
評点平均: お役立ち度: ★★★★★★★ (1)
T N への返信

6. Let's Encrypt 無料サーバー証明書

- T N の投稿

無料なので、Let's Encrypt サーバー証明書を利用してみる。

# dnf install certbot
# certbot

Certbot doesn’t know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run “certbot certonly” to do so. You’ll need to manually configure your web server to use the resulting certificate.



# certbot certonly
How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):<自分のメールアドレス>
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: <任意>


Select the webroot for 192.168.3.7: ------------------------------------------------------------------------------- 1: Enter a new webroot ------------------------------------------------------------------------------- Press 1 [enter] to confirm the selection (press 'c' to cancel): 1


次に webroot の入力を求められるので、/var/www/html と入力すると、

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/192.168.3.7/fullchain.pem. Your cert will expire on 2017-11-10. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
自己サーバー証明書に関する記述と置き換える。
# vi /etc/nginx/nginx.conf
ssl_certificate "/etc/letsencrypt/192.168.3.7/cert.pem";
ssl_certificate_key "/etc/letsencrypt/live/192.168.3.7/privkey.pem";

# nginx -t
# nginx -s reload

# crontab -e
0 3 * * * /usr/bin/certbot renew
評点平均: お役立ち度: ★★★★★★★ (1)