在CentOS 7.5系統上安裝RabbitMQ


http://www.rabbitmq.com/download.html
http://www.rabbitmq.com/install-rpm.html

[root@contoso ~]# wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
[root@contoso ~]# rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
[root@contoso ~]# yum update
[root@contoso ~]# yum install -y erlang

  1.  
    [root@contoso ~] # cat > hello.erl
  2.  
    - module(hello).
  3.  
    -export([hello_world/ 0]).
  4.  
    hello_world() -> io:fwrite( "hello, world\n").
  5.  
    [root@contoso ~] # erl
  6.  
    Erlang/OTP 21 [erts- 10.0. 3] [source] [ 64-bit] [ smp: 4 : 4] [ ds: 4 : 4 : 10] [async- threads: 1] [hipe]
  7.  
     
  8.  
    Eshell V1 0. 0. 3 (abort with ^G)
  9.  
    1> c(hello).
  10.  
    {ok,hello}
  11.  
    2> hello:hello_world().
  12.  
    hello, world
  13.  
    ok
  14.  
    3>

[root@contoso ~]# wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.7/rabbitmq-server-3.7.7-1.el7.noarch.rpm
[root@contoso ~]# yum install -y rabbitmq-server-3.7.7-1.el7.noarch.rpm
[root@contoso ~]# systemctl enable rabbitmq-server
[root@contoso ~]# systemctl restart rabbitmq-server

  1.  
    首先看看hostname輸出,注意是contoso.com而不是contoso,所以服務才無法啟動
  2.  
    [root@contoso ~] # hostname
  3.  
    contoso.com
  4.  
     
  5.  
    通過以下命令可以進一步證明rabbitmq-server啟動過程需要連接主機名contoso,但是contoso的主機名在此系統上沒有設置
  6.  
    [root@contoso ~] # rabbitmqctl status
  7.  
    Status of node rabbit@contoso ...
  8.  
    Error: unable to perform an operation on node 'rabbit@contoso'. Please see diagnostics information and suggestions below.
  9.  
     
  10.  
    Most common reasons for this are:
  11.  
     
  12.  
    * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
  13.  
    * CLI tool fails to authenticate with the server (e.g. due to CLI tool 's Erlang cookie not matching that of the server)
  14.  
    * Target node is not running
  15.  
     
  16.  
    In addition to the diagnostics info below:
  17.  
     
  18.  
    * See the CLI, clustering and networking guides on http://rabbitmq.com/documentation.html to learn more
  19.  
    * Consult server logs on node rabbit@contoso
  20.  
     
  21.  
    DIAGNOSTICS
  22.  
    ===========
  23.  
     
  24.  
    attempted to contact: [rabbit@contoso]
  25.  
     
  26.  
    rabbit@contoso:
  27.  
    * unable to connect to epmd (port 4369) on contoso: address (cannot connect to host/port)
  28.  
     
  29.  
     
  30.  
    Current node details:
  31.  
    * node name: rabbitmqcli66@contoso
  32.  
    * effective user's home directory: / var/lib/rabbitmq
  33.  
    * Erlang cookie hash: p5tKqEzeEvxH0+WQ75PYkA==
  34.  
     
  35.  
    我們可以通過設置以下格式的/etc/hosts文件映射格式,自己添加 2條本來就不存在的映射關系
  36.  
    contoso 127.0 .0 .1
  37.  
    contoso 192.168 .10 .13
  38.  
    其中 192.168 .10 .13是本機真實的IP地址,這樣就能解決rabbitmq-server無法啟動的問題啦
  39.  
     
  40.  
    [root@contoso ~] # cat /etc/hosts
  41.  
    :: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  42.  
    127.0 .0 .1 localhost localhost.localdomain localhost4 localhost4.localdomain4 contoso contoso.com
  43.  
    192.168 .10 .13 contoso contoso.com
  44.  
    [root@contoso ~] # systemctl restart rabbitmq-server
  45.  
    [root@contoso ~] # systemctl status rabbitmq-server
  46.  
    ● rabbitmq-server.service - RabbitMQ broker
  47.  
    Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
  48.  
    Active: active (running) since Sat 2018 -07 -21 15: 54: 21 CST; 31s ago
  49.  
    Process: 39174 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status= 69)
  50.  
    Main PID: 39286 (beam.smp)
  51.  
    Status: "Initialized"
  52.  
    Tasks: 90
  53.  
    CGroup: /system.slice/rabbitmq-server.service
  54.  
    ├─ 39286 /usr/lib64/erlang/erts -10.0 .3/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmb...
  55.  
    ├─ 39596 erl_child_setup 1024
  56.  
    ├─ 39617 inet_gethost 4
  57.  
    └─ 39618 inet_gethost 4
  58.  
     
  59.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: ## ##
  60.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: ## ## RabbitMQ 3.7.7. Copyright (C) 2007-2018 Pi...nc.
  61.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: ########## Licensed under the MPL. See http://www.ra...om/
  62.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: ###### ##
  63.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: ########## Logs: /var/log/rabbitmq/rabbit@contoso.log
  64.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: / var/log/rabbitmq/rabbit@contoso_upgrade.log
  65.  
    Jul 21 15: 54: 20 contoso.com rabbitmq-server[ 39286]: Starting broker...
  66.  
    Jul 21 15: 54: 21 contoso.com rabbitmq-server[ 39286]: systemd unit for activation check: "rabbitmq-server.service"
  67.  
    Jul 21 15: 54: 21 contoso.com systemd[ 1]: Started RabbitMQ broker.
  68.  
    Jul 21 15: 54: 21 contoso.com rabbitmq-server[ 39286]: completed with 0 plugins.
  69.  
    Hint: Some lines were ellipsized, use - l to show in full.
  70.  
    [ root@ contoso ~]#


[root@contoso ~]# systemctl status rabbitmq-server

  1.  
    [ root@contoso ~] # rabbitmqctl status
  2.  
    Status of node rabbit@contoso ...
  3.  
    [ {pid,39286},
  4.  
    {running_applications,
  5.  
    [{rabbit,"RabbitMQ","3.7.7"},
  6.  
    {mnesia,"MNESIA CXC 138 12","4.15.4"},
  7.  
    {rabbit_common,
  8.  
    "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
  9.  
    "3.7.7"},
  10.  
    {ranch_proxy_protocol,"Ranch Proxy Protocol Transport","1.5.0"},
  11.  
    {ranch,"Socket acceptor pool for TCP protocols.","1.5.0"},
  12.  
    {ssl,"Erlang/OTP SSL application","9.0"},
  13.  
    {public_key,"Public key infrastructure","1.6.1"},
  14.  
    {crypto,"CRYPTO","4.3"},
  15.  
    {asn1,"The Erlang ASN1 compiler version 5.0.6","5.0.6"},
  16.  
    {os_mon,"CPO CXC 138 46","2.4.5"},
  17.  
    {jsx,"a streaming, evented json parsing toolkit","2.8.2"},
  18.  
    {recon,"Diagnostic tools for production use","2.3.2"},
  19.  
    {inets,"INETS CXC 138 49","7.0"},
  20.  
    {xmerl,"XML parser","1.3.17"},
  21.  
    {lager,"Erlang logging framework","3.6.3"},
  22.  
    {goldrush,"Erlang event stream processor","0.1.9"},
  23.  
    {compiler,"ERTS CXC 138 10","7.2.2"},
  24.  
    {syntax_tools,"Syntax tools","2.1.5"},
  25.  
    {syslog,"An RFC 3164 and RFC 5424 compliant logging framework.","3.4.2"},
  26.  
    {sasl,"SASL CXC 138 11","3.2"},
  27.  
    {stdlib,"ERTS CXC 138 10","3.5.1"},
  28.  
    {kernel,"ERTS CXC 138 10","6.0"}]},
  29.  
    {os,{unix,linux}},
  30.  
    {erlang_version,
  31.  
    "Erlang/OTP 21 [erts-10.0.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe]\n"},
  32.  
    {memory,
  33.  
    [ {connection_readers,0},
  34.  
    {connection_writers,0},
  35.  
    {connection_channels,0},
  36.  
    {connection_other,0},
  37.  
    {queue_procs,0},
  38.  
    {queue_slave_procs,0},
  39.  
    {plugins,5892},
  40.  
    {other_proc,21085464},
  41.  
    {metrics,184596},
  42.  
    {mgmt_db,0},
  43.  
    {mnesia,73008},
  44.  
    {other_ets,2421712},
  45.  
    {binary,80872},
  46.  
    {msg_index,28720},
  47.  
    {code,20418905},
  48.  
    {atom,1082561},
  49.  
    {other_system,11138350},
  50.  
    {allocated_unused,5808752},
  51.  
    {reserved_unallocated,6766592},
  52.  
    {strategy,rss},
  53.  
    {total,[{erlang,56520080},{rss,69095424},{allocated,62328832}]}]},
  54.  
    {alarms,[]},
  55.  
    {listeners,[{clustering, 25672, "::"},{amqp, 5672, "::"}]},
  56.  
    {vm_memory_calculation_strategy,rss},
  57.  
    {vm_memory_high_watermark, 0.4},
  58.  
    {vm_memory_limit, 1582514176},
  59.  
    {disk_free_limit, 50000000},
  60.  
    {disk_free, 36644401152},
  61.  
    {file_descriptors,
  62.  
    [ {total_limit,924},{total_used,2},{sockets_limit,829},{sockets_used,0}]},
  63.  
    {processes,[{limit, 1048576},{used, 214}]},
  64.  
    {run_queue, 1},
  65.  
    {uptime, 1474},
  66.  
    {kernel,{net_ticktime, 60}}]
  67.  
    [ root@contoso ~] #


[root@contoso ~]# rabbitmq-plugins enable rabbitmq_management

  1.  
    [root@contoso ~] # rabbitmq-plugins enable rabbitmq_management
  2.  
    The following plugins have been configured:
  3.  
    rabbitmq_management
  4.  
    rabbitmq_management_agent
  5.  
    rabbitmq_web_dispatch
  6.  
    Applying plugin configuration to rabbit@contoso...
  7.  
    The following plugins have been enabled:
  8.  
    rabbitmq_management
  9.  
    rabbitmq_management_agent
  10.  
    rabbitmq_web_dispatch
  11.  
     
  12.  
    started 3 plugins.
  13.  
    [root@contoso ~] #

http://127.0.0.1:15672

一個是環境變量的配置文件 rabbitmq-env.conf
一個是配置信息的配置文件 rabbitmq.config
注意,這兩個文件默認是沒有的,如果需要必須自己創建。

rabbitmq-env.conf

這個文件的位置是確定和不能改變的,位於:/etc/rabbitmq目錄下(這個目錄需要自己創建)。
文件的內容包括了RabbitMQ的一些環境變量,常用的有:
#RABBITMQ_NODE_PORT=                                      //端口號
#HOSTNAME=
RABBITMQ_NODENAME=mq
RABBITMQ_CONFIG_FILE=                                       //配置文件的路徑
RABBITMQ_MNESIA_BASE=/rabbitmq/data           //需要使用的MNESIA數據庫的路徑
RABBITMQ_LOG_BASE=/rabbitmq/log                    //log的路徑
RABBITMQ_PLUGINS_DIR=/rabbitmq/plugins     //插件的路徑

 

rabbitmq 添加遠程訪問功能

 

[root@contoso ~]# cat > /etc/rabbitmq/rabbitmq.config
[{rabbit, [{loopback_users, []}]}].
[root@contoso ~]# systemctl restart rabbitmq-server
[root@contoso ~]# systemctl status rabbitmq-server

我們現在可以使用一組用戶名/密碼 guest/guest 登錄啦

 

http://127.0.0.1:15672/api/


RabbitMQ Management HTTP API
Introduction

Apart from this help page, all URIs will serve only resources of type application/json, and will require HTTP basic authentication (using the standard RabbitMQ user database). The default user is guest/guest.

Many URIs require the name of a virtual host as part of the path, since names only uniquely identify objects within a virtual host. As the default virtual host is called "/", this will need to be encoded as "%2f".

PUTing a resource creates it. The JSON object you upload must have certain mandatory keys (documented below) and may have optional keys. Other keys are ignored. Missing mandatory keys constitute an error.

Since bindings do not have names or IDs in AMQP we synthesise one based on all its properties. Since predicting this name is hard in the general case, you can also create bindings by POSTing to a factory URI. See the example below.

Many URIs return lists. Such URIs can have the query string parameters sort and sort_reverse added. sort allows you to select a primary field to sort by, and sort_reverse will reverse the sort order if set to true. The sort parameter can contain subfields separated by dots. This allows you to sort by a nested component of the listed items; it does not allow you to sort by more than one field. See the example below.

You can also restrict what information is returned per item with the columns parameter. This is a comma-separated list of subfields separated by dots. See the example below.

Most of the GET queries return many fields per object. See the separate stats documentation.
Examples

A few quick examples for Windows and Unix, using the command line tool curl:

    Get a list of vhosts:

    :: Windows
    C:\> curl -i -u guest:guest http://localhost:15672/api/vhosts
    # Unix
    $ curl -i -u guest:guest http://localhost:15672/api/vhosts
    HTTP/1.1 200 OK
    Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
    Date: Mon, 16 Sep 2013 12:00:02 GMT
    Content-Type: application/json
    Content-Length: 30

    [{"name":"/","tracing":false}]

    Get a list of channels, fast publishers first, restricting the info items we get back:

    :: Windows
    C:\> curl -i -u guest:guest "http://localhost:15672/api/channels?sort=message_stats.publish_details.rate&sort_reverse=true&columns=name,message_stats.publish_details.rate,message_stats.deliver_get_details.rate"

    # Unix
    $ curl -i -u guest:guest 'http://localhost:15672/api/channels?sort=message_stats.publish_details.rate&sort_reverse=true&columns=name,message_stats.publish_details.rate,message_stats.deliver_get_details.rate'

    HTTP/1.1 200 OK
    Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
    Date: Mon, 16 Sep 2013 12:01:17 GMT
    Content-Type: application/json
    Content-Length: 219
    Cache-Control: no-cache

    [{"message_stats":{"publish_details":{"rate" ... (remainder elided)

    Create a new vhost:

    :: Windows
    C:\> curl -i -u guest:guest -H "content-type:application/json" ^
          -XPUT http://localhost:15672/api/vhosts/foo


    # Unix
    $ curl -i -u guest:guest -H "content-type:application/json" \
       -XPUT http://localhost:15672/api/vhosts/foo


    HTTP/1.1 204 No Content
    Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
    Date: Mon, 16 Sep 2013 12:03:00 GMT
    Content-Type: application/json
    Content-Length: 0

    Note: you must specify application/json as the mime type.

    Note: the name of the object is not needed in the JSON object uploaded, since it is in the URI. As a virtual host has no properties apart from its name, this means you do not need to specify a body at all!
    Create a new exchange in the default virtual host:

    :: Windows
    C:\> curl -i -u guest:guest -H "content-type:application/json" ^
           -XPUT -d"{""type"":""direct"",""durable"":true}" ^
           http://localhost:15672/api/exchanges/%2f/my-new-exchange


    # Unix
    $ curl -i -u guest:guest -H "content-type:application/json" \
        -XPUT -d'{"type":"direct","durable":true}' \
        http://localhost:15672/api/exchanges/%2f/my-new-exchange


    HTTP/1.1 204 No Content
    Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
    Date: Mon, 16 Sep 2013 12:04:00 GMT
    Content-Type: application/json
    Content-Length: 0

    Note: we never return a body in response to a PUT or DELETE, unless it fails.
    And delete it again:

    :: Windows
    C:\> curl -i -u guest:guest -H "content-type:application/json" ^
           -XDELETE http://localhost:15672/api/exchanges/%2f/my-new-exchange


    # Unix
    $ curl -i -u guest:guest -H "content-type:application/json" \
        -XDELETE http://localhost:15672/api/exchanges/%2f/my-new-exchange


    HTTP/1.1 204 No Content
    Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
    Date: Mon, 16 Sep 2013 12:05:30 GMT
    Content-Type: application/json
    Content-Length: 0

[root@contoso ~]# python -V
Python 2.7.5

  1.  
    1. 安裝 gcc
  2.  
    首先確保你已經安裝了gcc包在你的系統上,如果你還沒有安裝gcc,可以使用下面的命令來安裝:
  3.  
    [root@contoso ~] # yum install -y gcc openssl-devel bzip2-devel
  4.  
     
  5.  
    2. 下載 python 2.7. 15
  6.  
    [root@contoso ~] # cd /usr/src
  7.  
    [root@contoso src] # wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
  8.  
    [root@contoso src] # ls
  9.  
    debug kernels Python- 2.7. 15.tgz
  10.  
    [root@contoso src] # tar xzf Python-2.7.15.tgz
  11.  
     
  12.  
    3. 安裝 python 2.7. 15
  13.  
    [root@contoso src] # cd Python-2.7.15
  14.  
    [root@contoso Python- 2.7. 15] # ./configure --enable-optimizations
  15.  
    make altinstall命令用來防止把默認的 2.7. 5版本可執行程序/usr/bin/python覆蓋掉,意思是保留默認版本的python
  16.  
     
  17.  
    4. 查看python版本,python- 2.7. 15和python- 2.7. 5兩個版本都是全局命令
  18.  
    [root@contoso ~] # /usr/bin/python -V
  19.  
    Python 2.7. 5
  20.  
    [root@contoso ~] # python -V
  21.  
    Python 2.7. 5
  22.  
    [root@contoso ~] # /usr/local/bin/python2.7 -V
  23.  
    Python 2.7. 15
  24.  
    [root@contoso ~] # python2.7 -V
  25.  
    Python 2.7. 15
  26.  
     
  27.  
    警告:不要重寫或鏈接默認版Python二進制可執行程序/usr/bin/python,這可能會損壞系統,因為默認版已經與CentOS系統深度集成啦。
  28.  
     
  29.  
    5. 安裝python- 2.7. 15版模塊管理工具
  30.  
    PIP是安裝和管理python模塊的有用工具。讓我們安裝python版的PIP工具。
  31.  
     
  32.  
    [root@contoso Python- 2.7. 15] # curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
  33.  
    [root@contoso Python- 2.7. 15] # python2.7 get-pip.py

[root@contoso ~]# wget https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.7.7/bin/rabbitmqadmin

[root@contoso ~]# mv rabbitmqadmin /usr/local/bin/

[root@contoso ~]# chmod 755 /usr/local/bin/rabbitmqadmin

[root@contoso ~]# rabbitmqadmin --help
Usage
=====
  rabbitmqadmin [options] subcommand

Options
=======
--help, -h              show this help message and exit
--config=CONFIG, -c CONFIG
                        configuration file [default: ~/.rabbitmqadmin.conf]
--node=NODE, -N NODE    node described in the configuration file [default:
                        'default' only if configuration file is specified]
--host=HOST, -H HOST    connect to host HOST [default: localhost]
--port=PORT, -P PORT    connect to port PORT [default: 15672]
--path-prefix=PATH_PREFIX
                        use specific URI path prefix for the RabbitMQ HTTP
                        API. /api and operation path will be appended to it.
                        (default: blank string) [default: ]
--vhost=VHOST, -V VHOST
                        connect to vhost VHOST [default: all vhosts for list,
                        '/' for declare]
--username=USERNAME, -u USERNAME
                        connect using username USERNAME [default: guest]
--password=PASSWORD, -p PASSWORD
                        connect using password PASSWORD [default: guest]
--base-uri=URI, -U URI  connect using a base HTTP API URI. /api and operation
                        path will be appended to it. Path will be ignored.
                        --vhost has to be provided separately.
--quiet, -q             suppress status messages [default: True]
--ssl, -s               connect with ssl [default: False]
--ssl-key-file=SSL_KEY_FILE
                        PEM format key file for SSL
--ssl-cert-file=SSL_CERT_FILE
                        PEM format certificate file for SSL
--ssl-ca-cert-file=SSL_CA_CERT_FILE
                        PEM format CA certificate file for SSL
--ssl-disable-hostname-verification
                        Disables peer hostname verification
--ssl-insecure, -k      Disables all SSL validations like curl's '-k' argument
--format=FORMAT, -f FORMAT
                        format for listing commands - one of [raw_json, long,
                        pretty_json, kvp, tsv, table, bash] [default: table]
--sort=SORT, -S SORT    sort key for listing queries
--sort-reverse, -R      reverse the sort order
--depth=DEPTH, -d DEPTH
                        maximum depth to recurse for listing tables [default:
                        1]
--bash-completion       Print bash completion script [default: False]
--version               Display version and exit

More Help
=========

For more help use the help subcommand:

  rabbitmqadmin help subcommands  # For a list of available subcommands
  rabbitmqadmin help config       # For help with the configuration file
[root@contoso ~]#

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM