2014年4月30日水曜日
scp
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# yum install /lib/ld-linux.so.2
# yum install libncursesw.so.5
================================================================
= SCP Command S -> T send
================================================================
[root@sfzod62 tmp]■# scp sfzod62:/tmp/sfzod62.txt sfzoa62:/tmp/sfzod62.txt
root@sfzod62's password:
root@sfzoa62's password:
sfzod62.txt 100% 0 0.0KB/s 00:00
Connection to sfzod62 closed.
[root@sfzod62 tmp]#
================================================================
[root@sfzod62 tmp
================================================================
= SCP Command S -> T receive
■scp sfzoa62:/tmp/sfzoa62.txt sfzod62:/tmp/sfzoa62.txt
root@sfzod62's password:
root@sfzoa62's password:
sfzod62.txt 100% 0 0.0KB/s 00:00
Connection to sfzod62 closed.
[root@sfzod62 tmp]#
-------------------------------------------------------------------
PostgreSQLのログ アーカイブ ジャーナル フルになったら
■history
history -c
■プロファイル
[root@sfzoa62 logrotate.d]# su - draftmaster
[draftmaster@sfzoa62 ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
[draftmaster@sfzoa62 ~]$
■アプリからDB接続
■Postgres9.3 JDBC Driver CEntOS6.4 Tomcat7
■テーブルスペースのサイズと、空き容量を確認する
コンプレスする方法は?
■アーカイブ指定する方法は?
■バックアップの指定は?
\\\\
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DB ERROR
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
VCDS
[root@sfzod62 ~]#
[root@sfzod62 ~]# cat /var/lib/pgsql/9.3/data/postgresql.conf | grep archi
#wal_level = minimal # minimal, archive, or hot_standby
#archive_mode = off # allows archiving to be done
#archive_command = '' # command to use to archive a logfile segment
# placeholders: %p = path of file to archive
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0 # force a logfile segment switch after this
#max_standby_archive_delay = 30s # max delay before canceling queries
# when reading WAL from archive;
[root@sfzod62 ~]#
ーーーーーーーーーーーーーーーーーーーーーーーー
[root@sfzoa62 tomcat]# pwd
/data/apdata/log/tomcat
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/var/lib/pgsql/9.3/data/pg_log
■# yum install uuid
*********************************************************************************
*
* http://www.unixmen.com/install-postgresql-9-3-centos-6-56-4/
*
*********************************************************************************
■# yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm - See more at: http://
www.unixmen.com/install-postgresql-9-3-centos-6-56-4/#sthash.xC361Pfu.dpuf
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
Setting up Install Process
pgdg-redhat93-9.3-1.noarch.rpm | 5.1 kB 00:00
Examining /var/tmp/yum-root-qjTmbu/pgdg-redhat93-9.3-1.noarch.rpm: pgdg-redhat93-9.3-1.noarch
Marking /var/tmp/yum-root-qjTmbu/pgdg-redhat93-9.3-1.noarch.rpm to be installed
No package See available.
No package more available.
No package at: available.
No package http://www.unixmen.com/install-postgresql-9-3-centos-6-56-4/#sthash.xC361Pfu.dpuf available.
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat93.noarch 0:9.3-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
pgdg-redhat93 noarch 9.3-1 /pgdg-redhat93-9.3-1.noarch 2.1 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total size: 2.1 k
Installed size: 2.1 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : pgdg-redhat93-9.3-1.noarch 1/1
Verifying : pgdg-redhat93-9.3-1.noarch 1/1
Installed:
pgdg-redhat93.noarch 0:9.3-1
Complete!
*********************************************************************************
■# yum install postgresql93-server postgresql93-contrib - See more at: http://www.unixmen.com/install-postgresql-9-3-
centos-6-56-4/#sthash.xC361Pfu.dpuf
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.jaist.ac.jp
* extras: ftp.jaist.ac.jp
* updates: ftp.jaist.ac.jp
Setting up Install Process
No package See available.
No package more available.
No package at: available.
No package http://www.unixmen.com/install-postgresql-9-3-centos-6-56-4/#sthash.xC361Pfu.dpuf available.
Resolving Dependencies
--> Running transaction check
---> Package postgresql93-contrib.x86_64 0:9.3.4-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql93 = 9.3.4 for package: postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64
---> Package postgresql93-server.x86_64 0:9.3.4-1PGDG.rhel6 will be installed
--> Running transaction check
---> Package postgresql93.x86_64 0:9.3.4-1PGDG.rhel6 will be installed
---> Package postgresql93-libs.x86_64 0:9.3.4-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
postgresql93-contrib x86_64 9.3.4-1PGDG.rhel6 pgdg93 483 k
postgresql93-server x86_64 9.3.4-1PGDG.rhel6 pgdg93 4.1 M
Installing for dependencies:
postgresql93 x86_64 9.3.4-1PGDG.rhel6 pgdg93 1.0 M
postgresql93-libs x86_64 9.3.4-1PGDG.rhel6 pgdg93 190 k
Transaction Summary
================================================================================
Install 4 Package(s)
Total download size: 5.7 M
Installed size: 23 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): postgresql93-9.3.4-1PGDG.rhel6.x86_64.rpm | 1.0 MB 00:05
(2/4): postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64.rpm | 483 kB 00:01
(3/4): postgresql93-libs-9.3.4-1PGDG.rhel6.x86_64.rpm | 190 kB 00:00
(4/4): postgresql93-server-9.3.4-1PGDG.rhel6.x86_64.rpm | 4.1 MB 00:06
--------------------------------------------------------------------------------
Total 402 kB/s | 5.7 MB 00:14
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : postgresql93-libs-9.3.4-1PGDG.rhel6.x86_64 1/4
Installing : postgresql93-9.3.4-1PGDG.rhel6.x86_64 2/4
Installing : postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64 3/4
Installing : postgresql93-server-9.3.4-1PGDG.rhel6.x86_64 4/4
Verifying : postgresql93-libs-9.3.4-1PGDG.rhel6.x86_64 1/4
Verifying : postgresql93-contrib-9.3.4-1PGDG.rhel6.x86_64 2/4
Verifying : postgresql93-server-9.3.4-1PGDG.rhel6.x86_64 3/4
Verifying : postgresql93-9.3.4-1PGDG.rhel6.x86_64 4/4
Installed:
postgresql93-contrib.x86_64 0:9.3.4-1PGDG.rhel6
postgresql93-server.x86_64 0:9.3.4-1PGDG.rhel6
Dependency Installed:
postgresql93.x86_64 0:9.3.4-1PGDG.rhel6
postgresql93-libs.x86_64 0:9.3.4-1PGDG.rhel6
Complete!
#
**************************************************************************
* status/ stop / start
**************************************************************************
■# /etc/rc.d/init.d/postgresql-9.3 status
postgresql-9.3 (pid 7335) を実行中...
■# /etc/rc.d/init.d/postgresql-9.3 stop
postgresql-9.3 サービスを停止中: [ OK ]
■# /etc/rc.d/init.d/postgresql-9.3 start
postgresql-9.3 サービスを開始中: [ OK ]
#
**************************************************************************
* Initialize the database:
**************************************************************************
■# service postgresql-9.3 initdb
データベースを初期化中: [ OK ]
#
**************************************************************************
* Make it bootable on start:
**************************************************************************
■# chkconfig postgresql-9.3 on
#
**************************************************************************
* Allow remote access from all:
**************************************************************************
■# vi /var/lib/pgsql/9.3/data/postgresql.conf
listen_addresses = '*'
■# vi /var/lib/pgsql/9.3/data/pg_hba.conf
host all all 0.0.0.0/0 md5
■# /etc/init.d/postgresql-9.3 reload
**************************************************************************
* Start the server, check if its running and listening:
**************************************************************************
■# /etc/init.d/postgresql-9.3 start
postgresql-9.3 サービスを開始中: [ OK ]
■# netstat -an | grep 543
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 ::1:5432 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 29677 /tmp/.s.PGSQL.5432
unix 3 [ ] STREAM CONNECTED 15543
**************************************************************************
* Allow Postgresql in The firewall
**************************************************************************
■# vi /etc/sysconfig/iptables
Add line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
and now restart iptables
■# service iptables restart
iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ]
iptables: ファイアウォールルールを消去中: [ OK ]
iptables: モジュールを取り外し中: [ OK ]
iptables: ファイアウォールルールを適用中: [ OK ]
#
**************************************************************************
* Create user and database in Postgresql
**************************************************************************
■# su - postgres
-bash-4.1$
■$ createuser user1
■$ createdb db1
- Set password and Grant access to the database db1 for user1: --
$ psql
psql (9.3.4)
postgres=# Type "help" for help
postgres=#alter user user1 with encrypted password 'user1'
postgres-# ALTER ROLE
postgres-# Type "help" for help
postgres=#grant all privileges on database db1 to user1
postgres-# GRANT
postgres-#
******************************************************************************
* http://lets.postgresql.jp/documents/tutorial/centos/2
******************************************************************************
■# id postgres
uid=26(postgres) gid=26(postgres) 所属グループ=26(postgres)
#
■# which psql
/usr/bin/psql
■#/etc/init.d/postgresql-9.3 start
■# psql
***********************************************************************
* Retreive DataBase List
***********************************************************************
■ -bash-4.1$ psql -l
List of database
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+-----------+------------+---------------+---------------+------------
db1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
-bash-4.1$
***********************************************************************
* Connect DataBase
***********************************************************************
■-bash-4.1$ psql db1
psql (9.3.4)
Type "help" for help.
db1=# select version();
version
--------------------------------------------------------------------------------------------------------------
PostgreSQL 9.3.4 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
(1 row)
■db1=#\q
bash-4.1$
***********************************************************************
* TABLE Define
***********************************************************************
■db1=# CREATE TABLE cus (id INTEGER PRIMARY KEY NOT NULL,name TEXT NOT NULL,cretime TIMESTAMP NOT NULL);
CREATE TABLE
■db1-# \d
List of relations
Schema | Name | Type | Owner
---------+-------+--------+----------
public | cus | table | postgres
(1 row)
db1-#
■db1-# \db+
List of tablespaces
Name | Owner | Location | Access privileges | Description
------------+----------+----------+-------------------+-------------
pg_default | postgres | | |
pg_global | postgres | | |
(2 rows)
db1-#
■db1=# \d cus
Table "public.cus"
Column | Type | Modifiers
----------+----------------------------------+-----------
id | integer | not null
name | text | not null
cretime | timestamp without time zone | not null
Indexes:
"cus_pkey" PRIMARY KEY, btree (id)
db1=#
***********************************************************************
* TABLE DATA INSERT
***********************************************************************
■db1=# BEGIN TRANSACTION;
BEGIN
db1=# INSERT INTO cus VALUES( 1,'Manda',current_timestamp);
INSERT 0 1
db1=# COMMIT;
COMMIT
■db1=# SELECT * FROM cus;
id | name | cretime
-----+--------+----------------------000------
1 | Manda | 2014-04-28 10:59:38.204301
(1 row)
db1=#
***********************************************************************
* psql exit
***********************************************************************
■db1-# \q
bash-4.1$
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ sfzod62 logrotate
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
====================================================================================
= logrotate
= /etc/cron.daily/logrotate
= /usr/sbin/logrotate
= /etc/logrotate.conf
= /etc/logrotate.d/(postgres)
= /var/lib/logrotate.status
====================================================================================
■# cat /etc/logrotate.d/postgres
/var/lib/pgsql/9.3/data/pg_log/*.log {
copytruncate
daily
size 1k
missingok
compress
rotate 2
olddir /var/lib/pgsql/9.3/data/pg_log/dirrotate
# create 0600 postgres postgres
}
#
====================================================================================
■# cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate -f /etc/logrotate.conf >/dev/null 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
====================================================================================
■# vi /var/lib/pgsql/9.3/data/postgresql.conf
.......
log_filename = 'postgresql.log'
........
■# /etc/init.d/postgresql-9.3 reload
====================================================================================
■# logrotate -f /etc/logrotate.d/postgres
# ls -ltr /var/lib/pgsql/9.3/data/pg_log
-rw------- 1 postgres postgres 0 5月 2 07:01 2014 postgresql.log
drwxr-xr-x 2 root root 4096 5月 2 07:01 2014 dirrotate
#
# ls -ltr /var/lib/pgsql/9.3/data/pg_log/dirrotate
-rw------- 1 postgres postgres 20 5月 2 07:01 2014 postgresql.log.1.gz
-rw------- 1 postgres postgres 20 5月 2 07:00 2014 postgresql.log.2.gz
#
====================================================================================
■# /usr/sbin/logrotate -f /etc/logrotate.conf >/dev/null 2>&1
# /var/lib/logrotate.status
logrotate state -- version 2
"/var/lib/pgsql/9.3/data/pg_log/postgresql.log"
====================================================================================
■# /etc/cron.daily/logrotate
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ sfzod62 tmpwatch
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
■# cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
#
====================================================================================
= tmpwatch cron 4day ago delete
====================================================================================
■# vi /etc/cron.dailytmpwatch
/usr/sbin/tmpwatch "$flags" 3d /var/lib/pgsql/9.3/data/pg_log/
■# /etc/cron.dailytmpwatch/tmpwatch
# ls -ltr /var/lib/pgsql/9.3/data/pg_log/*.log*
-rw------- 1 postgres postgres 0 4月 29 00:00 2014 /var/lib/pgsql/9.3/data/pg_log/postgresql-Tue.log
-rw------- 1 postgres postgres 0 4月 29 01:27 2014 /var/lib/pgsql/9.3/data/pg_log/postgresql-Sat.log
#