Home > SQL Archive
SQL Archive
ミラーリングによるバックアップ
余っているPC其の一
CPU: Celelon2.80GHz
HDD: 60G
メモリ: 768MB
これを無理矢理有効活用するべく、メインサーバーのMySQLとフォルダをリアルタイムミラーリングによるバックアップ機として復活させてみました。
【MySQL編】
マスタ側(例:192.168.1.10)
MySQL設定ファイルに追加 [root@centos ~]# vi /etc/my.cnf [mysqld] log-bin server-id = 1 DBのバックアップ [root@centos ~]# cd /var/lib/mysql [root@centos ~]# tar cpf /var/tmp/mysql.tar . レプリケーション設定 [root@centos ~]# mysql -u root -p mysql> grant replication slave, replication client on *.* to repl@"192.168.1.20" identified by 'replpasswd'; mysql> flush privileges; mysql> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | mysqld-bin.000001 | 28363 | | | +-------------------+----------+--------------+------------------+ 1 row in set (0.01 sec) ↑メモる MySQL再起動 [root@centos ~]# /etc/init.d/mysqld restart
スレーブ側(例:192.168.1.20)
バックアップデータ展開 [root@linux ~]# cd /var/lib/mysql [root@linux ~]# rm -fr * [root@linux ~]# tar xpf /var/tmp/mysql.tar MySQL再起動 [root@linux ~]# /etc/init.d/mysqld restart MySQL設定ファイルに追加 [root@linux ~]# vi /etc/my.cnf [mysqld] server-id = 2 レプリケーション設定 [root@linux ~]# mysql -u root -p mysql> grant all privileges on wordpress.* to wordpress@localhost identified by 'wordpresspasswd'; ← WordPress用ユーザー追加 mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.1.10', -> MASTER_USER='repl', -> MASTER_PASSWORD='replpasswd', -> MASTER_LOG_FILE='mysqld-bin.000001', -> MASTER_LOG_POS=28363; mysql> start slave; MySQL再起動 [root@centos ~]# /etc/init.d/mysqld restart
【フォルダ編】
フォルダ編はリアルタイムミラーリングツール導入(lsyncd+rsyncd)をご覧ください。
これでメインサーバーのHDDが何時逝っても大丈夫になりました。ただ、ミラーリング用サーバーは常に電源を入れているわけではありませんが・・・
さて、余っているPCは残り2台となりました。
余っているPC其の二
CPU: Pentium4 2.40GHz
HDD: 160G
メモリ: 1GB
余っているPC其の三(ThinkPad T20)
CPU: PentiumIII 700MHz
HDD: 12G
メモリ: 128MB
ThinkPadにはCentOS4までしか入らないし、もう完全にゴミかなぁ
- Comments: 0
- Trackbacks: 0
【MySQL】ユーザー一覧・DB/テーブル一覧
- 2009-04-06 (月)
- SQL

ユーザー一覧 mysql> use mysql mysql> select host,user from user; DB一覧 mysql> show databases; テーブル一覧 mysql> show tables;
- Comments: 0
- Trackbacks: 0
【PostgreSQL】ユーザーのパスワード変更
[root@centos ~]# su - postgres -bash-3.2$ psql template1 template1=# select usename from pg_user; ←ユーザー名一覧 (template1=# select * from pg_shadow;) ← 〃 template1=# alter user user_name with password 'user_password'; template1=# \q -bash-3.2$ exit logout
- Comments: 0
- Trackbacks: 0
【PostgreSQL】アクセス制限
- 2009-04-02 (木)
- SQL

[root@centos ~]# su - postgres -bash-3.2$ vi /var/lib/pgsql/data/pg_hba.conf # TYPE DATABASE USER CIDR-ADDRESS METHOD local all postgres ident sameuser local all all md5 host all all 127.0.0.1/32 md5 -bash-3.2$ exit [root@centos ~]# /etc/rc.d/init.d/postgresql restart
- Comments: 0
- Trackbacks: 0
【PostgreSQL】データベースの所有者変更
- 2009-03-31 (火)
- SQL

DB名:testdb
所有者:postgres
↓
所有者:hogehoge
[root@centos ~]# su - postgres -bash-3.2$ psql template1 template1=# select usesysid from pg_user where usename = 'hogehoge'; usesysid ---------- 12345 (1 row) template1=# update pg_database set datdba = 12345 where datname = 'testdb';
- Comments: 0
- Trackbacks: 0
Home > SQL Archive