2024年6月28日金曜日

オラクル リードオンリーユーザ作成 (oracle readonly user)

alter pluggable database arcsdbms open;
alter session set container=arcsdbms;
create user readonly_user identified by xxxx00;
grant connect to readonly_user;
grant create session to readonly_user; 
grant select any table to readonly_user;



SELECT
*
FROM
ARCSDBSS.SSR002
WHERE
GCODE = '101'
AND CCODE = '4397'
AND SCODE = '0018'
AND RCODE = '7716610016038'
ORDER BY rDATE DESC

SELECT
MAX(s2.rdate),gcode,ccode,scode,rcode
FROM
ssr002 s2
WHERE
s2.GCODE = '101'
AND s2.CCODE = '4397'
AND s2.SCODE = '0018'
AND s2.RCODE = '7716610016038'
GROUP BY
s2.gcode, s2.ccode, s2.scode, s2.rcode

2024年6月26日水曜日

Rocky linux9.4 最小インストール

■OSインストール
① root パスワード
② ユーザ作成
③ ソフトウェア選択→最小限のインストール
④インストール先→ローカル標準ディスク(自動構成)
⑤ ネットワークとホスト名 (ホスト名、IPv4設定)

■OS設定
# vi /etc/yum.conf __EOF__
proxy=http://10.0.19.2:3128
__EOF__

# vi /etc/profile.d/proxy.sh
PROXY="http://10.0.12.2:3128"
export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export https_proxy=$PROXY
export HTTPS_PROXY=$PROXY
__EOF__
# source /etc/profile

# dnf update
#timedatectl set-timezone Asia/Tokyo
# localectl set-locale LANG=ja_JP.utf8

# nmcli general hostname zabbix70
# nmcli c add type ethernet ifname enp1s0 con-name "private_mng_1a
# nmcli c mod private_mng_1a ipv4.address 10.0.19.119/24
# nmcli c mod private_mng_1a ipv4.method manual
# nmcli c mod private_mng_1a connection.autoconnect yes
# nmcli c mod private_mng_1a ipv4.gateway 10.0.19.2
# nmcli c up  private_mng_1a

# dnf clean all
# dnf update
# dnf install net-tools

■zabbix
vi /etc/yum.repos.d/epel.repo __EOF__
[epel]
...
excludepkgs=zabbix*
__EOF__

dnf install zabbix-web-japanese                         # zabbix文字化け 対応
 
【IPA-FONTS】
wget https://moji.or.jp/wp-content/ipafont/IPAexfont/IPAexfont00401.zip
wget  https://moji.or.jp/wp-content/ipafont/IPAexfont/ipaexm00401.zip
wget  https://moji.or.jp/wp-content/ipafont/IPAexfont/ipaexg00401.zip
unzip  IPAexfont00401.zip  -d /usr/share/fonts
unzip ipaexm00401.zip       -d /usr/share/fonts
unzip ipaexg00401.zip        -d  /usr/share/fonts
 fc-cache -fv


【postgres15】
# dnf update --refresh
# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# dnf  -y install postgresql15-server
# /usr/pgsql-15/bin/postgresql-15-setup initdb
# systemctl start postgresql-15
# systemctl enable postgresql-15
# systemctl status postgresql-15
# passwd postgres

# passwd postgres
# su - postgres
$ psql -V
psql (PostgreSQL) 15.5
$ psql
alter user postgres with password 'password';
exit
$  vi /var/lib/pgsql/15/data/pg_hba.conf 
#local   all             all              peer
#host    all             all             127.0.0.1/32            scram-sha-256
local     all             all              trust
host      all             all             10.0.0.0/16             password
$ vi /var/lib/pgsql/15/data/postgresql.conf 
listen_addresses = '*'          
port = 5432 
max_connections = 100 
log_timezone = 'Asia/Tokyo'
timezone = 'Asia/Tokyo'
lc_messages = 'ja_JP.utf8'                    # locale for system error message
lc_monetary = 'ja_JP.utf8'                    # locale for monetary formatting
lc_numeric = 'ja_JP.utf8'                       # locale for number formatting
lc_time = 'ja_JP.utf8'

# systemctl restart postgresql-15
# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# firewall-cmd --add-service=postgresql --zone=public --permanent
# firewall-cmd --reload

【zabbix】
# rpm -Uvh https://repo.zabbix.com/zabbix/7.0/alma/9/x86_64/zabbix-release-7.0-2.el9.noarch.rpm
# dnf clean all
# dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2
# sudo -u postgres createuser --pwprompt zabbix
# sudo -u postgres createdb -O zabbix zabbix
# zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix
# vi /etc/zabbix/zabbix_server.conf  <<__EOF__
DBPassword=password
__EOF__

# systemctl restart zabbix-server zabbix-agent2 httpd php-fpm
# systemctl enable zabbix-server zabbix-agent2 httpd php-fpm

# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-port=10050/tcp --zone=public --permanent
# firewall-cmd --add-port=10051/tcp --zone=public --permanent
# firewall-cmd --reload

【初期デフォルト】
URL localhost/zabbix
User Admin
PW   zabbix


【postgres監視】    DB監視   ポストグレス監視

# mkdir -m 700   /var/lib/zabbix
# chown zabbix:  /var/lib/zabbix

$ PGHOST=10.0.18.101
$ echo "CREATE USER zbx_monitor WITH PASSWORD '<PASSWORD>' INHERIT" | psql -h $PGHOST -U postgres
$ echo "GRANT pg_monitor TO zbx_monitor" | psql -h $PGHOST -U postgres

GRANT CONNECT ON DATABASE arcsdbms TO zbx_monitor;
GRANT CONNECT ON DATABASE workbase TO zbx_monitor;
GRANT CONNECT ON DATABASE ezservice TO zbx_monitor;

 # vi /var/lib/pgsql/15/data/pg_hba.conf 
host       all        zbx_monitor     localhost               trust
host       all        zbx_monitor     127.0.0.1/32            md5
host       all        zbx_monitor     ::1/128                 scram-sha-256

$ git clone https://git.zabbix.com/scm/zbx/zabbix.git --depth 1
# mkdir -p /var/lib/zabbix/postgresql
# cp -pr zabbix/templates/db/postgresql/postgresql /var/lib/zabbix/postgresql
# chown -R zabbix: /var/lib/zabbix/postgresql

# cp -p zabbix/templates/db/postgresql/template_db_postgresql.conf /etc/zabbix/zabbix_agent2.d/
# chown root: /etc/zabbix/zabbix_agent2.d/template_db_postgresql.conf
# chmod 644 /etc/zabbix/zabbix_agent2.d/template_db_postgresql.conf

# vi /var/lib/zabbix/.pgpass <<__EOF__
*:5432:*:zbx_monitor:<PASSWORD>
__EOF__

chown zabbix: /var/lib/zabbix/.pgpass
chmod 600 /var/lib/zabbix/.pgpass

tennplate修正。
① Postgres by Zabbix agentをコピー 
② {$PG.HOST}
    {$PG_PASSWORD}

※ Postgres by zabbix agent2テンプレートは使用できなかった。
{$PG_CONSTRING} がlocalhost以外エラーになる。
 
# systemctl restart zabbix-agent2
※ template は agent, エージェントはagent2でも問題なかった。




【オラクル監視】
Rocky linux9.4 / oracle19c / zabbix7.0

# dnf install libnsl
# rpm -ivh oracle-instantclient19.20-basic-19.20.0.0.0-1.x86_64.rpm

# vi /etc/profile.d/oracle.sh
export LD_LIBRARY_PATH=/usr/lib/oracle/19.20/client64/lib:$LD_LIBRARY_PATH
# .  /etc/profile
# vi /etc/sysconfig/httpd
LD_LIBRARY_PATH=/usr/lib/oracle/19.20/client64/lib/:$LD_LIBRARY_PATH
# vi /etc/ld.so.conf.d/oracle-instantclient.conf
/usr/lib/oracle/19.20/client64/lib
# ldconfig
# ldconfig  -p |grep libclntsh

# mkdir /etc/systemd/system/zabbix-agent2.service.d
#  vi /etc/systemd/system/zabbix-agent2.service.d/limit.conf
# cat /etc/systemd/system/zabbix-agent2.service.d/limit.conf
[Service]
LimitNOFILE=65536

# systemctl daemon-reload
# systemctl restart  zabbix-agent2

create pluggable database zabbix admin user zbx_admin identified by "system" file_name_convert=( 'ORCLCDB','ZABBIX');
alter pluggable database zabbix open;
alter pluggable database all save state;
alter session set container=zabbix;

To create Oracle user with required privileges, run:
CREATE USER zbx_monitor IDENTIFIED BY  "zbx%xxxxxx%";
-- Grant access to the zbx_monitor user.

grant connect, create session to zbx_monitor;
grant select any dictionary to zbx_monitor;
grant select on dba_tablespace_usage_metrics to zbx_monitor;
grant select on dba_tablespaces to zbx_monitor;
grant select on dba_users to zbx_monitor;
grant select on sys.dba_data_files to zbx_monitor;

grant select on v_$active_session_history to zbx_monitor;
grant select on v_$archive_dest to zbx_monitor;
grant select on v_$asm_diskgroup to zbx_monitor;
grant select on v_$database to zbx_monitor;
grant select on v_$datafile to zbx_monitor;
grant select on v_$event_name to zbx_monitor;
grant select on v_$instance to zbx_monitor;
grant select on v_$log to zbx_monitor;
grant select on v_$osstat to zbx_monitor;
grant select on v_$pgastat to zbx_monitor;
grant select on v_$process to zbx_monitor;
grant select on v_$recovery_file_dest to zbx_monitor;
grant select on v_$recovery_file_dest to zbx_monitor;
grant select on v_$restore_point to zbx_monitor;
grant select on v_$session to zbx_monitor;
grant select on v_$sgastat to zbx_monitor;
grant select on v_$sysmetric to zbx_monitor;
grant select on v_$system_event to zbx_monitor;
grant select on v_$system_parameter to zbx_monitor;
grant unlimited tablespace to zbx_monitor;
                   
create profile ZABBIX limit PASSWORD_LIFE_TIME unlimited;
alter user zbx_monitor profile ZABBIX;
alter profile ZABBIX limit PASSWORD_LIFE_TIME unlimited;
set linesize 500
col resource_name for a30
col resource_type for a20
col profile for a20
col limit for a20
select * from dba_profiles where profile='ZABBIX' and resource_name='PASSWORD_LIFE_TIME';

接続確認
$ vi   /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/tnsnames.ora << __EOF__
ZABBIX =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.18.211)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = zabbix.world)
    )
  )

__EOF__

export NLS_LANG=Japanese_Japan.AL32UTF8             
sqlplus zbx_monitor/password@zabbix

ホストマクロ設定(ホスト→マクロ→ホストマクロ)
{$ORACLE.CONNSTRING}   : tcp://localhost:1521
{$ORACLE.SERVICE}      : zabbix
{$ORACLE.PASSWORD}     : password
{$ORACLE.USER}         : zbx_monitor

# dnf install zabbix-get
$ zabbix_get -s oracle-host -k oracle.ping["{$ORACLE.CONNSTRING}","{$ORACLE.USER}","{$ORACLE.PASSWORD}","{$ORACLE.SERVICE}"]
zabbix_get -s 127.0.0.1 -k oracle.ping['tcp://10.0.18.211:1521','zbx_monitor','system','zabbix.world']
zabbix_get -s 127.0.0.1 -k oracle.instance.info['tcp://10.0.18.211:1521','zbx_monitor','system','zabbix.world']




2024年6月25日火曜日

oracle auditファイルの削除


【auditファイル削除】

SQL> DELETE FROM SYS.AUD$;
SQL> TRUNCATE TABLE SYS.AUD$;

ファイングレイン監査証跡削除
SQL> DELETE FROM SYS.FGA_LOG$;
SQL> TRUNCATE TABLE SYS.FGA_LOG$;


【共有プール開放】

SQL> ALTER SYSTEM FLUSH SHARED_POOL;
SQL> ALTER SYSTEM SET SHARED_POOL_SIZE =6G SCOPE = BOTH;         #上限設定
SQL> ALTER SYSTEM SET DB_CACHE_SIZE =4G  SCOPE = BOTH;    


  col bytes for 9,999,999,999,999
  select name, bytes
  from v\$sgastat where pool is null
  union all
  select pool, sum( bytes ) from v$sgastat
  where pool is not null
  group by pool ;


【SGAターゲットの設定】  ー動的に割り当て有効

SQL> SHOW PARAMETER SGA;

NAME      TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga      boolean FALSE
pre_page_sga      boolean FALSE
sga_max_size      big integer 12832M    →16G
sga_target      big integer 0

SQL> ALTER SYSTEM SET SGA_MAX_SIZE = 16G SCOPE = SPFILE;
SQL> ALTER SYSTEM SET SGA_TARGET = 8G SCOPE = BOTH;

SQL> SHUTDOWN IMMEDIATE;                                   -- SGA_MAX_SIZEを変えた場合。
SQL> STARTUP;

2024年6月12日水曜日

zabbix7 amazon linux2023 インストール postgres15

【postgres】 dnf -y install postgresql15-server postgresql15-server-devel postgresql-setup initdb passwd postgres vi `find / -name pg_hba.con...