1. 程式人生 > 實用技巧 >離線解決Rabbitmq啟動報“line 80: erl: command not found”

離線解決Rabbitmq啟動報“line 80: erl: command not found”

問題描述:

部署一套新環境,因為該環境的機器規定不能連外網,rabbitmq採用離線部署的方式。
將本地yum下載的rabbitmq所需rpm包手動上傳到該環境的機器離線部署。所有的rpm包都和本地線上安裝都是一樣的,本地測試機上部署和啟動正常,但是在新環境機器上啟動rabbitmq的時候出現了“/usr/lib/rabbitmq/bin/rabbitmq-server: line 80: erl: command not found”的報錯。報錯資訊如下:

[root@host1 ~]# rabbitmq-server
/usr/lib/rabbitmq/bin/rabbitmq-server: line 80: erl: command not found
[root@host1 ~]#

分析過程:

1、根據報錯說“erl: command not found”,就單獨執行了一下erl,發現並沒有什麼問題:

[root@host1 ~]# erl
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.3  (abort with ^G)
1>

2、查看了/etc/profile檔案,看了一下配置的路徑,也是和本地測試機實驗的時候配置是一樣的,路徑什麼的都是正確的,並沒有配錯誤:

[root@host1 ~]# cat /etc/profile
# /etc/profile
......   #省略若干行
  export PATH=$PATH:/usr/local/erlang/bin
  export PATH=$PATH:/usr/lib/rabbitmq/bin
[root@host1 ~]#

3、試著直接執行報錯的文件啟動,發現是可以的,服務也能啟動:

[root@host1 ~]# sh /usr/lib/rabbitmq/bin/rabbitmq-server

              RabbitMQ 3.6.12. Copyright (C) 2007-2017 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/[email protected]
  ######  ##        /var/log/rabbitmq/[email protected]
  ##########
              Starting broker...
 completed with 0 plugins.

那麼啟動執行的指令碼可能不是這個指令碼,所以想到替換一下啟動指令碼試試,或許有用。

解決過程:

1、找到rabbitmq-server命令執行的指令碼的位置:

[root@host1 ~]# which rabbitmq-server
/sbin/rabbitmq-server
[root@host1 ~]#

2、比較兩個文件,發現並不是同一個檔案。於是把可以執行的/usr/lib/rabbitmq/bin/rabbitmq-server做軟個連線到/sbin下面去替代原來執行報錯的/sbin/rabbitmq-server檔案:

[root@host1 sbin]# mv /sbin/rabbitmq-server /sbin/rabbitmq-server.bak
[root@host1 sbin]# ln -s /usr/lib/rabbitmq/bin/rabbitmq-server /sbin/rabbitmq-server

3、再次執行rabbitmq-server命令啟動,發現還在報錯:

[root@host1 sbin]# rabbitmq-server
/sbin/rabbitmq-server: line 22: /sbin/rabbitmq-env: No such file or directory
[root@host1 sbin]#

4、把報錯缺少的檔案rabbitmq-env再做一個軟連結到/sbin下面:

[root@host1 sbin]# ln -s /usr/lib/rabbitmq/bin/rabbitmq-env /sbin/rabbitmq-env

5、再執行rabbitmq-server命令來啟動服務,發現可以啟動了:

[root@host1 sbin]# rabbitmq-server   #這種啟動方法只能前臺啟動,Ctrl+c,程序就沒了。所以在正式啟動的時候我用的nohup rabbitmq-server >/dev/null 2>&1 & 這個命令啟動

              RabbitMQ 3.6.12. Copyright (C) 2007-2017 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/[email protected]
  ######  ##        /var/log/rabbitmq/[email protected]
  ##########
              Starting broker...
 completed with 0 plugins.

然後檢視程序,發現程序和埠號都已經起來了:

[root@host1 sbin]# ps -ef|grep rabbitmq
root     16778     1  0 Jul03 ?        00:32:36 /usr/local/erlang/lib/erlang/erts-8.3/bin/beam.smp -W w -A 128 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/local/erlang/lib/erlang -progname erl -- -home /root -- -pa /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.12/ebin -noshell -noinput -s rabbit boot -sname rabbit@host-172-51-121-10 -boot start_sasl -config /etc/rabbitmq/rabbitmq -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/var/log/rabbitmq/[email protected]"} -rabbit sasl_error_logger {file,"/var/log/rabbitmq/[email protected]"} -rabbit enabled_plugins_file "/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.6.12/plugins" -rabbit plugins_expand_dir "/var/lib/rabbitmq/mnesia/rabbit@host-172-51-121-10-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/var/lib/rabbitmq/mnesia/rabbit@host-172-51-121-10" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 -noshell -noinput
root     27708 25767  0 09:12 pts/1    00:00:00 grep --color=auto rabbitmq
[root@host1 sbin]#
[root@host1 sbin]# netstat -tlunp|grep 15672
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      16778/beam.smp
[root@host1 sbin]#

6、安裝外掛:

[root@host1 sbin]#  rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  amqp_client
  cowlib
  cowboy
  rabbitmq_web_dispatch
  rabbitmq_management_agent
  rabbitmq_management

Applying plugin configuration to rabbit@host1... started 6 plugins.
[root@host1 sbin]#
[root@host1 sbin]#

特別說明:
本文的這種解決方法,使用rabbitmq-server方法可以啟動服務,但是使用另一種service rabbitmq-server start的方法啟動,發現還是啟動不了,會報這個錯:

[root@host1 sbin]# service rabbitmq-server start
Starting rabbitmq-server (via systemctl):  Job for rabbitmq-server.service failed because the control process exited with error code. See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details.
                                                           [FAILED]

檢視報錯詳情:

[root@host1 sbin]# systemctl status rabbitmq-server.service
â— rabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker
   Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-07-03 11:26:58 CST; 22s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10985 ExecStart=/etc/rc.d/init.d/rabbitmq-server start (code=exited, status=1/FAILURE)

Jul 03 11:26:58 host1 systemd[1]: Starting LSB: Enable AMQP service provided by RabbitMQ broker...
Jul 03 11:26:58 host1 su[11076]: (to rabbitmq) root on none
Jul 03 11:26:58 host1 su[11208]: (to rabbitmq) root on none
Jul 03 11:26:58 host1 rabbitmq-server[10985]: Starting rabbitmq-server: FAILED - check /var/log/rabbitmq/startup_{log, _err}
Jul 03 11:26:58 host1 rabbitmq-server[10985]: rabbitmq-server.
Jul 03 11:26:58 host1 systemd[1]: rabbitmq-server.service: control process exited, code=exited status=1
Jul 03 11:26:58 host1 systemd[1]: Failed to start LSB: Enable AMQP service provided by RabbitMQ broker.
Jul 03 11:26:58 host1 systemd[1]: Unit rabbitmq-server.service entered failed state.
Jul 03 11:26:58 host1 systemd[1]: rabbitmq-server.service failed.
[root@host1 sbin]#

檢視報錯日誌:

[root@host1 sbin]# cat /var/log/rabbitmq/startup_err
erlexec: HOME must be set
[root@host1 sbin]#

這個問題暫時還沒找到怎麼解決的方法,後續解決了再補上。

後記:
遇到報錯“/usr/lib/rabbitmq/bin/rabbitmq-server: line 80: erl: command not found”,在網上查了很多解決方法,主要說法有兩種:
1、在/usr/lib/rabbitmq/bin/rabbitmq-server檔案的80行新增erl的環境變數;
2、修改/etc/profile修改環境變數,加上類似export HOME=/usr/lib/rabbitmq的配置
這兩種方法都試過了,對我的問題不奏效,但記下來作為借鑑。

原文連結:https://blog.51cto.com/10950710/2139572