2017년 3월 21일 화요일

MariaDB charset UTF8 설정

MariaDB charset UTF8 설정


CentOS 7.x 버전에 APM 을 설치했더니 MySQL 디폴트 문자셋이 latin1 으로 되어있네요.

/etc/my.cnf 를 수정해주면 됩니다.

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

init_connect='set names utf8'
character-set-server=utf8

위 두줄은 추가해주고

# systemctl restart mariadb

2017년 3월 20일 월요일

How to fix, Replication slave server Error Duplicate entry

How to fix, Replication slave server Error Duplicate entry


Error 'Duplicate entry for key 'PRIMARY'' on query.

MySQL Replication 슬래이브 서버에서

show slave status 로 상태 확인시 위와 같은 에러가 있으면 더 이상 DB 데이터 싱크는 되지 않습니다.

아무튼 이런 경우에는 my.cnf 에 아래 옵션을 넣어주면 됩니다.

[mysqld]
server-id=2
slave-skip-errors=1062

1062 에러가 primary key 데이터 중복시 나는 에러입니다.

auto_increment 가 되어 있는데도 불구 하고 에러가 나는게 조금 이상하긴 하네요.

2017년 3월 15일 수요일

LSYNCD Error Terminating since out of inotify watches

LSYNCD Error Terminating since out of inotify watches



lsyncd 로그 파일에 아래와 같은 에러가 있다면 동기화 하려는 파일의 수가 많을 때 발생합니다.


Wed Mar 15 14:05:54 2017 Normal: --- TERM signal, fading ---
Wed Mar 15 14:05:56 2017 Error: Terminating since out of inotify watches.
Consider increasing /proc/sys/fs/inotify/max_user_watches


동기화 시키려는 파일이 많은 때는 위와 같은 에러가 발생합니다.

이럴때는 max_user_watches 수를 증가시켜 주면 됩니다.

먼저 얼마로 되어 있는지 확인해 보고 수치를 증가시켜 줍시다.

# cat /proc/sys/fs/inotify/max_user_watches
8192

# echo 65536 > /proc/sys/fs/inotify/max_user_watches


이제 lsyncd 를 재시작 하면 됩니다.

ssh-copy-id Pseudo-terminal will not be allocated because stdin is not a terminal

ssh-copy-id Pseudo-terminal will not be allocated because stdin is not a terminal



# ssh-copy-id root@192.168.1.2
Pseudo-terminal will not be allocated because stdin is not a terminal.
ssh: Could not resolve hostname umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys && (test -x /sbin/restorec: Name or service not known

위와 같이 복사가 안 될 때는 scp 명령어로 복사하여 주면 됩니다.

# scp ./.ssh/id_rsa.pub root@192.168.1.2:~/.ssh/authorized_keys

authorized_keys 에 다른 서버의 키 값이 있다면 복사가 아닌 cat 으로 덧붙어 주어야 합니다.

# cat ./.ssh/id_rsa.pub | ssh root@192.168.1.2 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"


2017년 3월 10일 금요일

LINUX fdisk error

LINUX fdisk error


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 5: Input/output error.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

디스크 상태가 이상해서 파티션을 다시 잡을려고 하니 위와 같이 에러가 발생한다.

아무래도 디스크가 맛이 갔나보다.

2017년 3월 9일 목요일

MySQL omtimize table 중에 process 를 kill 하면

MySQL omtimize table 중에 process 를 kill 하면



테이블 파일이 깨집니다.


optimize table example_table;

이렇게 쿼리를 실행한 후에 시간이 너무 오래 걸려서

show processlist; 로 해당 ID 를 kill id값; 했더니 아래처럼 나오네요~

#144 - Table './example/example_table' is marked as crashed and last (automatic?) repair failed

2017년 3월 3일 금요일

MySQL 쿼리 실행시간 제한은 없는 듯 하다

MySQL 쿼리 실행시간 제한은 없는 듯 하다


잘 못 실행된 쿼리로 인해 DB 서버가 먹통이 되는 현상을 경험했다면,
응급 조치로는 show processlist 로 확인하고 해당 id 를 kill 해주는 방법이 있습니다.

php 와 같이 사용하는 경우에는 php 에서 실행시간을 제한(max_execution_time 설정값 또는 set_time_limit 함수이용)을 걸 수가 있지만, mysql 환경설정에는 아무리 구글링을 해봐도 찾지를 못하겠네요.

현재로써는 cron 을 이용해서 쉘스크립트로 프로세스를 체크해서 Time 이 일정 수치 이상된 프로세스 id 는 kill 을 해주도록 해주는 방법이 최선인 듯 합니다.

MariaDB [mysql]> show processlist;
+----+------+-----------+-------+---------+------+------------+-------------------+----------+
| Id | User | Host      | db    | Command | Time | State      | Info              | Progress |
+----+------+-----------+-------+---------+------+------------+-------------------+----------+
|  8 | root | localhost | mysql | Query   |    0 | NULL       | show processlist  |    0.000 |
| 15 | root | localhost | NULL  | Query   |    4 | User sleep | select sleep(300) |    0.000 |
+----+------+-----------+-------+---------+------+------------+-------------------+----------+
2 rows in set (0.00 sec)

MariaDB [mysql]> kill 15;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> show processlist;
+----+------+-----------+-------+---------+------+-------+------------------+----------+
| Id | User | Host      | db    | Command | Time | State | Info             | Progress |
+----+------+-----------+-------+---------+------+-------+------------------+----------+
|  8 | root | localhost | mysql | Query   |    0 | NULL  | show processlist |    0.000 |
+----+------+-----------+-------+---------+------+-------+------------------+----------+
1 row in set (0.00 sec)

MariaDB [mysql]>