2020年4月19日日曜日

Django インストール #2


$ sudo pip3 install virtualenv
$ virtualenv --version
$ virtualenv local/venv36-22
$ source local/venv36-22/bin/activate
※ $ deactivate
$ pip3 install django
$ cd Make
$ mkdir BI-tool
$ cd BI-tool
$ django-admin startproject Conf
$ python3 manage.py startapp app


※エラー
apxs not found
# dnf install httpd-devel
cc     not found
# dnf install gcc
make not found
# dnf instal make
mariadb-config not found
# dnf install MariaDB-devel
MySQLdb/_mysql.c:46:10: 致命的エラー: Python.h: そのようなファイルやディレクトリはありません
# dnf install python36-devel

ImportError: Unable to find zbar shared library
# dnf install zbar

2020年4月17日金曜日

CentOS8 mariaDBインストール

 ※Status code: 404 for https://dlm.mariadb.com/repo/mariadb-server/10.7....
 → Ver.10 サポート切れ!!
# dnf remove MareaDB-client
# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
# dnf install MariaDB-client

# dnf install MariaDB-server  MariaDB-devel
# mysql_upgrade --user=root --password=password

※ ERROR
- Downloading successful, but checksum doesn't match. Calculated
→ dnf --nogpgcheck install xxxx  / update

※ERROR
dnf install OpenIPMI-libs
dnf install mariadb-connector-odbc

※ERROR
正しい鍵 URL がこのリポジトリー用に設定されているか確認してください。. 失敗したパッケージは: MariaDB-client-10.7.8-1.el8.x86_64
→rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB


【CentOS8 にMariaDBの最新版をインストール】

【マウントした他ディスクにデータを置く場合。】
/u01にデータを格納するディスクをあらかじめマウント
# midir /u01
# vi /etc/fstab

/dev/vdb /u01 ext4 defaults
# sync;reboot
# mkdir -p /u01/MariaDB/mysql_data
# mkdir -p /u01/MariaDB/log
# touch /u01/MariaDB/log/mariadb_error.log

# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
※プロキシ環境で上手く行かなかったので、wgetでダウンロードした後にbashで実行。
# cat /etc/yum.repos.d/mariadb.repo
[mariadb-main]
name = MariaDB Server
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.5/yum/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1
module_hotfixes = 1

[mariadb-maxscale]
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
name = MariaDB MaxScale
baseurl = https://dlm.mariadb.com/repo/maxscale/latest/centos/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-tools]
name = MariaDB Tools
baseurl = https://downloads.mariadb.com/Tools/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1


# dnf remove mysql*
# dnf remove Mariadb*

# dnf install MariaDB

# chown -R mysql:mysql /u01/MariaDB
# chown -R mysql:mysql /u01

# vi  /etc/my.cnf.d/server.cnf 
[mariadb]
character-set-server=utf8
log_error = /u01/MariaDB/log/mariadb_error.log
datadir   = /u01/MariaDB/mysql_data/

[mariadb-10.5]
character-set-server=utf8

# mv /var/lib/mysql/* /u01/MariaDB/mysql_data/

# systemctl start mariadb
# systemctl enable mariadb

# mysql -u root
MariaDB [(none)]>  alter user root@localhost identified by 'password';

※ amazon linux では syntax error
→set password for root@localhost = password('password');

(リモートアクセス用 ユーザの作成)
MariaDB [(none)]>  create user admin@'%';
MariaDB [(none)]> grant all privileges on *.* to admin@'%'  with grant option;
MariaDB [(none)]> alter user admin@'%'  identified by 'password';
※amazon linux では syntax error
→ set password for  admin@'%' =password('password');
MariaDB [(none)]> flush privileges;

※ 「@'%'」省略可

(ローカルアクセス用ユーザの作成)
MariaDB [(none)]>  create user admin@localhost;
MariaDB [(none)]> grant all privileges on *.* to admin@localhost  with grant option;
MariaDB [(none)]> alter user admin@localhost  identified by 'password';
MariaDB [(none)]> flush privileges;

MariaDB [(none)]> select user, host, plugin from mysql.user;
+-----------------+-------------+----------------------------------+
| User                   | Host          | plugin                                       |
+-----------------+-------------+----------------------------------+
| mariadb.sys  | localhost  | mysql_native_password  |
| root                   | localhost  | mysql_native_password  |
| mysql               | localhost  | mysql_native_password  |
|                            | localhost   |                                                     |
|                            | rocky           |                                                     |
| admin              | %                  | mysql_native_password |
| admin              | localhost   | mysql_native_password |
+-----------------+---------------+---------------------------------+
7 rows in set (0.001 sec)

MariaDB [(none)]> quit

※リモートアクセスとローカルアクセスの入り口を持つ各ユーザを作成。

# mysql -u admin -ppassword
MariaDB [(none)]> create database testdb;
MariaDB [(none)]> quit

【※】
# systemctl start mariadb
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
# journalctl -xe
[ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
Failed to start MariaDB 10.5.8 database server.

→データベースのアップグレードが必要そう。
  今回は、面倒臭いので、
# systemctl stop mysqld
# dnf remove MariaDB*
# dnf remove mysql*
# mv /usr/lib/mysql /usr/lib/mysql.old 
してから、mariadbを再インストール


【CentOS8 にMariaDB Repositoryからインストール】

CentOS8にMariaDB インストールは、下記を参照

RHEL 8 / CentOS 8 で MariaDB Package Repository を設定



---------------------------------------------------------------------------------------------------------------
# dnf list maria*          #インストール状況確認
# dnf info mariadb-server mariadb mariadb-devel
# dnf install -y mariadb-server mariadb mariadb-devel
# dnf list installed | grep mariadb
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb

8/3下記問題は発生しなかった。
---------------------------------------------------------------------------------------------------------------
エラーで起動できない。
[Warning] Could not increase number of max_open_files to more than 1024 (request: 4206)
[Warning] Changed limits: max_open_files: 1024  max_connections: 151 (was 151)  table_cache: 421 (was 2000)

#  mkdir /etc/systemd/system/mariadb.service.d
# vi /etc/systemd/system/mariadb.service.d/limits.conf
[Service]
LimitNOFILE=5000

上記エラーは解消されたが、起動しない。
4月 17 16:50:30 libra.jp mysql-prepare-db-dir[12739]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
 4月 17 16:50:30 libra.jp mysql-prepare-db-dir[12739]: If this is not the case, make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.
 4月 17 16:50:30 libra.jp mysqld[12779]: 2020-04-17 16:50:30 0 [Note] /usr/libexec/mysqld (mysqld 10.3.17-MariaDB) starting as process 12779 ...
 4月 17 16:50:32 libra.jp systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
 4月 17 16:50:32 libra.jp systemd[1]: mariadb.service: Failed with result 'exit-code'.
 4月 17 16:50:32 libra.jp systemd[1]: Failed to start MariaDB 10.3 database server.
-- Subject: Unit mariadb.service has failed

PCの再起動で解消????
-------------------------------------------------------------------------------------------------------------------
$ mysql -u root
>  select user, host from mysql.user;
> create user admin;
> grant all privileges on *.* to admin identified by 'password';
> alter user root@localhost identified by 'password';
or
> create user admin@libre.com identified by 'password';
※version 10.3.17  20200804追記





【CentOS7 にMariaDBの最新版をインストール】

# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
※プロキシ環境で上手く行かなかったので、wgetでダウンロードした後にbashで実行。

# yum remove mysql*
# yum remove Mariadb*

# yum install MariaDB

# vi  /etc/my.cnf.d/server.cnf 
[mariadb]
character-set-server=utf8
[mariadb-10.5]
character-set-server=utf8

# systemctl enable mariadb
# systemctl start mariadb

# mysql -u root
MariaDB [(none)]>  alter user root@localhost identified by 'password';
MariaDB [(none)]>  create user admin@localhost identified by 'password';
MariaDB [(none)]> grant all privileges on *.* to admin@localhost  with grant option;
MariaDB [(none)]> alter user admin@localhost identified by 'password';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit
# mysql -u admin -p
MariaDB [(none)]> create database testdb;
MariaDB [(none)]> quit

【※】
# systemctl start mariadb
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
# journalctl -xe
[ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
Failed to start MariaDB 10.5.8 database server.

→データベースのアップグレードが必要そう。
  今回は、面倒臭いので、
# systemctl stop mysqld
# yum remove MariaDB*
# yum remove mysql*
# mv /usr/lib/mysql /usr/lib/mysql.old 
してから、mariadbを再インストール



2020年4月16日木曜日

CenOS7 oracle 11g インストール

下記からダウンロード1

https://www.oracle.com/technetwork/jp/indexes/downloads/index.html

1239269270  4月 15 00:19 linux.x64_11gR2_database_1of2.zip
1111416131  4月 15 00:22 linux.x64_11gR2_database_2of2.zip

# useradd oracle
# passwd oracle
# usermod -aG wheel oracle
# yum --enablerepo=base install gcc libaio-devel compat-libstdc++-33 elfutils-libelf-devel mksh gcc-c++ libstc++-devel
# su - oracle
$ mkdir Inst
$ cd Inst
$ unzip linux.x64_11gR2_database_1of2.zip
$ unzip linux.x64_11gR2_database_2of2.zip
$ cd database
$ export LANG=C
$ sudo firewall-cmd --add-port=1521/tcp --zone=public --permanent
$ sudo firewall-cmd --reload
$ ./runInstaller
mail address -> blank -> next->yes
Create and configure a database
Server Class
Single instance database installation
Typical install
/home/oracle/app/oracle
/home/oracle/app/oracle/product/11.2.0/dbhome_1
File System
/home/oracle/app/oracle/oradata
Enterprisee Edition(4.29GB)
oracle
orcl
OraclePassword01
OraclePassword01
/home/oracle/app/oraInventory
oracle
Fix & ChekAgain
OK
スワップ領域とバージョンが新しすぎてエラー、取り敢えずignore ALLで先に進んでみる。

エラーが発生してSTOP
NFO: gcc -o ctxhx -m64 -L/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -L/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib/ -L/home/oracle/app/oracle/product/11.2.0/dbhome_1/lib/stubs/  /home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ctxhx.o -L/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ -lm -lsc_fa -lsc_ex -lsc_da -lsc_ca -lz  -lctxhx -Wl,-rpath,/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -
INFO: lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11  `cat /home/oracle/app/oracle/product/11.2.0/dbhome_1/lib/sysliblist`

INFO: //usr/lib64/libstdc++.so.5: undefined reference to `memcpy@GLIBC_2.14'
collect2: error: ld returned 1 exit status

INFO: make: *** [ctxhx] Error 1

INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'install' of makefile '/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'. See '/home/oracle/app/oraInventory/logs/installActions2020-04-16_11-29-15AM.log' for details.
Exception Severity: 1










2020年4月14日火曜日

ssh 無通信で切断されてしまう。ssh IP制限

# vi /etc/ssh/sshd_config
# add by takahab
ClientAliveInterval 120
ClientAliveCountMax 3


sshで繋らなくなった。
kex_exchange_identification: read: Connection reset by peer


# vi /etc/hosts.allow
sshd: 127.0.0.1
sshd: xxx.xxx.xxx.xxx
sshd: .jp                              ←これを追加で解決


【ssh IP制限】
# cat /var/log/secure* | grep 'Accepted publickey' | awk '{ print $11}' | sort | uniq -c | sort -r
# cat /var/log/secure* | grep 'Invalid user' | awk '{ print $10}' | sort | uniq -c | sort -r
# cat /var/log/secure* | grep 'refused connect' | awk '{ print $10}' | sort | uniq -c | sort -r

# cat /var/log/secure* |grep 'Invalid user' | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH) }'|uniq -c |sort

# for i in `cat /var/log/secure* |grep from | awk 'match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0, RSTART, RLENGTH) }'|uniq -c |sort` ;do whois $i |grep country; done|sort |uniq -c

#  whois  [IP address] | grep country

# cat /var/log/ssh/sshd.log | grep 'Accepted publickey' | awk '{ print $7 $9}' | sort | uniq -c | sort -r
# cat /var/log/ssh/sshd.log | grep 'Invalid user' | awk '{ print $7}' | sort | uniq -c | sort -r
# cat /var/log/ssh/sshd.log | grep 'refused connect' | awk '{ print $7}' | sort | uniq -c | sort -r


# /etc/hosts.deny
sshd : all
or
ALL : ALL

# /etc/hosts.allow
sshd : 202.229.102.0/255.255.255.0
sshd : 202.229.102.

sshd : 218.221.32.0/255.224..0
sshd : 218.221.32.

sshd : 180.0.0.0/255.192.0.0

sshd: 202.229.102.0/255.255.255.0,218.221.32.0/255.255.224.0,180.0.0.0/255.192.0.0

sshd: *.casio.co.jp, *.cxdnext.co.jp \
            *.so-net.ne.jp

 

2020年4月3日金曜日

ssh port fowarding & xfreerdp

【ローカルフォワード】
$ ssh -p 3128 "Remote IP" -L 8080:"target IP":80 -g -f -N
Client→(8080)Local⇒(3128)Remote(中継)→(80)Target
※ -g 外部アクセス許可(許可しない場合は、localhostのみ)
   -f バックグランドで実行
   -N 接続先でコマンドを実行しない。

例) ssh -p 3128  192.168.10.10 -L 8080:192.168.10.11:80 -g
     http://localhost:8080/

【リモートフォワード】
$ ssh  "Remote IP" -R 8080:"target IP":80
Local ⇒(22)Remote↓
Client→(8080)Remote(中継)→(80)Terget

例) ssh  192.168.10.10 -R 8080:192.168.10.11:80
     http://192.168.10.10:8080/

※ 外部アクセスを許す場合は、Remote serverで、
# vi /etc/ssh/sshd_config
GatewayPorts yes

例)
ssh -C -N -f -p 'Port No' -L port:IP address:port
-C:  圧縮
-N: コマンド実行無し
-f:バックグランド

【実例】
NOTE=’IPアドレス’
# if [  "$1" = "proxy" ]; then
    # echo "ローカルポート10080は、192.168.1.100:22を経由して、192.168.11.100:80に接続"
    # sshpass -p password ssh -C -N -f -p 22 192.168.1.100 -L  10080:192.168.11.100:80

elif [  "$1" = "win" ]; then
        echo  xfreerdp -u user -d local -p password -a 16  127.0.0.1:63389
        xfreerdp -u user -d local -p password -a 16 -g 1920x1080 127.0.0.1:63389

elif [  "$1" = "note" ]; then
        echo  xfreerdp -f -u user -d local -p password -a 16  $NOTE:3389
        xfreerdp  /u:user /d:local /p:password /bpp:16 /size:3840x2040 /f /v:$NOTE:3389  /kbd:0xE0010411 /kbd-lang:0x0411 /audio-mode:1 +fonts +clipboard

※ 全画面からの戻りは、[cntl+alt+return]

elif [  "$1" = "term" ]; then
        CMD="sh ~/go"
        echo $CMD
        gnome-terminal --geometry 100x65-0+0           -- bash -c "$CMD"
        gnome-terminal --geometry 100x65-200+0      -- bash -c "$CMD"
        gnome-terminal --geometry 100x65-400+0      -- bash -c "$CMD"

#       xwininfo     画面位置検知

elif [  "$1" = "x11" ]; then
#----------------------------X11 Forwarding-------------------------------------------------------
       echo "X11 forwarding server"
       sshpass -p password ssh -X -C -p 60022  xxx.xxx.xxx.xxx

elif [  "$1" = "scp" ]; then
       echo scp -P 60022  $2 user@xxxx.xxx.xxx.xxx:~/$2
       sshpass -p password scp -P 60022  $2 user@xxx.xxx.xxx.xxx:~/$2
else
       sshpass -p password ssh -p 60022 xxx.xxx.xxx.xxx

fi

2020年3月29日日曜日

Rocky linux 8にpostgres14をインストール

【Rocky linux9 Postgres clieant インストール 2024/1/10追記】
# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{centos})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf install libpq-devel
or
# dnf install postgresql15-devel


【2023/12/15追記】
■Postgres client インストール
# dnf install libpq-devel
# which pg_config
/usr/bin/pg_config

ERROR
 gcc: エラー: /usr/lib/rpm/redhat/redhat-hardened-cc1: そのようなファイルやディレクトリはありません
→dnf install redhat-rpm-config


【2023/04/20更新】
■Postgre client インストール(Django)
# dnf install postgresql14-devel
# find / -print |grep pg_config
/usr/pgsql-14/bin/pg_config
$ . ./env
$ PATH=/usr/pgsql-14/bin:$PATH;export PATH
$ pip3 install psycopg2
$ ./env freeze
$ vi Config/settings.py << __EOF__
DATABASES = { 
   'default': {
     'ENGINE'       :  'django.db.backends.postgresql_psycopg2',
     'NAME'           :  'office_pg',
     'USER'            :  'admin',
     'PASSWORD':  'casio00',
     'HOST'            :  '192.168.254.201',
     'PORT'            :  '5432',
   },
}  
$ psql -U postgres -h 192.168.254.201 

■Postgre Server インストール
$  cat /etc/redhat-release
Rocky Linux release 8.7 (Green Obsidian)
# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{centos})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf update
# dnf module list postgresql
# dnf module disable postgresql
# dnf search postgresql*-server
# dnf install -y postgresql14-server
# passwd postgres
# PGSETUP_INITDB_OPTIONS='--encoding=UTF-8 --no-locale'
# /usr/pgsql-14/bin/postgresql-14-setup initdb
# vi /var/lib/pgsql/14/data/pg_hba.conf 
#local   all             all                                   peer
local     all             all                                    trust
#host    all             all             127.0.0.1/32            ident
host all all 192.168.0.0/16                     password
# vi /var/lib/pgsql/14/data/postgresql.conf
listen_addresses = '*'          
port = 5432
# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# firewall-cmd --reload
# mkdir  -p /data/postgres/data
# chown  -R postgres:postgres /data/postgres/data
# semanage fcontext -a -t postgresql_db_t "/data/postgres(/.*)?"
# grep -i postgresql /etc/selinux/targeted/contexts/files/file_contexts.local
# restorecon -R -v /data/postgres
# ls -lZR /data/postgres

(確認)
#  ls -l /var/lib/pgsql/14/data
 # vi /usr/lib/systemd/system/postgresql-14.service
#  grep -v -E "^#|^$" /var/lib/pgsql/14/data/pg_hba.conf
# grep listen_addresses /var/lib/pgsql/14/data/postgresql.conf
# ls -lZ /var/lib/pgsql
 drwx------. 4 postgres postgres system_u:object_r:postgresql_db_t:s0 51  4月 20 14:26 14

 
# systemctl start postgresql-14
# systemctl enable  postgresql-14

$ su - postgres

$ psql -U postgres
ALTER USER postgres PASSWORD 'password';

$ psql 
create user admin with password 'password' superuser;
create database ARCSDBMS owner admin;



-------------------------------------old----------------------------------------------------
# useradd admin
# su - postgres
$ postgres --version
postgres (PostgreSQL) 12.1
$ createuser admin
$ createdb testdb -O admin
$ psql  -c "select usename from pg_user;"
$ psql -l testdb
$ psql testdb
testdb=>\du
testdb=>\l
testdb=> create table test_table (no int, name text);
testdb=> insert into test_table (no,name) values (01,'CentOS');
testdb=> select * from test_table;
testdb=> drop table test_table;
testdb=>\dt
testdb=>\q
$ dropdb testdb
$ psql -l

【パスワード変更】
# vi /var/lib/pgsql/data/pg_hba.conf
local   all             all                                    peer/md5 → trust
# systemctl  restart postgresql
# su - postgres
$ psql -U postgres
postgres=# alter role postgres with password 'newpassword';

pg_hba.conf を戻す。







NEXTJS PWA化

$ cd frontend $ npm install @ducanh2912/next-pwa $ vi next.config.ts<<__EOF__ import withPWAInit from "@ducanh2912/next-pwa"...