Debian(Jessie) 서버의 MySQL에 이상한 문제가 있습니다.
서버가 다시 시작되면 systemd는 mysqld를 시작하려고 시도하지만 실패합니다(포트 3306이 이미 사용된 것처럼 보이지만 왜 사용되는지는 알 수 없습니다).
그러나 몇 분 후에 서버에 SSH로 연결하여 실행하면 sudo systemctl start mysql
성공할 것입니다.
서버를 다시 시작할 때마다 문제가 재현될 수 있습니다.
이미 이 문제가 발생한 사람이 있습니까? 아니면 MySQL이 올바르게 시작되지 않는 원인이 무엇인지 추측하십니까? 재부팅 후 MySQL을 시작하기 전에 지연을 추가할 수 있지만 무슨 일이 일어나고 있는지 이해하고 싶고 실제로 문제가 해결될지 확신할 수 없습니다.
sudo systemctl status mysql -l
재부팅 후 결과는 다음과 같습니다 .
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: failed (Result: exit-code) since Fri 2017-09-01 21:54:44 CEST; 1min 41s ago
Process: 581 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
Sep 01 21:54:06 gimli systemd[1]: Starting LSB: Start and stop the mysql database server daemon...
Sep 01 21:54:44 gimli mysql[581]: Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
Sep 01 21:54:44 gimli systemd[1]: mysql.service: control process exited, code=exited status=1
Sep 01 21:54:44 gimli systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Sep 01 21:54:44 gimli systemd[1]: Unit mysql.service entered failed state.
그리고 해당 로그는/var/log/mysql/error.log
170901 21:54:16 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170901 21:54:16 [Note] Plugin 'FEDERATED' is disabled.
170901 21:54:17 InnoDB: The InnoDB memory heap is disabled
170901 21:54:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170901 21:54:17 InnoDB: Compressed tables use zlib 1.2.8
170901 21:54:17 InnoDB: Using Linux native AIO
170901 21:54:17 InnoDB: Initializing buffer pool, size = 128.0M
170901 21:54:17 InnoDB: Completed initialization of buffer pool
170901 21:54:17 InnoDB: highest supported file format is Barracuda.
170901 21:54:22 InnoDB: Waiting for the background threads to start
170901 21:54:23 InnoDB: 5.5.57 started; log sequence number 351234412
170901 21:54:23 [Note] Server hostname (bind-address): '192.168.1.14'; port: 3306
170901 21:54:23 [Note] - '192.168.1.14' resolves to '192.168.1.14';
170901 21:54:23 [Note] Server socket created on IP: '192.168.1.14'.
170901 21:54:23 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
170901 21:54:23 [ERROR] Do you already have another mysqld server running on port: 3306 ?
170901 21:54:23 [ERROR] Aborting
170901 21:54:23 InnoDB: Starting shutdown...
170901 21:54:24 InnoDB: Shutdown completed; log sequence number 351234412
170901 21:54:24 [Note] /usr/sbin/mysqld: Shutdown complete
그러나 수동으로 실행하면 sudo systemctl start mysql
올바르게 작동합니다.
170901 22:01:36 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170901 22:01:36 [Note] Plugin 'FEDERATED' is disabled.
170901 22:01:36 InnoDB: The InnoDB memory heap is disabled
170901 22:01:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170901 22:01:36 InnoDB: Compressed tables use zlib 1.2.8
170901 22:01:36 InnoDB: Using Linux native AIO
170901 22:01:36 InnoDB: Initializing buffer pool, size = 128.0M
170901 22:01:36 InnoDB: Completed initialization of buffer pool
170901 22:01:36 InnoDB: highest supported file format is Barracuda.
170901 22:01:36 InnoDB: Waiting for the background threads to start
170901 22:01:37 InnoDB: 5.5.57 started; log sequence number 351234412
170901 22:01:37 [Note] Server hostname (bind-address): '192.168.1.14'; port: 3306
170901 22:01:37 [Note] - '192.168.1.14' resolves to '192.168.1.14';
170901 22:01:37 [Note] Server socket created on IP: '192.168.1.14'.
170901 22:01:37 [Note] Event Scheduler: Loaded 0 events
170901 22:01:37 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.57-0+deb8u1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Debian)
내가 아는 한, systemd 스크립트는 수정되지 않았으며(Debian mysql 패키지에 포함된 스크립트임), 내가 아는 한 제대로 작동한 적이 없습니다. 3306 포트는 다른 프로세스에서 사용되어서는 안 됩니다.
답변1
재부팅하고 루트로 실행한 후 바로 서버에 SSH를 연결해 netstat -lp | grep 3306
해당 포트에서 실제로 수신 대기 중인 프로그램을 확인하면 문제를 추가로 디버깅할 수 있습니다.
답변2
분명히 문제는 mysql이 시작될 때 네트워크 인터페이스가 작동하지 않았다는 것입니다. 이는 아마도 DHCP에 약간의 시간이 걸리는 것과 관련이 있을 것입니다.
적어도 이제 인터페이스를 고정 IP로 설정했으므로 더 이상 mysql 문제를 관찰하지 않으므로(다시 시작할 때마다 재현 가능) 문제가 해결되었습니다.
데비안에서 고정 IP를 설정하는 절차는 다음과 같습니다.
- SSH 기능이 손실될 수 있으므로 네트워크를 엉망으로 만들기 전에 서버(전원 버튼, 키보드, 화면)에 물리적으로 액세스할 수 있는지 확인하세요.
- /etc/network/인터페이스 편집
다음으로 교체
iface eth0 inet dhcp
:iface eth0 inet static address 192.168.1.14 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 gateway 192.168.1.1
- 재부팅(참고: 예를 들어 네트워크를 다시 시작하면 충분
systemctl restart networking
하지만 내 경우에는 연결이 끊겼지만 전원 버튼으로 서버를 다시 시작하지 않으면 다시 연결할 수 없었습니다)
이 예에서는 고정 IP 192.168.1.14와 게이트웨이 192.168.1.1을 할당합니다.
물론 이것은 단지 해결 방법일 뿐이며, 실제 문제는 mysql이 네트워크 인터페이스가 작동될 때까지 기다려야 한다는 것입니다. 그러나 저는 그렇게 할 만큼 시스템을 잘 알지 못합니다.