2022年5月10日火曜日

Rocky Linux chrony 設定

# dnf install chrony

NTPD停止
# systemctl stop ntpd
# systemctl disable ntpd

# systemctl start chronyd
# systemctl enable chronyd
# systemctl status chronyd
# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^-   v118-27-19-72.cxxt.stati>        2  10   377   518    +1271us[+1271us] +/-   13ms
^+  i45-32-25-115.vpsv.d.rsp>      3  10   207   878    +33us[  -61us] +/- 4448us
^-  y.ns.gin.ntt.net                            2  10   377   45m   -6994us[-7482us] +/-   91ms
^*  ipv4.ntp3.rbauman.com         2  10   377   874    +507us[ +412us] +/- 4536us

# chronyc -a makestep                    # 手動で同期 

【サーバ設定】
# vi /etc/chrony.conf
allow 192.168.254.0/24
# systemctl restart chronyd
# firewall-cmd --add-service=ntp --permanent
# firewall-cmd --reload

【クライアント設定】
# vi /etc/chrony.conf
#pool 2.pool.ntp.org iburst
pool 192.168.254.253 iburst
pool 192.168.254.254 iburst
# systemctl restart chronyd
# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.254.253               2   6   377    33    +58us[ +130us] +/- 2715us
M (Mode)
ソースのモードを示す。記号ごとにそれぞれ以下の意味がある。
^ はサーバー
= はピア
# はローカル

S (State)
この列は、ソースの状態を示します。
「*」は、chronyd が現在同期しているソースを表す。
「+」は、選択したソースと結合する、受け入れ可能なソースを表す。
「-」は、受け入れ可能なソースで、結合アルゴリズムにより除外されたものを表す。
「?」は、接続が切断されたソース、またはパケットがすべてのテストをパスしないソースを表す。
「x」は、chronyd が falseticker と考える (つまり、その時間が他の大半のソースと一致しない) クロックを表す。
「~」は、時間の変動性が大きすぎるように見えるソースを表します。
「?」条件は、少なくとも 3 つのサンプルが収集されるまで開始時にも表示されます。

2022年5月6日金曜日

Django web Serverの構築(websv)

# dnf install httpd httpd-devel
# dnf install python36 python3-libs python36-devel
# pip3 install --upgrade pip
# mkdir /var/www/wsgi
# chmod 0755 /var/www/wsgi
# mkdir /var/log/python/
# chmod  a+w /var/log/python                           ※ あとで直す。
# vi /etc/httpd/conf/httpd.conf
ServerName websv1:80
# dnf install gcc rpm-build
# pip3 install mod-wsgi
# vi /etc/httpd/conf.modules.d/20-wsgi.conf
LoadModule wsgi_module /usr/local/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
# httpd -M|grep wsgi
proxy_uwsgi_module (shared)
wsgi_module (shared)
#  vi /etc/httpd/conf.d/wsgi.conf
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
WSGIApplicationGroup %{GLOBAL}
WSGISocketPrefix /var/run/wsgi

WSGIDaemonProcess test user=apache group=apache processes=1 threads=100 maximum-                               requests=10000 \
                             home=/var/www/wsgi/test \
                            python-home=/var/www/wsgi/test/myenv/venv36-d324 \
                           python-path=/var/www/wsgi/test/django:/var/www/wsgi/test/myenv/venv36-d324/lib/python3.6/site-packages \
                           lang=ja_JP.utf8

WSGIScriptAlias /test /var/www/wsgi/test/Config/wsgi.py process-group=test

Alias /static/ /var/www/wsgi/test/static/
Alias /media/ /var/www/wsgi/test/media/
WSGIPassAuthorization on

# for s3
Alias /assets/ /s3/assets/
Alias /media/  /s3/media/
<Directory /s3/assets>
   Require all granted
</Directory>

<Directory /s3/media>
   Require all granted
</Directory>

<Location /test>
WSGIProcessGroup test
</Location>

#   cd  /var/www/wsgi
#    scp -rp root@websv1:/var/www/wsgi/test  .
# chown -R apache:apache test

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

# dnf remove mariadb* mysql*
# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
# dnf install MariaDB-client 
# dnf install zbar





apache バーチャルホスト リバースプロキシ 設定(仮想ホスト)

#---------------------------------------
# LOCATION リバースプロキシ
#---------------------------------------
# vi /etc/httpd/conf.d/wsgi.conf

<Proxy *>
  Require all granted
  #Order Deny,Allow
  #Deny from all
  #Allow from 192.168.25.146
</Proxy>

ProxyRequests Off
ProxyPreserveHost On

<Location /office>
  proxyPass http://192.168.25.146:80/office/ keepalive=On
  ProxyPassReverse http://192.168.25.146:80/office/
</Location>




#----------------------------------
# VirtualHost   ( 仮想ホスト )
#----------------------------------
インターフェースに複数IPを割り当てる
  VLAN=global_network
  VLAN_IP_1=192.168.1.241/24
  VLAN_IP_1=192.168.1.242/24
  VLAN_IP_1=192.168.1.243/24
  VLAN_IP_1=192.168.1.244/24
  VLAN_GW=192.168.1.1
  nmcli c delete $VLAN
  nmcli c add type ethernet ifname $DEVICE con-name "$VLAN"
  nmcli c mod $VLAN    ipv4.addresses $VLAN_IP_1
  nmcli c mod $VLAN +ipv4.addresses $VLAN_IP_2
  nmcli c mod $VLAN +ipv4.addresses $VLAN_IP_3
  nmcli c mod $VLAN +ipv4.addresses $VLAN_IP_4
  nmcli c mod $VLAN ipv4.method manual
  nmcli c mod $VLAN connection.autoconnect yes
  nmcli c mod $VLAN ipv4.gateway $VLAN_GW
  nmcli c up $VLAN


# dnf install httpd mod_ssl
# vi /etc/httpd/conf.d/httpd-vhost.conf
#-------------------------------------------
#  Link Server
#-------------------------------------------

<VirtualHost *:80>
  ServerName link.mydomain.example

  RewriteEngine on
  RewriteRule (.*)?$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
ServerName link.mydomain.example

<Proxy *>
Require all granted
</Proxy>

ProxyRequests Off
ProxyPreserveHost On

# LogLevel warn
# TransferLog logs/ssl_access_log

ProxyPass / http://10.0.1.101:80/ keepalive=On
ProxyPassReverse / http://10.0.1.101:80/
RequestHeader set X-Forwarded-Proto "https"

SSLEngine on

# SSLv2、SSLv3, TLS1.0 TLS1.1を無効化する
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDSA+AESGCM
# SSLCipherSuite PROFILE=SYSTEM
SSLHonorCipherOrder Off

SSLCertificateFile /etc/ssl/certs/ssl-cert-link.crt
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-link.key

</VirtualHost>

# cd /etc/ssl
 # ln -s  ../pki/tls/private private

#  apachectl configtest

# firewall-cmd --add-service=https --permanent
# firewall-cmd --reload

※ 下記は、httpdを起動すると勝手につくられる。
/etc/pki/tls/certs/localhost.crt
/etc/pki/tls/private/localhost.key
※ ssl.conf内の<VirtualHost _default_:443>は、マッチしなかった場合のデフォルト

【自己証明書】
# cd ~/Cert
#  openssl version
OpenSSL 1.1.1k  FIPS 25 Mar 2021
# openssl genrsa  -out ssl-cert-link.key  2048
# openssl req -new -key ssl-cert-link.key -out ssl-cert-link.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:link.mydomain.example
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# openssl x509 -days 3650 -req -signkey ssl-cert-link.key -in ssl-cert-link.csr -out  ssl-cert-link.crt

# cp  ssl-cert-link.crt  /etc/ssl/certs/
# cp ssl-cert-link.key /etc/ssl/private/

※確認方法
# openssl req -noout -text -in ssl-cert-link.csr
# openssl x509 -text -fingerprint -noout -in  ssl-cert-service.crt

URL: https://link.mydomain.example/test
URL: https://service.mydomain.example/test
URL: https://office.mydomain.example/test

※ key : RSA PRIVATE KEY(鍵)
     csr: CERTIFICATE REQUES(証明書の署名リクエスト)
     crt: CERTIFICATE( サーバ証明書)
     pem: BEGIN/END行で挟んだ書式(入れ物)

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...