ネットでいちいち調べ直すのも面倒になってきたので、 また、紙のメモでは探し出すのも難しいくらい多くなったので、 ここにメモしておきます。
主に Linux サーバ(今は CentOS Stream release 8)の管理関係
$ sudo reboot
$ sudo systemctl start httpd.service $ sudo systemctl restart httpd.service $ sudo systemctl stop httpd.service
firewalld、postgresql.service、sshd なども同じ
$ systemctl list-unit-files --type=service
$ sudo systemctl enable httpd.service $ sudo systemctl disable httpd.service
$ sudo systemctl daemon-reload
$ sudo useradd -b ユーザのホームディレクトリ -m ユーザ名 $ sudo useradd -b BASE_DIR -m -G GROUP -p PASSWORD USERNAME ← こういうものらしい
オプション -m:ユーザのホームディレクトリを作成する
$ sudo userdel -r ユーザ名
$ sudo passwd ユーザ名 $ passwd ← 自分のパスワードを変更するとき
CentOS Stream release 8 では、パッケージの管理には dnf を使う
$ dnf list installed
$ dnf repolist
$ perl -MExtUtils::Installed -e 'print "$_\n" for ExtUtils::Installed->new->modules'
$ sudo dnf install epel-release
$ sudo dnf install httpd
$ sudo dnf remove httpd
$ dnf check-update
$ sudo dnf upgrade httpd*
(Apache の場合)
$ sudo dnf upgrade
$ sudo dnf install perl-App-cpanminus $ sudo cpanm --sudo -v モジュール名
cpan minus をインストールして、perl のモジュールは cpan minus で管理する
$ crontab -e 34 12 * * 5 /home/hogeuser/hogehoge.sh # 分 時 日 月 曜日 コマンド
金曜(5 が金曜) 12:34 に動く
5 の代わりに * にしておくと毎日(0-7 で 0 と 7 が日曜)
時刻と曜日の間は、日月
/etc/ssh/sshd-config を編集
AllowUsers hogeuser@"***.***.***.***, ***.***.***.***, ***.***.***.***, ***.***.***.***" AllowUsers hoheuser@"***.***.***.***, ***.***.***.***, ***.***.***.***, ***.***.***.***" AllowUsers gogeuser@"***.***.***.***, ***.***.***.***, ***.***.***.***, ***.***.***.***"
今は、TLS(Transport Layer Security)だけれど、SSL の名前は引きずっている。
素の Apache にはインストールされていない
$ sudo dnf install mod_ssl
適切なディレクトリや設定ファイルもできる
ssl.conf のコンテキストを設定する:httpd_config_t になっていないと Apache が起動しない
$ openssl s_client -connect hogehoge.hohehohe.ac.jp:443
$ openssl x509 -text -noout -in 証明書 $ openssl rsa -text -noout -in 秘密鍵 $ openssl s_client -connect hogehoge.hohehohe.ac.jp:443 -showcerts
テストサーバでサーバ証明書が必要なとき
$ openssl genrsa 2048 > server.key $ openssl req -new -key server.key > server.csr ← ここで common name(URL)を入力する $ openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt
/etc/httpd/conf.d/ssl.conf
SSLCertificateChaneFile server.crt SSLCertificateChaneKeyFile server.key
とする
$ getenforce Enforcing ← SELinux 有効=実行中 Disable ← SELinux 無効 Permissive ← SELinux 無効、ログ残る
$ sestatus SELinux status: enabled (以下略:getenforce より詳しいものが表示される)
/etc/selinux/config
SELINUX=enforcing
にする
OSの再起動をする前に(permissive mode でいろいろやってOKだったら)
$ sudo fixfiles -F onboot
permissive mode では、オプション -F がいると redhat.com にあった
$ ls -lZ
オプション Z でコンテキストが見える
$ sudo chcon -R -u system_u -t :httpd_sys_content_t ディレクトリ名
ディレクトリ名の最後には「/」を付けない オプション -R:ディレクトリ以下全て
↓ でもいいらしい
$ sudo chcon -R system_u:object_r:httpd_sys_content_t ディレクトリ名
$ getsebool -a
$ sudo setsebool -P httpd_enable_homedirs ON ← public_html を公開する
$ sudo firewall-cmd --list-all $ sudo firewall-cmd --list-all --permanent ← permanentであるもののみ表示
$ sudo firewall-cmd --state running
$ sudo firewoll-cmd --add-service https ← 今通す $ sudo firewoll-cmd --permanet --add-service https ← 登録
今は、プログラムとしては sendmail ではなく、postfix を使う
$ sudo dnf install postfix
/etc/postfix/main.cf を編集
たぶん、IPv6でサーバが動いていないので、
/etc/hosts を編集し、IPv6関連をコメントアウトする
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
「::1」は IPv6 なのだそう
$ cat /etc/centos-release $ cat /etc/redhat-release # /etc/centos-release のシンボリックリンク $ cat /etc/system-release # /etc/centos-release のシンボリックリンク $ cat /etc/os-release # 上のより詳しいものも表示される
$ httpd -v
$ curl inet-ip.info
↑ は、Windows10 でも、Windows11 でも使える
$ ip a
$ du -sh [hoge_dir] # directory usage
いちいち読んでいるようなので、ディレクトリの数が多いと時間がかかる
オプション -sh を付けないと、各ディレクトリの容量のリストも表示される
$ less /etc/passwd
今は passwd ファイルにはパスワードは格納されていない
home directory もわかる
$ less /etc/group
あまり使い途はないかも?
$ sudo httpd -t -D DUMP_VHOSTS
$ scp -r user@***.***.***.***:/home/user/元ディレクトリ 先ディレクトリ $ scp -r 元ディレクトリ user@***.***.***.***:/home/user/先ディレクトリ
オプション -r: recursive
$ find . -type d | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
参照(というよりはそのままです):treeを使わずにfindでディレクトリツリーリスト表示
$ sudo ln -s 元ディレクトリ(またはファイル) シンボリックリンク
$ cp -a 元ディレクトリ(またはファイル)先ディレクトリ(またはファイル)
オプション -a は archive = -dR -- preserve=all と同じ
レポジトリからのインストールが上手くいかなかったので……
$ wget http://ftp.jaist.ca.jp/pub/CTAN/systems/texlive/tlnet/install-tl-unx.tar.gz $ tar xvzf install-tl-unx.tar.gz $ cd install-tl-日付 $ sudo ./install-tl (いろいろ表示されて) <I> start installation to hard disk …… Enter command: I ← 「I」と入力し、エンターキーを押す
1時間以上インストールしていた
$ echo $PATH texlive に path が通っていないものが表示される $ sudo vi /etc/profile.d/texlive.sh ← 新規作成
/etc/profile.d/texlive.sh
PATH=/usr/local/texlive/2021/bin/x86_64-linux/:$PATH; export PATH MANPATH=/usr/local/texlive/2021/texmf-dist/doc/man:$MANPATH; export MANPATH INFOPATH=/usr/local/texlive/2021/texmf-dist/doc/info:$INFOPATH; export INFOPATH
とする
新たにログインすると使えるようになっている
path も通っている
$ mysql --defaults-extra-file=/home/hogehoge/mysqldump.cnf --add-drop-table --databases hogehogedb
cron などでも使える
mysqldump.cnf にデータベースのアクセス情報を入れておく
オプション --add-drop-table を付けておくと、ダンプした sql を実行したとき、新しい(または戻す)データベースの中に既に何かあったら削ってくれる
mysqldump.cnf の中身
[client] user=mysqlusernamehoge password='hogepasswd' ← クォーテーションで囲むと、ややこしい文字もおっけいになる host=localhost
$ sudo dnf install https://rpm.remirepo.net/enterprize/remi-release8.rpm ← 事前に EPEL のインストールが必要 $ sudo dnf install phpmyadmin --enablerepo=remi
ローカルマシン以外から phpMyAdmin が使えるように
/etc/phpMyAdmin/config.inc.php を変更
$cfg['Servers'][$i]['host'] = '127.0.0.1'; ← 'localhost' から変更
IPアドレスによる制限も
/etc/httpd/conf.d/phpMyAdmin.conf
#Require local Require ip ***.***.***.***
$ mysql -u root -p > create user 'hogeuser' identified by 'hogepassword'; > create database hogedb; > grant all privileges on hogedb.* to hogeuser identified by 'hogepassword'; > \q
Today:2 | Yesterday:3 | Total:711 since 22 December 2021 |