Mysql

配置集群時無法通過socket ‘/var/run/mysqld/mysqld.sock’(2“No such file or directory”)連接到本地MySQL伺服器

  • October 4, 2018

我有 3 個 MariaDB 節點。想配置集群。在gcomm://中指定集群中所有成員的my.cnf ips按此

然後?pc.wait_prim=nogcomm://ip1,ip2,ip3的時候添加

然後mysqld程序在每個 VM 上啟動,但是當我嘗試連接mysql -uroot -ppass以便執行時

SET GLOBAL wsrep_provider_options="pc.bootstrap=1";

錯誤彈出:

無法通過套接字’/var/run/mysqld/mysqld.sock’連接到本地MySQL伺服器(2“沒有這樣的文件或目錄”)

每個程序的error.log顯示:

2018-02-01 15:13:23 140529975699392 [Note] WSREP: gcomm: connecting to group 'my_wsrep_cluster', peer '10.0.0.42:,10.0.0.44:,10.0.0.43:'
2018-02-01 15:13:23 140529975699392 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') connection established to 71d7b5ed tcp://10.0.0.44:45
2018-02-01 15:13:23 140529975699392 [Warning] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') address 'tcp://10.0.0.44:4567' points to own listeddress, blacklisting
2018-02-01 15:13:23 140529975699392 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') connection established to 6ac0d002 tcp://10.0.0.42:45
2018-02-01 15:13:23 140529975699392 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') turning message relay requesting on, nonlive peers:
2018-02-01 15:13:23 140529975699392 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') connection established to 6bd1b1f9 tcp://10.0.0.43:45
2018-02-01 15:13:23 140529975699392 [Note] WSREP: gcomm: connected
2018-02-01 15:13:23 140529975699392 [Note] WSREP: Changing maximum packet size to 64500, resulting msg size: 32636
2018-02-01 15:13:23 140529975699392 [Note] WSREP: Shifting CLOSED -> OPEN (TO: 0)
2018-02-01 15:13:23 140529975699392 [Note] WSREP: Opened channel 'my_wsrep_cluster'
2018-02-01 15:13:23 140529975699392 [Note] WSREP: Waiting for SST to complete.
2018-02-01 15:13:23 140529635424000 [Note] WSREP: declaring 6ac0d002 at tcp://10.0.0.42:4567 stable
2018-02-01 15:13:23 140529635424000 [Note] WSREP: declaring 6bd1b1f9 at tcp://10.0.0.43:4567 stable
2018-02-01 15:13:23 140529635424000 [Warning] WSREP: no nodes coming from prim view, prim not possible
2018-02-01 15:13:23 140529635424000 [Note] WSREP: view(view_id(NON_PRIM,6ac0d002,2) memb {
       6ac0d002,0
       6bd1b1f9,0
       71d7b5ed,0
} joined {
} left {
} partitioned {
})
2018-02-01 15:13:23 140529627031296 [Note] WSREP: New COMPONENT: primary = no, bootstrap = no, my_idx = 2, memb_num = 3
2018-02-01 15:13:23 140529627031296 [Note] WSREP: Flow-control interval: [28, 28]
2018-02-01 15:13:23 140529627031296 [Note] WSREP: Trying to continue unpaused monitor
2018-02-01 15:13:23 140529627031296 [Note] WSREP: Received NON-PRIMARY.
2018-02-01 15:13:23 140529975253760 [Note] WSREP: New cluster view: global state: :-1, view# -1: non-Primary, number of nodes: 3, my ind protocol version -1
2018-02-01 15:13:23 140529975253760 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2018-02-01 15:13:26 140529635424000 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') connection to peer 71d7b5ed with addr tcp://10.0.0.44timed out, no messages seen in PT3S
2018-02-01 15:13:26 140529635424000 [Note] WSREP: (71d7b5ed, 'tcp://0.0.0.0:4567') turning message relay requesting off

為什麼會發生,出了什麼問題?

檢查您的配置文件/etc/my.cnf/etc/my.cnf.d/server.cnf查找套接字參數。確保客戶端和伺服器相同。socket參數的一個好地方是在

$$ client-server $$中的部分/etc/my.cnf。套接字文件由 MariaDB 伺服器在啟動時創建。 請注意,MariaDB 配置文件可能駐留在其他位置,這些位置可能會覆蓋您在上述兩個文件中的設置。有關更多詳細資訊,請參閱MariaDB KB 中的此頁面

另請注意,您可能能夠通過 TCP 而不是通過套接字連接到 MariaDB。您可以指定要使用 TCP 而不是帶有mysql ... --protocol=TCP. 如果這是成功的,那麼您可以SHOW VARIABLES LIKE 'socket';找出套接字文件的真正位置(或應該在哪裡)。然後,您可以連接mysql ... --socket=/path/to/file.sock或編輯配置文件,以便客戶端從那裡正確讀取它。

在某些情況下,您還可以通過列出程序來確定使用的套接字文件位置:ps -ef | grep mysql這可能會輸出類似

root     23900     1  0 13:27 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/vserv-03.pid
mysql    24402 23900  0 13:27 ?        00:00:50 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --wsrep_on=ON --wsrep_provider=/usr/lib64/galera/libgalera_smm.so --log-error=/var/lib/mysql/vserv-03.err --open-files-limit=65535 --pid-file=/var/lib/mysql/vserv-03.pid --socket=/var/lib/mysql/mysql.sock --wsrep_start_position=98b22222-aa16-1114-ba1a-886633c6b8eb:55133333

正如您在此處看到的(向右滾動),它在/var/lib/mysql/mysql.sock.

編輯: 找到套接字文件位置的一個非常好的方法是:

netstat -ln | grep mysql
unix  2      [ ACC ]     STREAM     LISTENING     22418    /var/lib/mysql/mysql.sock 

重新啟動後發生在我身上……在任何地方都找不到套接字文件。就我而言,它應該在: /var/run/mysqld/mysqld.sock

就我而言,我通過以下方式修復了它:

apt-get update
apt-get upgrade

完成這些步驟後,套接字出現在 mysqld 目錄中,我可以啟動 mysql (mariaDB)。

引用自:https://dba.stackexchange.com/questions/196836