5:最初のテスト

rails generate controllerを実効した時点でテストが出来ている
$ ls test/controllers/
static_pages_controller_test.rb
見てみよう
$ cat test/controllers/static_pages_controller_test.rb
require “test_helper”

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
 test “should get home” do
  get static_pages_home_url
  assert_response :success
 end

 test “should get help” do
  get static_pages_help_url
  assert_response :success
 end
end
$
rails test
Running 2 tests in a single process (parallelization threshold is 50)
Run options: –seed 6539
# Running:
..
Finished in 0.506600s, 3.9479 runs/s, 3.9479 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips

db/test.sqlite3が出来ているので、Gitリポジトリに登録されると邪魔なのですが、.gitignoreに既にイグノアーされる記述が入っている
.gitignoreファイルの抜粋
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*
テスト駆動開発のサイクルは「失敗するテストを最初に書く」「次にアプリケーションのコードを書いて成功させる(パスさせる)」「必要ならリファクタリングする」のように進みます。多くのテストツールでは、テストの失敗を red 、成功したときを green で表します。ここから、このサイクルを「 redgreen ・REFACTOR」と呼ぶこともあります。これに従って最初のサイクルを完了させましょう。まず失敗するテストを書いて red になるようにします。
$ gedit test/controllers/static_pages_controller_test.rb
require “test_helper”

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test “should get home” do
    get static_pages_home_url
    assert_response :success
end

  test “should get help” do
    get static_pages_help_url
    assert_response :success
  end

  test “should get about” do
    get static_pages_about_url
    assert_response :success
  end
end
$ rails test
前略
NameError: undefined local variable or method `static_pages_about_url’
中略
3 runs, 2 assertions, 0 failures, 1 errors, 0 skips
エラーを見るとstatic_pages_about_urlのURLが無いと言っているのでabout用のルーティングを追加する
$ gedit test/controllers/static_pages_controller_test.rb
Rails.application.routes.draw do
 get ‘static_pages/home’
 get ‘static_pages/help’
 get “static_pages/about”   ←これを追記
root “application#hello”
end
そしてテスト
$ rails test
前略
AbstractController::ActionNotFound: The action ‘about’ could not be found for StaticPagesController
中略
3 runs, 2 assertions, 0 failures, 1 errors, 0 skips
今度のエラーはaboutのコントローラーが無いと言っているので
$ gedit app/controllers/static_pages_controller.rb
class StaticPagesController < ApplicationController
  def home
  end

  def help
  end

  def about   ← aboutを追記
  end
end
そしてテスト
$ rails test
1) Error:
StaticPagesControllerTest#test_should_get_about:
ActionController::MissingExactTemplate: StaticPagesController#about is 3 runs, 2 assertions, 0 failures, 1 errors, 0 skips
今度はaboutのテンプレートが無いといっているので
$ gedit app/views/static_pages/about.html.erb
こんなファイルは無いので空白のページが表示されるので、作る
<h1>About<h1>
<p>
<a href=“https://railstutorial.jp/”>Ruby on Rails Tutorial</a>
 is a <a href=“https://railstutorial.jp/#ebook”>book</a> and

 <a href=“https://railstutorial.jp/screencast”>screencast</a>
 to teach web development with

 <a href=“https://rubyonrails.org/”>Ruby on Rails</a>.
 This is the sample app for the tutorial.
</p>
で、テスト
$ rails test
前略
3 runs, 3 assertions, 0 failures, 0 errors, 0 skips
無事エラーがゼロになった。そしてブラウザにhttp://localhost:3000/static_pages/aboutと入力すると

と表示された。

カテゴリー: その他 | コメントする

4:ほぼ静的なページの作成

サンプルアプリケーションを生成する
$ cd ..
$ pwd
/Rails/environment
$ rails _7.0.6_ new sample_app –skip-bundle
create
    create README.md
    create Rakefile
    create .ruby-version
   後略
$ cd sample_app/
Gmfileの編集
$ gedit Gemfile
source “https://rubygems.org”
git_source(:github) { |repo| “https://github.com/#{repo}.git” }

gem “rails”, “7.0.6”
gem “sassc-rails”, “2.1.2”
gem “sprockets-rails”, “3.4.2”
gem “importmap-rails”, “1.1.0”
gem “turbo-rails”, “1.1.1”
gem “stimulus-rails”, “1.0.4”
gem “jbuilder”, “2.11.5”
gem “puma”, “5.6.4”
gem “bootsnap”, “1.12.0”, require: false

group :development, :test do
gem “sqlite3”, “1.4.2”
gem “debug”, “1.5.0”, platforms: %i[ mri mingw x64_mingw ]
end

group :development do
gem “web-console”, “4.2.0”
end

group :test do
gem “capybara”, “3.37.1”
gem “selenium-webdriver”, “4.2.0”
gem “webdrivers”, “5.0.0”
gem “rails-controller-testing”, “1.0.5”
gem “minitest”, “5.15.0”
gem “minitest-reporters”, “1.5.0”
gem “guard”, “2.18.0”
gem “guard-minitest”, “2.4.6”
end

group :production do
gem “pg”, “1.3.5”
end
gemをインストール
$ bundle _2.3.14_ config set –local without ‘production’
$ bundle _2.3.14_ install
Fetching gem metadata from https://rubygems.org/………..
Resolving dependencies…….
Using rake 13.0.6
Using concurrent-ruby 1.2.2
後略

gitにコミット
$ git init
Reinitialized existing Git repository in /Rails/environment/sample_app/.git/
$ git add -A
$ git commit -m “Initialize repository”
[main (root-commit) 70d02f5] Initialize repository
70 files changed, 1235 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 .ruby-version
create mode 100644 Gemfile
後略
README.md
を書き換えてみる
$ gedit README.md
# Ruby on Rails チュートリアルのサンプルアプリケーション

これは、次の教材で作られたサンプルアプリケーションです。
[*Ruby on Rails チュートリアル*](https://railstutorial.jp/)
(第7版)
[Michael Hartl](https://www.michaelhartl.com/) 著

ライセンス
後略
この変更をコミットする
$ git commit -am “Improve the README”
[main 7cba1a8] Improve the README
1 file changed, 37 insertions(+), 13 deletions(-)
helloアクションをApplicationコントローラーに追加する
$ gedit app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def hello
render html: “hello, world!”
end
end
ルーティングを設定する
$ gedit config/routes.rb
Rails.application.routes.draw do
  root “application#hello”
end
そしてコミット
$ git commit -am “Add hello”
[main b394c69] Add hello
2 files changed, 4 insertions(+), 4 deletions(-)
バンドルをロック
$ bundle _2.3.14_ lock –add-platform x86_64-linux
Writing lockfile to /Rails/environment/sample_app/Gemfile.lock
ブランチを作成
$ git switch -c static-pages
Switched to a new branch ‘static-pages’
StaticPagesコントローラを生成する
$ rails generate controller StaticPages home help
  create app/controllers/static_pages_controller.rb
  route get ‘static_pages/home’
    get ‘static_pages/help’
  invoke erb
後略
これでapp/controllers/static_pages_controller.rbにhomeとhelpが追加される

gitにコミット
$ git add -A
$ git commit -m “Add a Static Pages controller”
[static-pages 3020c96] Add a Static Pages controller
6 files changed, 28 insertions(+)
create mode 100644 app/controllers/static_pages_controller.rb
create mode 100644 app/helpers/static_pages_helper.rb
後略
そしてapp/controllers/static_pages_controller.rbを見てみると
class StaticPagesController < ApplicationController
 def home
 end

 def help
 end
end
とhomeとhelpのアクション(ブランクだが)が追加されている
ルートファイルにhomeとhelpの定義が追加されている。見てみよう
$ cat config/routes.rb
Rails.application.routes.draw do
 get ‘static_pages/home’
 get ‘static_pages/help’
 root “application#hello”
end
別ターミナルでserverが立ち上げっているのを確認後、http://localhost:3000/static_pages/homeにアクセスすると

このページはコントローラーのhomeによって呼び出されたapp/views/static_pages/home.html.erbの内容が表示されている
同様にhelpも同じ感じで表示される筈だ
HomeページのHTMLを修正する
$ gedit app/views/static_pages/home.html.erb
<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href=”https://railstutorial.jp/”>Ruby on Rails Tutorial</a>
  sample application.
</p>
そしてブラウザからhttp://localhost:3000/static_pages/homeにアクセスすると

同様に
$ gedit app/views/static_pages/help.html.erb
<h1>Help</h1>
<p>
    Get help on the Ruby on Rails Tutorial at the
    <a href=”https://railstutorial.jp/help”>Rails Tutorial Help page</a>.
    To get help on this sample app, see the
   <a href=”https://railstutorial.jp/#ebook”><em>Ruby on Rails Tutorial</em>
    book</a>.
</p>
そしてブラウザから

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

中国からの危険なメール

画像に alt 属性が指定されていません。ファイル名: smbc.png

このメールは巧妙に偽造されているメールです。詳しい説明は省くが(詳しく知りたい方はメールヘッダーをチェックしてください)①は偽造されているので、本当はsmbcから送られてはいない。②は青字の本人確認をの所にマウスを持って行くと表示されるもので、クリックするとここに飛ぶ。ここのドメインはやたら長い文字の後に(いかにもインチキ臭いが).topになっている。このtopというドメインは中国が管理しているので、絶対にクリックしてはいけない。繰り返しますが.topドメインは絶対にクリックしない事

カテゴリー: 危険メールや手紙、IP | コメントする

3:チュートリアル続き2

toyアプリケーションを作る
$ cd ..
$ rails 7.0.6 new toy_app –skip-bundle
$ cd toy_app/
Gemfile編集
$ gedit Gemfile
source “https://rubygems.org”
git_source(:github) { |repo| “https://github.com/#{repo}.git” }

ruby “3.2.2”

gem “rails”, “7.0.6”
gem “sassc-rails”, “2.1.2”
gem “sprockets-rails”, “3.4.2”
gem “importmap-rails”, “1.1.0”
gem “turbo-rails”, “1.1.1”
gem “stimulus-rails”, “1.0.4”
gem “jbuilder”, “2.11.5”
gem “puma”, “5.6.4”
gem “bootsnap”, “1.12.0”, require: false
gem “sqlite3”, “1.4.2”

group :development, :test do
gem “debug”, “1.5.0”, platforms: %i[ mri mingw x64_mingw ]
end

group :development do
gem “web-console”, “4.2.0”
end

group :test do
gem “capybara”, “3.37.1”
gem “selenium-webdriver”, “4.2.0”
gem “webdrivers”, “5.0.0”
end

gemをインストールし、ロックする
$ bundle _2.3.14_ install

$ bundle _2.3.14_ lock –add-platform x86_64-linux
helloのアクションを追加し、ルートの設定
$ gedit app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def hello
    render html: “Toy_app hello, world!”
  end
end
$ gedit config/routes.rb
Rails.application.routes.draw do
  root ‘application#hello’
end

でもう一つにターミナルで起動しているサーバーをctrl+cで止め、ディレクトリーを変更し、サーバーを起動
$ cd ..
$ cd toy_app
$ rails s
でlocalhost:3000 でToy_app hello, world!と表示される筈

元のターミナルに戻りgit init, add, commitを行う
$ git init
Reinitialized existing Git repository in /Rails/environment/toy_app/.git/
$ git add -A
$ git commit -m “Add hello”

scaffoldを使いUser データーベースを作成
$ rails generate scaffold User name:string email:string
色々追加されるが、この意味はデーベース名をUserとし、テーブルnameとemailを文字列として作成、続いてデーターベースをマイグレートする
$ rails db:migrate
== 20230811074601 CreateUsers: migrating ========
— create_table(:users)
   -> 0.0022s
== 20230811074601 CreateUsers: migrated (0.0022s) ===
ここで、ブラウザから localhost:3000/usersとすると

と表示される筈、New userをクリックするとユーザーを作成出来るので試す。


emailはわざと正しくない(@が無い)ものを入力し、Create Userをクリックし保存(検証をしていないので)。保存出来てしまう
上の画像が保存後のもの、メチャクチャなemailが登録されている。下の方のリンクをクリックすると、その内容の画面になる。ブラウザに http://localhost:3000/users/newと入力し、もう一人作り保存し、http://localhost:3000/users/と入力すると
2人分のリストが表示される。後、チュートリアルにあるように削除などをやってみる。

ルートを設定する
$ gedit config/routes.rb
Rails.application.routes.draw do
  resources :users
  root ‘users#index’
end
そして、app/controllers/users_controller.rbを見てみると

下の方が表示されていないが、scaffoldにより index, showなどが自動的に出来ている。

Micropostsリソースもscaffoldでコードを生成
$ rails generate scaffold Micropost content:text user_id:integer
データーベースをマイグレーション
$ rails db:migrate
== 20230813055824 CreateMicroposts: migrating =========
— create_table(:microposts)
  -> 0.0019s
== 20230813055824 CreateMicroposts: migrated (0.0019s) ===========
config/routes.rbを開いてみると
$ cat config/routes.rb
Rails.application.routes.draw do
   resources :microposts    ← 追加されている
   resources :users
   root ‘users#index’
end
また、app/controllers/microposts_controller.rbも追加されているので、ブラウザに http://localhost:3000/microposts/newと入力しマイクロポストを新規に作って見る

そしてCreate Micropostをクリックし、作成すると

と、表示されるので、userの時と同じようにいくつか作って、index,show destoryなどをやってみる。
異なるデータモデル同士の関連付けをやっていくが、userは複数のmicropostを持てるし、micorpostはuserが持っているので
$ gedit app/models/user.rb
class User < ApplicationRecord
  has_many :microposts
end
$ gedit app/models/micropost.rb
class Micropost < ApplicationRecord
  belongs_to :user
style=”color: #ff6600;”>end

また、これまではデーターベースに入力されるデーターの検証を一切やってないので、制限や検証をやっていく。先ずはマイクロポストの最大文字数を140文字に制限する
$ gedit app/models/micropost.rb
class Micropost < ApplicationRecord
  validates :content, length: { maximum: 140 }
end
そして、micropostに140文字以上を入力してどうなるか試す。

141文字入れるとエラーになる(この文字数は全角でも141文字の様だ、全角1文字はやはり1文字と数える)
次はuser,emailを空白にしたらエラーを出す
$ gedit app/models/user.rb
class User < ApplicationRecord
  has_many :microposts
  validates :name, presence: true
  validates :email, presence: true
end
そして、ブラウザにuser, micropostを空欄にしてCreate Userをクリックすると


とエラーが表示される

そしてgitにコミット
$ git status
On branch main
Changes not staged for commit:
 (use “git add <file>…” to update what will be committed)
 (use “git restore <file>…” to discard changes in working directory)
 modified: config/routes.rb
 後略
$
git add -A
$ git commit -m “Finish toy app”
[main e33fc8d] Finish toy app
36 files changed, 589 insertions(+), 1 deletion(-)
create mode 100644 app/controllers/microposts_controller.rb
create mode 100644 app/controllers/users_controller.rb
create mode 100644 app/helpers/microposts_helper.rb

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

2:Railsのチュートリアルをやる1

https://railstutorial.jp/chapters/beginning?version=7.0#cha-beginningを参考にして行っていく。はじめにこのチュートリアルと違うのは
1:IDE(cloud9)で無く、ローカルのサブホストで行っている
2:rubyとrailsが違っている。ruby 3.1.2 → 3.2.2,  rails 7.0.4 → 7.0.6
3:一人でやっているのでgithubは使わない
4:ディプロイをしないので render は使わない
で早速、時間がかかるのでRubyドキュメントをスキップする設定
$ echo “gem: –no-document” >> ~/.gemrc
bundlerのバージョンを指定してインストールする
$ gem install bundler -v 2.3.14

私はrailsのデーターは独立した領域を割り当てていて、そこに保存するようにしている。
$ sudo mkdir /ライリスを保存するディレクトリ
$ sudo chown -R ユーザー名. /ライリスを保存するディレクトリ
$ cd /ライリスを保存するディレクトリ
$ mkdir environment     ← 開発用ディレクトリーを作る
$ cd environment
バージョンの優先順位は高い方から rbenv shell, rbenv local, rbenv global の順になっている。前にグローバルを設定しているがlocalも設定しておく
$ rbenv local 3.2.2
テストプログラム hello_app を作る
$ rails _7.0.6_ new hello_app –skip-bundle
色々インストールされる。次はGemfileの編集
$ cd hello_app
$ gedit Gemfile

source “https://rubygems.org”
git_source(:github) { |repo| “https://github.com/#{repo}.git” }

ruby “3.2.2”

gem “rails”, “7.0.6”
gem “sprockets-rails”, “3.4.2”
gem “importmap-rails”, “1.1.0”
gem “turbo-rails”, “1.1.1”
gem “stimulus-rails”, “1.0.4”
gem “jbuilder”, “2.11.5”
gem “puma”, “5.6.4”
gem “bootsnap”, “1.12.0”, require: false
gem “sqlite3”, “1.4.2”

group :development, :test do
gem “debug”, “1.5.0”, platforms: %i[ mri mingw x64_mingw ]
end

group :development do
gem “web-console”, “4.2.0”
end

group :test do
gem “capybara”, “3.37.1”
gem “selenium-webdriver”, “4.2.0”
gem “webdrivers”, “5.0.0”
end

rubyとrailsのバージョンがチュートリアルとは違う
gemをインストールし、ロックしておく
$ bundle _2.3.14_ install
$ bundle _2.3.14_ lock –add-platform x86_64-linux
次にターミナルを追加し、railsをインストールすると追加されているWEBサーバーを起動する(追加したターミナルでの作業)
$ cd
/ライリスを保存するディレクトリ/environment/hello_app
$ bundle install –gemfile /ライリスを保存するディレクトリ/environment/hello_app/Gemfile
あれーエラーが出ている
An error occurred while installing sqlite3 (1.4.2), and Bundler cannot continue.
これはsqlite-develを入れればいいみたい
$ sudo dnf install sqlite-devel    ←この時yum.repo.dのalmalinux-crb.repoのenabled=が1になっていること
再度
$ bundle install –gemfile /ライリスを保存するディレクトリ/environment/hello_app/Gemfile
$ rails server
=> Booting Puma
=> Rails 7.0.6 application starting in development
=> Run `bin/rails server –help` for more startup options
Puma starting in single mode…
* Puma version: 5.6.4 (ruby 3.2.2-p53) (“Birdie’s Version”)
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 42058
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop

そして、ブラウザのURL欄にlocahost:3000
と入力したら
と表示された

元のターミナルに戻って、アクションを追加します。
$ gedit app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def hello                      ← ここから3行を追記
    render html: “hello, world”
  end
end
次にルートを設定
$ gedit config/routes.rb
Rails.application.routes.draw do
  root “application#hello”
end
そして、ブラウザに戻って、再読み込みをすると
hello, worldが表示される

元のターミナルの戻り、gitのセットアップ
gitのバージョンを確認
$ git –version
git version 2.39.3
次に名前とemailの設定
$ git config –global user.name kk-otake
$ git config –global user.email メアド
確認は git config user.name などで出来る。次は、Gitのデフォルトブランチ名の設定です
$ git config –global init.defaultBranch main
エイリアスを設定して置くと便利なので、git sをstatusのエイリアスに設定する
$ git config –global alias.s status
コマンドを入力するたびにパスワードを入力しなくて済むように認証情報をキャッシュする。
$ git config –global credential.helper “cache –timeout=86400”
これで1日に設定された。
新しいリポジトリの初期化
$ git init
Reinitialized existing Git repository in /Rails/environment/hello_app/.git/
全ファイルをリポジトリに追加
$ git add -A
gitのステイタスを見てみる
$ git s
On branch main

No commits yet

Changes to be committed:
(use “git rm –cached <file>…” to unstage)
new file: .gitattributes
new file: .gitignore
new file: .ruby-version
後略

リポジトリに保存(コミット)する
$ git commit -m “Initialize repository”  ← -mはコメント
[main (root-commit) a6e33ca] Initialize repository
70 files changed, 1170 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .gitignore
後略

ログを見てみる

$ git log
commit a6e33cab770514bc9f373bd962102bab8f4663d3 (HEAD -> main)
Author: f-otake <otake@inpac.jp>
Date: Thu Aug 10 09:23:22 2023 +0900
Initialize repositor

Gitのブランチ(Branch)
$ git switch -c modify-README
Switched to a new branch ‘modify-README’
$ git branch
main
* modify-README
*がついている所が使用中のブランチ
Gitの編集(Edit)
練習の為README.mdを編集
$ gedit README.md

# Ruby on Rails Tutorial

## “hello, world!”

This is the first application for the
[*Ruby on Rails Tutorial*](https://railstutorial.jp/)
by [Michael Hartl](https://www.michaelhartl.com/). Hello, world!

そして保存後、確認
$
git status
On branch modify-README
Changes not staged for commit:
(use “git add <file>…” to update what will be committed)
(use “git restore <file>…” to discard changes in working directory)
modified: README.md

no changes added to commit (use “git add” and/or “git commit -a”)

でもって、コミット(オプション-aはすべての変更ファイル(git mvで作成したファイルも含む)をまとめてコミット)
$ git commit -a -m “Improve the README file”
[modify-README ca00142] Improve the README file
1 file changed, 5 insertions(+), 22 deletions(-)
Gitのマージ(Merge)

$ git switch main
Switched to branch ‘main’
$ git merge modify-README
Updating a6e33ca..ca00142
Fast-forward
README.md | 27 +++++———————-
1 file changed, 5 insertions(+), 22 deletions(-)

変更をマージした後は、git branch -dを実行してトピックブランチを削除
$ git branch -d modify-README
Deleted branch modify-README (was ca00142).

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

サブホストの画面に解像度を追加する

almalinux 9を追記;2023-2-11、下記の紫字がalmaに関する記述
私はKVMを使いサブホストを作り、いろいろなテストやサーバーを立ち上げています。
サブホストへのアクセスはvirt-managerから当該サブホストを選び画面上の開くをクリックして編集などをしています。この時解像度は1920×1080となり、これではスクロールダウンしないと画面のしたの方が見えません。そこで解像度を追加して行きます。色々試した結果 1920×900が最適と分かり、これを追加します。現在サポートしている解像度を表示(注、下の文字の入力は- – になっている所がありますが、表示はー一つになって見えますし、コピペしてもーは一つなので気をつけて下さい。wordpressのバグ??)
# xrandr -q
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 8192 x 8192
Virtual-0(almaはVirtual-1) connected primary 1920×1080+0+0 0mm x 0mm 
1024×768 59.95+
1920×1200 59.95
1920×1080 60.00*
1600×1200 59.95
1680×1050 60.00
1400×1050 60.00
1280×1024 59.95
1440×900 59.99
1280×960 59.99
一部省略
Virtual-1 disconnected(almaではdisconnectedは表示されない)
Virtual-2 disconnected
Virtual-3 disconnected
注:almalinuxでVirtual-1 でない場合はこのページの一番したのログイン画面を参考にして、X11にしてください
次にcvt を実行して希望の解像度の Modeline を取得します
# cvt 1920 900
# 1920×900 59.97 Hz (CVT) hsync: 56.01 kHz; pclk: 142.50 MHz
Modeline “1920x900_60.00” 142.50 1920 2032 2232 2544 900 903 913 934 -hsync +vsync
解像度の追加
# xrandr –newmode “1920x900_60.00” 142.50 1920 2032 2232 2544 900 903 913 934 -hsync +vsync
newmodeの後にcvtで得られたデータを入れる。このモードを追加する
# xrandr –addmode Virtual-0(almaはVirtual-1) 1920x900_60.00
Virtual-0は現在のスクリーン番号。この時画面の解像度が変化したが(小さくなった)そして現在の画面に反映させる
# xrandr –output Virtual-0(almaはVirtual-1) –mode 1920x900_60.00
これで画面の下まで見れる。だけど再起動すると全部消え、またxrandr –newmodeからやるハメになるので、デフォルトの解像度にする。(almaLinuxは下記を参照)
# gedit /etc/gdm/Init/Default
#!/bin/sh
# Stolen from the debian kdm setup, aren’t I sneaky
# Plus a lot of fun stuff added
# -George

PATH=”/usr/bin:$PATH”
OLD_IFS=$IFS

xrandr –newmode “1920x900_60.00” 142.50 1920 2032 2232 2544 900 903 913 934 -hsync +vsync
xrandr –addmode Virtual-0 1920x900_60.00
xrandr –output default –mode 1920x900_60.00
注:almaLinuxでは上の2行は不要だった
xrandr –output Virtual-1 –mode 1920x922_60.00

gdmwhich () {
COMMAND=”$1″
OUTPUT=
IFS=:
for dir in $PATH
do
if test -x “$dir/$COMMAND” ; then
if test “x$OUTPUT” = “x” ; then
OUTPUT=”$dir/$COMMAND”
fi
fi
done
IFS=$OLD_IFS
echo “$OUTPUT”
}
青字の所を追加する。私の場合は
xrandr –addmode default では駄目で
xrandr –output Virtual-0ではダメだった、理由は不明
これで再起動後も大丈夫では無かった。
今度はグラフィカルの設定からやってみる
アプリケーション → システムツール → 設定 → 左ペインのデバイスを選び、また左のディスプレイをクリック、右ペインの解像度をクリックすると作った 1920×900があるので、それをクリックし、設定を終了。
これで再起動し、ログイン後(ログイン画面は小さい)無事1920×900になった。

本日(2023-3-25)ログイン後でも解像度が変更になってない(CentOS7)
調べるとどうも/etc/gdm/Init/Defaultを行っていないみたいなので、/etc/rc.d/rc.localの最後に /etc/gdm/Init/Defaultを追記したが、
xrandr –output default –mode 1920x900_60.00
xrandr –output Virtual-0 –mode 1920x900_60.00に変更すること

almaLinuxでは/etc/gdm/Init/Defaultを変更しても再起動後には反映しなかったので、調べるとここに回答があった
X Window SystemX.orgからWaylandにデフォルトが変更になったので
# gedit /etc/gdm/custom.conf   (抜粋)

[daemon]
# Uncomment the line below to force the login screen to use Xorg
WaylandEnable=false  コメントアウトを取る

[security]

これでディスプレーサーバーが X11になる
#
gedit /etc/xdg/autostart/resoChg.desktop   ファイル名は最後に.desktopがあれば何でもらしい
[Desktop Entry]
Type=Application
Name=GNOME run Default
Exec=/etc/gdm/Init/Default
OnlyShowIn=GNOME;
NoDisplay=true;
これでログインすると希望の解像度になった。
念の為、下の画像はパスワードの入力右下の歯車をクリックするとディスプレーサーバーが何になっているか分かる。


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

$ bundle 2.4.18 installでエラー

sqlite-develをインストールしろとエラーが出た。これをインストールするがその前に/etc/yum.repos.d/almalinux-crb.repoの[crb]にあるenabled=が1になっている事を確認後
$ sudo dnf install sqlite-devel
でインストールをしておく


カテゴリー: その他 | コメントする

PINGが通らない

ある時baculaでバックアップの設定をしている時、一つのサブホストだけPINGが通らない。でもそこからbaculaが動いているサブホストにはPINGが通る?
最初はICMPエコー-no設定を疑ったが、問題ない
ここからはPINGを通してくれないサブホストでの設定
# firewall-cmd –list-all –zone=domestic ← domesticゾーン情報確認

domestic (active)  ← donesticは日本に割り当てられたグローバルIP
  target: default ← 許可していないアクセスは拒否
  icmp-block-inversion: no  ← ここがNOで下にある icmp-blocks:に設定が
  interfaces:                           無いのでどこからでもPING応答する
  sources: ipset:domestic ← IPセット(日本国内)
  services: dns http https imaps ipsec pop3 pop3s smtp smtps ssh
  ports: 20000/tcp 8080/tcp ← ポート(このポートと上のサービスはダミーだよ)
  protocols:
  forward: no
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

これには随分泣かされた。やっと気が付いたのはROUTING
# route

Kernel IP routing table
Destination  Gateway   Genmask   Flags   Metric  Ref  Use  Iface default  buffalo.setup  0.0.0.0     UG    100   0    0  enp1s0 buffalo.setup  0.0.0.0    255.255.255.255    UG             0             0             0     enp1s0

本来なら最後の行は
192.168.4.0   0.0.0.0  255.255.255.0  U        100      0      0     enp1s0
になっていなくてはならない。
このOSはAlmalinux 8なので今までのCentOS7とは勝手が違い、/etc/sysconfig/network-scriptsに設定をする訳では無い。nmcliを使え等と言っているが、老体の俺には覚えるのが辛い。まずは一番下のGATEWAYを消すbuffalo.setupのIPは192.168.xx.xxなので、
# ip route delete 192.168.xx.xx
そしてルートを追加
# nmcli con add type ethernet ifname enp1s0
この時正確な表示は覚えていないが、ethernet-enp1s0-1 を設定したみたいなのが出た
# nmcli con mod ethernet-enp1s0-1 ipv4.gateway 0.0.0.0

# route

Kernel IP routing table
Destination  Gateway   Genmask   Flags   Metric  Ref   UseIface
default   buffalo.setup  0.0.0.0    UG    100   0    0   enp1s0
192.168.4.0   0.0.0.0  255.255.255.0   U      100      0      0     enp1s0

と正常になったので
baculaのサブホストに移り、PINGを実行。やっと帰ってきた。やれやれ

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

全てのサブホストで数字キー以外を受け付けない!!

これには閉口した。もうログインすら出来ない! ただメインのホストは正常だ。
再起動したり色々試したが直らない。どうも日本語の関係がおかしいみたいだ。なのでメインのホストで、アプリケーション → システムツール → 設定から下記の画像のように“地域と言語”で入力ソースに英語を追加し、日本語(かな漢字)と日本語の二つを削除し、サブホストのログインを試すと無事文字キーも入力出来たので、
その後日本語(かな漢字)と日本語の二つを追加し、英語を削除したが、サブホストでは文字キーも問題なく入力出来た。バンザーイ!!

カテゴリー: その他 | コメントする

php-fpm が少し変更になった?

almalinux9のサブホストをalmalinux8で作成中、このホストはWEBサーバーやMAILサーバーにする予定。複数のバーチャルWEBの中に古いXOOPSがあり、これがphp56でしか動かないので、almalinux9でphp56がインストール出来ず、almalinux8を使えと言われたので、バージョン8で作成。
前置きが長くなったが、インストールしたいphpのバージョンは 5.6と7.4。
早速 https://qiita.com/bezeklik/items/860ba080bf4c664cd8e9 などを参考にphp-fpmなどをインストールたが、これらのWEBから変更になった箇所が有る見たい

php56のphp.iniの場所が変更になった、以前は
/opt/remi/php56/root/etc/php.ini
だったが、php74と同じような場所になった
/etc/opt/remi/php56/php.ini

listen portを使わなくなった見たい。以前は port=9056などと指定をしていたが、これがポートでは無くソケットを使うようだ。
listen = /var/opt/remi/php56/run/php-fpm/www.sock

 

カテゴリー: その他 | コメントする