13:WEBサーバーをapacheにする

現時点ではdevelopment modeだが、production mode ではapacheを使うつもりだ。ただ作っているアプリのカラムが30以上もあり、WEBの表示を画面全体で見たいので、先にapacheで見れるようにするために gemのpassengerを入れて、apacheで表示出きるようにする。(注:railsアプリの公開は社内だけにし、テレワークの社員はVPNで社内ネットワークに入り、ローカルIPアドレス:3000でアクセス出来るようにするので、暗号化はしていない)まずはGemfile にpassengerを入れる
[fuji@rails8 TourData]$ gedit Gemfile
前略
# gem “image_processing”, “~> 1.2”
gem “spring-commands-rspec”
gem “passenger”     ← これを追記

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem “debug”, platforms: %i[ mri windows ], require: “debug/prelude”
後略
で、お決まりの
[fuji@rails8 TourData]$ bundle
apacheにpassengerをインストールするがその前にhomeデレクトリーを第三者が実行出来るようにしておく。
[fuji@rails8 TourData]$ chmod o+x/home/fuji
[fuji@rails8 TourData]$ passenger-install-apache2-modules


This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort. Enterをオス
Which languages are you interested in?

Use <space> to select.
If the menu doesn't display correctly, press '!'

 ‣ ⬢  Ruby     Rubyに三角が付いているのを確認後 Enter
   ⬡  Python
   ⬢  Node.js

色々足りないものが表示されたが記録が無くなっているので、何が不足していたかは思い出せないが、ともかくyum install …….などと言ってくれるのでその通りにインストールし、再度
[fuji@rails8 TourData]$ passenger-install-apache2-modules
で、最後の方で
Almost there!
Please edit your Apache configuration file, and add these lines:

LoadModule passenger_module /home/fuji/.rbenv/versions/3.2.9/lib/ruby/gems/3.2.0/gems/passenger-6.0.27/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
 PassengerRoot /home/fuji/.rbenv/versions/3.2.9/lib/ruby/gems/3.2.0/gems/passenger-6.0.27
 PassengerDefaultRuby /home/fuji/.rbenv/versions/3.2.9/bin/ruby
</IfModule>

After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

Press ENTER when you are done editing.

——————————————–
Validating installation…
* Checking whether this Passenger install is in PATH… ✓
* Checking whether there are no other Passenger installations… ✓
* Checking whether Apache is installed… ✓
* Checking whether the Passenger module is correctly configured in Apache… (!)

You did not specify ‘LoadModule passenger_module’ in any of your Apache
configuration files. Please paste the configuration snippet that this
installer printed earlier, into one of your Apache configuration files, such
as /etc/httpd/conf/httpd.conf.

Detected 0 error(s), 1 warning(s).
Press ENTER to continue.

——————————————–
Deploying a web application

To learn how to deploy a web app on Passenger, please follow the deployment
guide:

https://www.phusionpassenger.com/library/deploy/apache/deploy/

Enjoy Phusion Passenger, a product of Phusion® (www.phusion.nl) 🙂
https://www.phusionpassenger.com

Passenger® is a registered trademark of Asynchronous B.V.

Checking whether the Passenger module is correctly configured in Apache… (!) だけがエラーになっている。当たり前だ、インストールしただけなので設定は終わっていない。
まずはpassenger module をロードするがこれは
[root@rails8 ~]# gedit /etc/httpd/conf.modules.d/00-rails.conf
LoadModule passenger_module /home/fuji/.rbenv/versions/3.2.9/lib/ruby/gems/3.2.0/gems/passenger-6.0.27/buildout/apache2/mod_passenger.so
PassengerEnabled on
<IfModule mod_passenger.c>
 PassengerRoot /home/fuji/.rbenv/versions/3.2.9/lib/ruby/gems/3.2.0/gems/passenger-6.0.27
 PassengerDefaultRuby /home/fuji/.rbenv/versions/3.2.9/bin/ruby
</IfModule>
と設定を新規に作った。次はdocument rootなどの設定だが、これは新規に
[root@rails8 ~]# gedit /etc/httpd/conf.d/rails.conf
DocumentRoot “/Rails/TourData/public”

<Directory “/Rails/TourData/public”>
 AllowOverride None
 # Allow open access:
 Require all granted
</Directory>
そしてapacheを再起動
[root@rails8 ~]# systemctl restart httpd
[root@rails8 ~]# systemctl status httpd
で起動を確認
次にpassengerの起動
[fuji@rails8 TourData]$ passenger start –environment development
でpassengerはスタートしたが、その端末に
Started GET “/metrics” for 127.0.0.1 at 2025-08-30 16:49:25 +0900
ActionController::RoutingError (No route matches [GET] “/metrics”):
でもブラウザで http://IP アドレス:3000にアクセスするとapacheでアクセス出来る

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

12:ツアーデーターを作る

先走って、ログインから作ったが、本当はこっちを先に作るべきだった。
[fuji@rails8 TourData]$ rails g scaffold Tour ref_no:string conf_no:string agt_name:string look:string jtb_ac:string course_no:string flight:string arr:date dep:date hotel:string name:text no_pax:integer room_type:text meal:string night:integer remarks:text pax_type:string rooming:string unit_price:float usd_total:float tts_date:date tts:float jpy_ttl:integer net:float received:date book_date:date invoice_date:date s_no:integer inp_icg:string agt_code:string agt_icg:string htl_code:string
記入途中

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

CentOS 7 運用時の色んなメモ

apache 設定チェック : apachectl configtest
apache ロードされているmoduleを表示:httpd -M

postfix 設定チェック : postfix check
postfix 設定表示         : postconf   変更した部分のみの表示:postconf -n

dovecot設定表示        :doveconf -n
                                   問題無ければ、デフォルトと異なる設定だけが出力されます。
                                   設定項目名にミスがあれば、エラーが表示されます。
                                   但し、設定項目の内容のチェックまではされないようです。
                                  設定項目があっていれば、指定したファイルが存在しなくてもエラーにはなりません。
spamassasin 設定チェック : spamassassin –lint  (– は見にくいが: ハイフォンが二つ)

sambaマウント: mount.cifs -o username=moriyama,password=xxxxx (記号は\をつける) //192.168.xx.xx/it /IT

ddの進捗情報 :dd status=progress if=xxxx…… of=xxxx…..
ネットワーク越しのdd(ローカルからローカル):コピー先のホストで
nc -l 12345 | dd of=/dev/Kvm/web5
12345は両ホストで使用していないポートなら何でもいい。
コピー元のホストに移って
dd status=progress if=/dev/Kvm/web4 | nc 192.168.xx.xx 12345
IPはコピー先のIP、最後の数字はポートNoで

ネットワーク越しのdd(リモートからローカル):ssh -p xxx username@ip or domain sudo dd status=progress  if=/dev/xxx…. |dd of=/dev/xxx….
defaultのポートなら -p xxxはいらない。dd を sudo でパスワードなしでやるには visudo で設定が必用(参照:https://qiita.com/RyodoTanaka/items/e9b15d579d17651650b7

rsync       : rsync -av –exclude-from=/root/exclude1 –password-file=/etc/rsync.passwd rsync://root@192.168.xx.xx/webdata /webdata
      dry-runは -n
      外からは:rsync -av -e ‘ssh -p xxx -i .ssh/id_rsa’ –exclude-from=/root/exclude1 –password-file=/etc/rsync.passwd rsync://root@グローバルIP/webdata /webdata

letsencrypt で cert file を更新したらDRBDのSECONDARYにも設定が必要
初めて行う時は /etc/rsyncd.conf に追記が必要
[letsencrypt]
path = /etc/letsencrypt
authusers = root
secrets file = /etc/rsyncd.secrets
read only =no
追記したらrsyncdを再起動して設定を有効にする。
# systemctl restart rsyncd
そしてコピー
# rsync -av –exclude-from=/root/exclude1 –password-file=/etc/rsyncd.passwd rsync://root@192.168.0.55/letsencrypt /test3
で /test3に出来た必要なファイルを /etc/letsencrypt にコピー
letsebcrypt でcertificatesで有効期限を表示
# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Found the following certs:
Certificate Name: aarah.info-0001
Serial Number: 4dd777ec388a651d72423d6df2c9ae24460
Key Type: RSA
Domains: aarah.info inpac.jp inpactours.jp kinryo.net opengarden.info www.aarah.info www.inpac.jp www.inpactours.jp www.kinryo.net www.opengarden.info
Expiry Date: 2023-04-12 07:32:50+00:00 (VALID: 78 days)
Certificate Path: /etc/letsencrypt/live/aarah.info-0001/fullchain.pem
Private Key Path: /etc/letsencrypt/live/aarah.info-0001/privkey.pem
Certificate Name: kinryokai.net
Serial Number: 4040193692d1e64b9ec8639985a7943a43f
Key Type: RSA
Domains: kinryokai.net mail.kinryokai.net www.kinryokai.net
Expiry Date: 2023-04-12 07:33:20+00:00 (VALID: 78 days)
Certificate Path: /etc/letsencrypt/live/kinryokai.net/fullchain.pem
Private Key Path: /etc/letsencrypt/live/kinryokai.net/privkey.pem
Certificate Name: mail.kinryo.net
Serial Number: 32edf706664cd2ce65b156a10cbedd55168
Key Type: RSA
Domains: mail.kinryo.net
Expiry Date: 2023-03-21 08:17:31+00:00 (VALID: 56 days)
Certificate Path: /etc/letsencrypt/live/mail.kinryo.net/fullchain.pem
Private Key Path: /etc/letsencrypt/live/mail.kinryo.net/privkey.pem

vsftp 設定チェック :  vsftpd /etc/vsftpd/vsftpd.conf

ポート指定の疎通確認  :
LINUX:  nc -vz ドメイン(IP)ポート番号
Winows powershallから: test-netcpnnection IPアドレス -port ポート番号

ssh接続               :ssh -i 秘密鍵のパス リモートユーザー@リモートサーバーのホスト名

空ポートの確認 :ss -nat 又は-nau   # t=tcp, u=udp

virbr0の停止
    # virsh net-destroy default,   再起動後も止める:# virsh net-autostart default –disable
    Almalinux 8以上  # systemctl disable libvirtd 但し仮想化が動いていれば出来無いので上の行の様にして止める
 

mail.kinryokai.netだけのcertbot 更新  : certbot certonly –webroot -w /webdata/public/kinryokai -d  mail.kinryokai.net

bacula conf のチェック    https://www.kinryo.net/?p=2510

samba mount    mount.cifs //192.168.xx.xx/yyyy /zzz -o user=name

SSH経由でVNC(CentOS7)
  まずSSHで接続:# ssh -p ポート番号 ユーザ@IP かドメイン -L 12345(このポートは任意):IP かドメイン: サーバのVNCポート
  新しいターミナルを開け
  # vncviewer
  ウィンドウが開くので、localhost:12345

lvextend で領域を増やしたら(xfsの場合)
  sudo xfs_growfs マウントポイント(xfsはマウントしたまま出来る)で領域を増やす

ポートが空いているか調べる
  $ netstat -an |grep ポート番号
  このポートを閉じる時
  $ lsof -i:ポート番号     PIDの番号がいる
  $ kill PIDの番号

grep -A オプション
  直後の3行が表示され
  ABCD 検索した文字
  EFG
  HI
  JKL

php-fpm の再起動
       私はphp56とphp74をインストールしているので、
       # systemctl restart php56-php-fpm
       # systemctl restart php74-php-fpm

wordpressをブラウザからアップデート(FTP不使用)
  wp-config.php のdefine(‘WP_DEBUG’,false); の次に
  define(‘FS_METHOD’,’direct’); を追記

mariadb IDを10,000からスターとする
  ALTER TABEL テーブル名 AUTO_INREMENT=10000;

カテゴリー: Linux運用時のメモ | コメントする

mariadbでdateのカラムにnullを認める mariadb Ver 15.1 Distrib 10.5.27

まずは現在の状況をチェック
MariaDB [(none)]> SELECT @@SESSION.sql_mode;
前略
|STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
あれー、NO_ZERO_IN DATE もNO_ZERO_DATE も入っていない。
これがDATEカラムにnullが認められないが、入っていないのでSTRICT_TRANS_TABLESだけを削除する

MariaDB [(none)]> SET SESSION sql_mode = ‘ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;
うんで、再度チェック
MariaDB [(none)]>
SELECT @@SESSION.sql_mode;
| ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION |
STRICT_TRANS_TABLESを取ると、NO_ZERO_IN DATE や NO_ZERO_DATEが入っていても、ワーニングを出し、データーは保存されるようだ。

でも、実際にdateカラムが””(空白)になっているデーターをインポートするとエラーになってしまう。(原因は不明、sql_modeでは表示されないが、どうもNO_ZERO_IN DATE や NO_ZERO_DATEがデフォルトで有効になっているのかな?)
なので再度、NO_ENGINE_SUBSTITUTION だけを有効にして
MariaDB [(none)]> SET SESSION sql_mode = ‘NO_ENGINE_SUBSTITUTION’;
で、再度インポート
MariaDB [(none)]>
LOAD DATA INFILE ファイルのパス INTO テーブル名 FIELDS TERMINATED BY ‘\T’ IGNORE 1 ROWS
やっと、dateカラムが空白になっているファイルのインポートが出来た。

カテゴリー: Linux運用時のメモ | コメントする

11:ログイン機能をつける

基本方針:これから作るrailsアプリは社内の特定部署の社員しか使わないので、userのデーターベースは作りますが、大げさなgemやrails8から実装されたauthenticationなどは使わず、管理者が直接データーベースにアクセスし、ユーザー名とパスワードを作るようにし、アプリ側からはユーザーデーターの新規作成、編集、削除など一切作らないようにします。
まずはデーターベースの作成
[fuji@rails8 TourData]$ rails g model user name:string password_digest:string
invoke active_record
create db/migrate/20250820061510_create_users.rb
create app/models/user.rb
invoke test_unit
create test/models/user_test.rb
create test/fixtures/users.yml
[fuji@rails8 TourData]$ rails db:migrate
== 20250820061510 CreateUsers: migrating ======================================
— create_table(:users)
-> 0.0873s
== 20250820061510 CreateUsers: migrated (0.0875s) =
password_digestに注意してください。これは平文でパスワードを入れると、データーベースには暗号化した文字列が入るようになる。
そのためにGEMが必要になるので
[fuji@rails8 TourData]$ gedit Gemfile

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem “image_processing”, “~> 1.2”
gem “spring-commands-rspec” → これは前に入れた
gem “bcrypt”           → これを追記
group :development, :test do0
でお約束の
[fuji@rails8 TourData]$ bundle

で最初にtestユーザーでも作っておく、railsコンソールで作るがその前にusers.rbを設定しておく
[fuji@rails8 TourData]$ gedit app/models/user.rb
class User < ApplicationRecord
   has_secure_password              → これを追記
   validates :name, prsence: true, uniqueness: true → これを追記
end

railsのコンソールから直接ユーザーを作る
[fuji@rails8 TourData]$ rails c
tour-data(dev)> User.new( name: ‘ユーザー名’, password: ‘パスワード’, password_confirmation: ‘パスワード’).save
TRANSACTION (0.2ms) BEGIN /*application=’TouData’*/
User Create (1.0ms) INSERT INTO `users` (`name`, `password_digest`, `created_at`, `updated_at`) VALUES
後略
そしてデーターベースにログインし、ユーザーが出来ているか確認した。

ログイン画面を作るが、rails ではセッションを使うので
[fuji@rails8 TourData]$ rails g controller Sessions new
create app/controllers/sessions_controller.rb
  route get “sessions/new”
  invoke erb
  create app/views/sessions
後略
routeの変更するがログイン画面を/loginにしたいので
[fuji@rails8 TourData]$ gedit config/routes.rb
Rails.application.routes.draw do
 #get “sessions/new”       コメントアウトし
 get “/login”, to: “sessions/new”    ここから
post “/login”, to: “sessions#create”    ↓
    delete ‘/logout’, to: ‘sessions#destroy’ ここまで追記
後略
テンプレートを作る
[fuji@rails8 TourData]$ gedit /app/views/sessions.new.html.erb
<h1>* LOG IN *</h1>
<%= form_for(:session, url: login_path) do |f| %>
<%= f.label :name %>
<%= f.email_field :name %><br><br>
<%= f.label :password %>
<%= f.password_field :password %><br><br>
<%= f.submit “Log in” %>
<% end %>

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

10:下準備

springを入れます(これはプリローダーでアプリをバックグランドで走らせてままに出来、rails generate やrake コマンドの起動が早くなるとの事)Gemfileに追記する
[fuji@rails8 TourData]$ gedit Gemfile
前略
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem “image_processing”, “~> 1.2”
gem ‘spring-commands-rspec’ → これを追記
group :development, :test do

[fuji@rails8 TourData]$ bundle
[fuji@rails8 TourData]$ spring binstub rspec
スプリングが走っているかチェック
[fuji@rails8 TourData]$ spring status
Spring is not running.
なので
[fuji@rails8 TourData]$ spring start
[fuji@rails8 TourData]$ spring status
Spring is running:
140726 spring server | TourData | started 9 secs ago

JavaScriptを圧縮するためにnode.jsを入れますがどのバージョンがあるか調べます。
[fuji@rails8 TourData]$ sudo dnf module list nodejs
前略
nodejs 18 common [d], development, minimal, s2i Javascript runtime
nodejs 20 common [d], development, minimal, s2i Javascript runtime
nodejs 22 common [d], development, minimal, s2i Javascript runtime
後略
なので、22を入れます
[fuji@rails8 TourData]$ sudo dnf module -y install nodejs:22/common

 

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

9:データーベースの設定

Databaseをmariadb(3:10.5.27-1)に変更したので、設定が必要になる。databaseなどを作っていく
[fuji@rails8 TourData]$  sudo mysql
前略
MariaDB [(none)]> grant all privileges on tour_data_development.* to yyyyyyy@localhost identified by “xxxxxxxx”;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all privileges on tour_data_test.* to yyyyyyy@localhost identified by “xxxxxxxxx”;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> create database tour_data_development;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create database tour_data_test;
Query OK, 1 row affected (0.000 sec)

ここで、これから作るrailsアプリを作る,データーベースはmysqlにするが、アプリを置く領域を作ってあるのでそこに移動(30Gibある)
[fuji@rails8 ~]$ cd /rails
[fuji@rails8 Rails]$ rails new TourData -d mysql
     create
     create README.md
     create Rakefile
     create .ruby-version
     create config.ru
     create .gitignore
     create .gitattributes
後略
[fuji@rails8 ~]$ cd TourData
次に設定ファイルの変更
[fuji@rails8 TourData]$  gedit config/database.yml

default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch(“RAILS_MAX_THREADS”) { 5 } %>
username: yyyyyyy  ← ここを設定したユーザーに
password: xxxxxxx   ここを設定したパスワードに
socket: /var/lib/mysql/mysql.sock

development:
<<: *default
database: tour_data_development

Gemファイル記載されたパッケージ群の相互依存関係を調べるため
[fuji@rails8 TourData]$ bundle
Bundle complete! 21 Gemfile dependencies, 119 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
1 installed gem you directly depend on is looking for funding.
Run `bundle fund` for details

で新規に端末を開いてWEBサーバーを立ち上げるが、この端末はずーっと、サーバーが使用するので、今後のために別の端末を立ち上げそこでサ行をする
[fuji@rails8 TourData]$   rails s

ブラウザでlocalhost:3000にアクセスして、上に画面が出れば正常です。

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

8:railsのデーターベースをmariadbにする

rubyとrailsの設定は終わっているとする(ここを参照
まずはmariadbのインストール
$ sudo dnf install mariadb-server mariadb-devel
注:以前にmysqlなどをインストールしていると/var/lib/mysqlにデーターが残っているのでスタートに失敗するので、/var/lib/mysqlを空にしておくこと。mariadb-develはrailsに必要になります
$ sudo systemctl enable – –now mariadb
ここで以前は mysql_secure_installation などをやっていたのですが、いつのバージョンからは分かりませんが、現在は”unix_socket 認証プラグインを使用するように構成されています。”との事なので、
$ sudo mysql
とやるとログインできます

MariaDB [(none)]> show databases;
+—————————–+
| Database                      |
+—————————–+
| information_schema |
| mysql |
| performance_schema |
+——————————+
3 rows in set (0.001 sec)

MariaDB [(none)]> select user,host,password from mysql.user;
+—————–+————–+————–+
| User               | Host          | Password |
+—————–+————–+————–+
| mariadb.sys | localhost |                    |
| root                 | localhost | invalid     |
| mysql             | localhost | invalid     |
+——————+————-+————–+
3 rows in set (0.003 sec)
と言う分けで,rootのPWは無効化されています。
ちなみにインストールされている物は(mariadbはログアウトしてね)
$ sudo dnf list installed |grep mariadb
mariadb.x86_64                                       3:10.5.27-1.el9_5     @appstream
mariadb-backup.x86_64                       3:10.5.27-1.el9_5      @appstream
mariadb-common.x86_64                    3:10.5.27-1.el9_5      @appstream
mariadb-connector-c.x86_64              3.2.6-1.el9_0              @appstream
mariadb-connector-c-config.noarch 3.2.6-1.el9_0              @appstream
mariadb-connector-c-devel.x86_64   3.2.6-1.el9_0              @appstream
mariadb-connector-c-doc.noarch      3.2.6-1.el9_0              @crb
mariadb-devel.x86_64                           3:10.5.27-1.el9_5       @crb
mariadb-errmsg.x86_64                        3:10.5.27-1.el9_5      @appstream
mariadb-gssapi-server.x86_64             3:10.5.27-1.el9_5      @appstream
mariadb-server.x86_64                          3:10.5.27-1.el9_5      @appstream
mariadb-server-utils.x86_64                3:10.5.27-1.el9_5      @appstream
ここで、databaseのデーターディレクトリーをRailsのデーターディレクトリ(/Rails)と同じ領域に移します。まず、ディレクトリー作成
$ sudo mkdir /Rails/mysql
$ sudo chown mysql. /Rails/mysql
でサーバーの設定ファイル変更
$ sudo gedit /etc/my.cnf.d/mariadb-server.cnf
前略
[mysqld]
datadir=/Rails/mysql      ← ここを変更
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid
mariadbのデーターの保存場所を変更したので、再起動しておく
$ sudo systemctl restart mariadb

いよいよrailsのプログラムを作成
$ cd /Rails
$ rails new TourData -d mysql
ずらずらとかなりのファイルが作成されるが出来た様だ,なのでディレクトリーを変更
$ cd TourData

9:データーベースの設定 に続く

カテゴリー: Ruby on railsに挑戦(almalinux9) | コメントする

lsyncd をインストールして見た

ファイルサーバーが動いている本番環境では問題があるので、3番目のホストに同期するようにしてテストする。すべて同じネットワークにある。

  1. ホスト名: smb7 ファイルサーバーが動いているサーバー
  2. ホスト名: smb6A ファイルサーバーをコピーしたホスト、IPとホスト名だけを変更、     rsyncで30分毎に同期している。バックアップとしている
  3. ホスト名: smb3 ファイルサーバーをコピーしたホスト、IPとホスト名だけを変更、rsyncで30分毎に同期している。2番目のバックアップとしている

前提:smb3でrsyncの設定が済んでいる亊。私はファイルサーバのバックアップしているので設定は終わっているが、Cronで30分毎のバックアップは止める。
smb6Aでの設定。
先ずはlsyncdのインストール
# dnf install lsyncd
Verは2.2.3がインストールされた。でもってlsyncdの設定
# gedit /etc/lsyncd.conf

このファイルではーーがコメントの様だ。でlsyncdをスタート
# systemctl start lsyncd
# systemctl enable lsyncd
テストをする。smb6Aに何か保存、smb3に反映してるか、保存したファイルを消去、smb3から消えているか。(ただこれは30分毎に本チャンのファイルサーバーから同期が入るので、その影響の無い時間にテストする) 無事確認が済んだ。
少し様子を見てから、本番環境に設定する。

ちなみに、lsyncdはファイルの作製、変更、消去などをOSが通知するのを受けて動作するが、最大数があるので調べて見る
# sysctl -a | grep inotify
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 128
fs.inotify.max_user_watches = 262144
user.max_inotify_instances = 128
user.max_inotify_watches = 262144

fs.inotify.max_queued_eventsとは(googleより)
もし、ファイルシステムの変更が頻繁に発生し、イベントの取りこぼしが発生している可能性がある場合は、max_queued_eventsの値を大きくすることを検討すると良いでしょう。ただし、値を大きくしすぎると、カーネルのメモリ消費量が増加する可能性があるため、適切な値を設定する必要があります。

fs.inotify.max_user_instancesとは(googleより)
このパラメータは、各ユーザーが同時に使用できる inotify インスタンスの数を制限します。inotify インスタンスは、ファイルシステムの監視対象ごとに作成されます。例えば、多数のディレクトリやファイルを監視するアプリケーションでは、多くの inotify インスタンスが必要になります。

fs.inotify.max_user_watchesとは(googleより)
Linuxカーネルのinotifyサブシステムにおける、ユーザーが監視できるファイルの最大数を設定するパラメータです。inotifyは、ファイルシステムの変更を監視するためのカーネル機能で、例えばファイルが作成、削除、変更されたときにアプリケーションに通知を送るのに使われます。fs.inotify.max_user_watches は、inotifyインスタンスごとに監視できるファイルの最大数を制限し、システムリソースの過剰な消費を防ぎます。

 

カテゴリー: Linux運用時のメモ | コメントする

DRBDを止めた

DRBDを止めた理由

1:原因は未だに不明だが、再起動後 pacemaker が良く落ちてクラスターの変更が出来ない。PCSDを使用せず、drbd だけ走らせてもいい(DRBDはファイルサーバーに使っているので、おかしければすぐに社員から連絡が入り対処出きるので、どうしてもクラスターの変更を自動でしなくても良さげ)

2:DRBDは必ず2台以上の運用が前提でこれが極まれに問題になる。1台だけでもそれをPRIMARYにして運用は出来るがこれだとDRBDの意味がない。

3:これがかなり問題になるが問題が出たとき、DRBDのファイルシステムを通常のホストにマウント出来ない(kmod-drbd9xなどをインストールしDRBD対応のカーネルにしてもいいが、検査の為だけに変更するのもなー?)

4:ではどうするか
通常のファイルサーバーと物理的に別のホストでそれぞれファイルサーバーを起動し、メインでないホストはrsyncで30分おきにデータを同期する(lsyncはまだ勉強中)。またさらに、サブの方にファイルサーバーのバックアップ用のホストを作り、やはりrsyncで1時間おきに同期をする。また、ファイルサーバーのデーターをbaculaで1日おきにバックアップする。つまり待機側にはファイルサーバーを2台作っておく。又、デザスターリカバリーの為に物理的にかなり離れた場所に、rsyncでデーターを1時間おきに同期する。
これら4重のホストでデーターを同期している。ファイルサーバーはsambaで運用しているが、今までに瞬電以外で止まった事はない。マイグレーションの時人為ミスで、ファイルサーバーが落ちた事もあったが!

カテゴリー: Linux運用時のメモ | コメントする