CentOS 6.6 + MySQL MHA(0.56)\
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@slave2
我的 SSH 检查没有问题
[root@master ~]# ssh -v root@slave2
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to slave2 [192.168.233.133] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'slave2' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8
Last login: Wed Jun 1 06:56:32 2016 from master
并通过命令行测试 ssh 连接,正确
[root@master ~]# ssh root@slave2
Last login: Wed Jun 1 22:55:06 2016 from 192.168.233.1
[root@slave2 ~]#
当我使用 mha ssh 检查(masterha_check_ssh 脚本)时,出现错误“权限被拒绝(publickey,password)”。
[root@monitor ~]# masterha_check_ssh --conf=/etc/app1.cnf
Thu Jun 2 04:25:52 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Jun 2 04:25:52 2016 - [info] Reading application default configuration from /etc/app1.cnf..
Thu Jun 2 04:25:52 2016 - [info] Reading server configuration from /etc/app1.cnf..
Thu Jun 2 04:25:52 2016 - [info] Starting SSH connection tests..
Thu Jun 2 04:25:53 2016 - [error][/usr/local/share/perl5/MHA/SSHCheck.pm, ln63]
Thu Jun 2 04:25:52 2016 - [debug] Connecting via SSH from root@master(192.168.233.135:22) to root@slave2(192.168.233.133:22)..
Permission denied (publickey,password).
Thu Jun 2 04:25:52 2016 - [error][/usr/local/share/perl5/MHA/SSHCheck.pm, ln111] SSH connection from root@master(192.168.233.135:22) to root@slave2(192.168.233.133:22) failed!
Thu Jun 2 04:25:53 2016 - [error][/usr/local/share/perl5/MHA/SSHCheck.pm, ln63]
Thu Jun 2 04:25:52 2016 - [debug] Connecting via SSH from root@slave2(192.168.233.133:22) to root@master(192.168.233.135:22)..
Permission denied (publickey).
Thu Jun 2 04:25:53 2016 - [error][/usr/local/share/perl5/MHA/SSHCheck.pm, ln111] SSH connection from root@slave2(192.168.233.133:22) to root@master(192.168.233.135:22) failed!
SSH Configuration Check Failed!
at /usr/local/bin/masterha_check_ssh line 44
You have new mail in /var/spool/mail/root
这是我的 mha 配置,ssh_user 是 root ~ 我有 5 个服务器—— master、slave1、slave2、slave3、monitor
[root@monitor bin]# cat /etc/app1.cnf
[server default]
user=root
password=123456
ssh_user=root
master_binlog_dir= /data/mysql3306/logs/
remote_workdir=/data/mysql3306/logs/mha_save_binlog
secondary_check_script= /usr/bin/masterha_secondary_check -s slave3 -s slave2
ping_interval=3
#master_ip_failover_script=/script/masterha/master_ip_failover
#shutdown_script= /script/masterha/power_manager
#report_script= /script/masterha/send_master_failover_mail
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/app1.log
[server1]
hostname=master
[server2]
hostname=slave1
[server3]
hostname=slave2
[server4]
hostname=slave3
这件事已经让我抓狂了 24 个小时,有人能帮帮我吗?
答案1
一种解决方法是使用预共享密钥(在所有集群之间)并使用masterha_check_ssh
公钥认证。