Ubuntu上只能源码安装Erlang,RabbitMQ和各种相关依赖,无法使用yum,rpm等方式!
源码安装Erlang和RabbitMQ:
注意只要安装了Erlang环境,RabbitMQ解压后即可使用,无需安装!!Web插件安装需要在rabbitmq-server启动条件下进行。启动后需要将防火墙开启5672和15672默认端口才可远程访问。默认guest用户无法远程访问,需要按照博客中介绍的重新创建一个用于administrator权限的admin用户才行。
https://blog.csdn.net/sms15732621690/article/details/80962080
https://blog.csdn.net/sdsabc2000/article/details/38845595
最新的19.3及以上的erlang包,虽然是tar.gz结尾,并没有使用gzip压缩,tar zxvf会报错!!去掉z参数,直接使用tar xvf即可解包,一定注意!!
最新的RabbitMQ选择generic-unix版本的xz包(debian的gz包坑爹,只有几K),关于xz包如何解压的问题:
https://blog.csdn.net/u013439115/article/details/77935602
Erlang安装缺少ncurses依赖,也要源码安装,我的Ubuntu16.04LTS需要安装ncurses6.1源码版本才能成功:
https://blog.csdn.net/QQ1910084514/article/details/79820876
http://blog.51cto.com/liuzhenlife/1892078
https://yq.aliyun.com/ziliao/69471
Erlang的configure检查时提示找不到openssl,但没有报错,可以正常安装,Ubuntu也带了openssl,安装新版本zlib和openssl并生效请参照前面安装Nginx的文章!!
常见的修复安装命令:用于一些包源码安装时缺少依赖,只要在安装命令执行后紧接着再执行一下下面的命令(不用带上包名)
sudo apt-get -f install
最后所有的/etc/profiles中环境变量配置,包括openssl,erlang,rabbitmq(注意PATH=$PATH:XXX这种只能出现一次,写在所有环境变量配置的最后!否则后面写的覆盖前面的,前面的环境变量就无效了!!):
export OPENSSL=/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
ERLANG_HOME=/opt/erlang
RABBITMQ_HOME=/opt/rabbitmq_server-3.6.10
export PATH=$PATH:$ERLANG_HOME/bin:$RABBITMQ_HOME/sbin
export ERLANG_HOME
export RABBITMQ_HOME
Ubuntu普通用户在任意目录启动rabbit-server,提示错误:
baigang@baigang-virtual-machine:/opt$ which rabbitmq-server
/opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server
baigang@baigang-virtual-machine:/opt$ rabbitmq-server &
[1] 53456
baigang@baigang-virtual-machine:/opt$ /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server: 51: /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server: cannot create /opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine.pid: Permission denied
Failed to write pid file: /opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine.pid
[1]+ Exit 73 rabbitmq-server
这是由于普通用户在/opt的各层目录和文件默认都没有写权限,所以无法写入rabbitmq的pid造成启动失败,解决办法是在错误提示的各层目录都使用sudo chmod a+w xxx目录命令为普通用户添加目录写权限,最后在已经生成的pid文件也使用sudo chmod a+w xxx.pid为普通用户添加文件写命令!
启动成功:
baigang@baigang-virtual-machine:~$ rabbitmq-server &
[1] 53719
baigang@baigang-virtual-machine:~$
RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine.log
###### ## /opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine-sasl.log
##########
Starting broker...
completed with 0 plugins.
baigang@baigang-virtual-machine:~$
baigang@baigang-virtual-machine:~$ ps aux|grep rabbit
baigang 53719 0.0 0.0 4508 1640 pts/4 S 12:16 0:00 /bin/sh /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server
baigang 53824 34.0 2.9 3259196 60208 pts/4 Sl 12:16 0:05 /opt/erlang/lib/erlang/erts-8.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 32000 -K true -B i -- -root /opt/erlang/lib/erlang -progname erl -- -home /home/baigang -- -pa /opt/rabbitmq_server-3.6.10/ebin -noshell -noinput -s rabbit boot -sname rabbit@baigang-virtual-machine -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine.log"} -rabbit sasl_error_logger {file,"/opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine-sasl.log"} -rabbit enabled_plugins_file "/opt/rabbitmq_server-3.6.10/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/opt/rabbitmq_server-3.6.10/plugins" -rabbit plugins_expand_dir "/opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672
baigang 53949 0.0 0.0 21292 1092 pts/4 S+ 12:17 0:00 grep --color=auto rabbit
状态查看:
baigang@baigang-virtual-machine:~$ rabbitmqctl status
Status of node 'rabbit@baigang-virtual-machine'
[{pid,53824},
{running_applications,
[{rabbit,"RabbitMQ","3.6.10"},
{mnesia,"MNESIA CXC 138 12","4.14.3"},
{os_mon,"CPO CXC 138 46","2.4.2"},
{ranch,"Socket acceptor pool for TCP protocols.","1.3.0"},
{ssl,"Erlang/OTP SSL application","8.1.1"},
{public_key,"Public key infrastructure","1.4"},
{rabbit_common,
"Modules shared by rabbitmq-server and rabbitmq-erlang-client",
"3.6.10"},
{xmerl,"XML parser","1.3.13"},
{crypto,"CRYPTO","3.7.3"},
{asn1,"The Erlang ASN1 compiler version 4.0.4","4.0.4"},
{syntax_tools,"Syntax tools","2.1.1"},
{compiler,"ERTS CXC 138 10","7.0.4"},
{sasl,"SASL CXC 138 11","3.0.3"},
{stdlib,"ERTS CXC 138 10","3.3"},
{kernel,"ERTS CXC 138 10","5.2"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:4:4] [async-threads:64] [kernel-poll:true]
"},
{memory,
[{total,53825064},
{connection_readers,0},
{connection_writers,0},
{connection_channels,0},
{connection_other,0},
{queue_procs,2736},
{queue_slave_procs,0},
{plugins,0},
{other_proc,20046312},
{mnesia,61584},
{metrics,184096},
{mgmt_db,0},
{msg_index,46776},
{other_ets,2141232},
{binary,49816},
{code,21379329},
{atom,891849},
{other_system,9202694}]},
{alarms,[]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
{vm_memory_high_watermark,0.4},
{vm_memory_limit,826292633},
{disk_free_limit,50000000},
{disk_free,3195473920},
{file_descriptors,
[{total_limit,924},{total_used,2},{sockets_limit,829},{sockets_used,0}]},
{processes,[{limit,1048576},{used,154}]},
{run_queue,0},
{uptime,35},
{kernel,{net_ticktime,60}}]
集群状态查看:
baigang@baigang-virtual-machine:~$ rabbitmqctl cluster_status
Cluster status of node 'rabbit@baigang-virtual-machine'
[{nodes,[{disc,['rabbit@baigang-virtual-machine']}]},
{running_nodes,['rabbit@baigang-virtual-machine']},
{cluster_name,<<"rabbit@baigang-virtual-machine">>},
{partitions,[]},
{alarms,[{'rabbit@baigang-virtual-machine',[]}]}]
守护进程后台运行:
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$ rabbitmq-server --detached &
[1] 56532
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$
RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine.log
###### ## /opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine-sasl.log
##########
Starting broker...
completed with 6 plugins.
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$ ps aux|grep rabbit
baigang 56532 0.0 0.0 4508 1700 pts/4 S 13:01 0:00 /bin/sh /opt/rabbitmq_server-3.6.10/sbin/rabbitmq-server --detached
baigang 56646 74.6 3.5 3275840 72552 pts/4 Sl 13:01 0:08 /opt/erlang/lib/erlang/erts-8.3/bin/beam.smp -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 32000 -K true -B i -- -root /opt/erlang/lib/erlang -progname erl -- -home /home/baigang -- -pa /opt/rabbitmq_server-3.6.10/ebin -noshell -noinput -s rabbit boot -sname rabbit@baigang-virtual-machine -boot start_sasl -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine.log"} -rabbit sasl_error_logger {file,"/opt/rabbitmq_server-3.6.10/var/log/rabbitmq/rabbit@baigang-virtual-machine-sasl.log"} -rabbit enabled_plugins_file "/opt/rabbitmq_server-3.6.10/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/opt/rabbitmq_server-3.6.10/plugins" -rabbit plugins_expand_dir "/opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/opt/rabbitmq_server-3.6.10/var/lib/rabbitmq/mnesia/rabbit@baigang-virtual-machine" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 --detached
baigang 56772 0.0 0.0 21292 932 pts/4 S+ 13:01 0:00 grep --color=auto rabbit
服务开启情况下Web插件的安装:同样遇到无法创建文件问题,仍然是没有权限,解决办法参照上面服务器安装的pid创建权限问题
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$ rabbitmq-plugins enable rabbitmq_management
Plugin configuration unchanged.
Applying plugin configuration to rabbit@baigang-virtual-machine... nothing to do.
baigang@baigang-virtual-machine:/opt/rabbitmq_server-3.6.10/etc/rabbitmq$
然后可以通过默认15672端口Web监控页面正常访问。
RabbitMQ的rpm安装方式参考:
https://www.jianshu.com/p/f05803196c24