wget http://www.erlang.org/download/otp_src_20.0.tar.gz
# 解压到习惯目录
tar -zxvf otp_src_20.0.tar.gz -C /usr/local/
# 修改名字
mv otp_src_20.0 erlang
# 安装erlang需要的依赖包
yum -y install gcc glibc-devel make ncurses-devel openssl openssl-devel autoconf gcc-c++ kernel-devel m4 unixODBC unixODBC-devel wxGTK wxGTK-devel fop libxslt libxslt-devel
# 进入目录
cd erlang
# 指定安装的目录和相关的配置
./configure --prefix=/usr/local/erlang --enable-gui=no --enable-threads --enable-smp-support --enable-kernel-poll --enable-native-libs --enable-hipe --without-javac
# 如果没有报错,或只出现没有 wx not found和Java compiler disabled by user是正常的
make & make install
如果出现错误如“没有目标创建XXXXX”,找到进入的目录如果是hipe目录,就在配置中增加:
./configure --prefix=/usr/local/erlang --enable-XXXXX # XXXX 表示报错的目录,一般是权限的问题;
本人习惯将安装文件和源文件放在一个大目录下,如erlang,这样当需要卸载的时候直接删除这个目录就行了;
apt安装
sudo apt update
apt install erlang
默认安装的客户端是在/usr/local/erlang/bin下的
cd /usr/local/erlang/bin
# 输入./erl,如果出现交互界面则成功了
链接和环境变量
# 创建一个软连接到系统路径中
ln -s /usr/local/erlang/bin/erl /usr/bin/erl
rabbitMQ的安装和使用
cd /usr/local
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-generic-unix-3.6.10.tar.xz
xz -d rabbitmq-server-generic-unix-3.6.10.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.6.10.tar
# 重新命名
mv rabbitmq_server-3.6.10 rabbitmq_server
# 进入文件目录,这已经算是安装好的文件了
相关的使用的命令都在sbin目录中,将sbin目录添加到系统环境变量;
vi /etc/profile
# 在文件的末尾添加
#set rabbitmq
export PATH=$PATH:/usr/local/rabbitmq_server/sbin
配置开机自启动
在/etc/rc.d/rc.local文件中加入启动命令
vi /etc/rc.d/rc.local
# start rabbitmq
/usr/local/rabbitmq_server/sbin/rabbitmq-server -detached
reboot # 重启测试一下
使用sysv-rc-conf管理
apt intsall sysv-rc-conf
vi rabbitmq.service
# start rabbitmq
/usr/local/rabbitmq_server/sbin/rabbitmq-server -detached
chmod 755 rabbitmq.service
# 将本脚本放置在/etc/init.d目录下
sysv-rc-conf打开管理界面添加权限。
如果无法启动可能有一下的原因:
可能是权限问题,你需要切换到root账户执行操作;
主机名问题,rabbitmq会在启动前会解析主机名的地址是否可通,需要添加主机名;
vi /etc/hosts
127.0.0.1 hostname
apt安装
apt install rabbitmq-server
apt安装后rabbitmq-server会自动启动。rabbitmq的安装文件目录在/usr/local/rabbitmq,启动文件在/etc/init.d/rabbitmq-server,命令行目录在/usr/sbin/rabbitmmq.
# /etc/init.d/rabbitmq-server
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=rabbitmq-server
DAEMON=/usr/sbin/${NAME} # 守护进程的路径
CONTROL=/usr/sbin/rabbitmqctl # 客户端路径
DESC="RabbitMQ Messaging Server"
USER=rabbitmq
ROTATE_SUFFIX=
INIT_LOG_DIR=/var/log/rabbitmq # 日志路径
PID_FILE=/var/run/rabbitmq/pid # 进程文件路径
rabbitmq的组件
rabbitmq的组件放置在~/bin目录下,我们进入可以看到:
rabbitmqctl : rabbitmq的客户端,用来连接管理rabbitmq;
rabbitmq-env :配置环境变量的管理者;
rabbitmq-plugins:rabbitmq后台插件管理;
rabbitmq-server: rabbitmq守护进程;
rabbitmq的管理
rabbitmq使用rabbitmqctl管理,常用的命令有:
rabbitmq-server -detached # 使用守护进程方式启动
rabbitmq-server start # 使用阻塞方式启动
rabbitmqctl stop # 关闭rabbitmq
rabbitmqctl list_users # 查看后台管理员名单
rabbitmqctl list_queues # 查看当前的所有的队列
rabbitmqctl list_exchanges # 查看所有的交换机
rabbitmqctl list_bindings # 查看所有的绑定
rabbitmqctl list_connections # 查看所有的tcp连接
rabbitmqctl list_channels # 查看所有的信道
rabbitmqctl stop_app # 关闭应用
rabbitmqctl start_app # 打开应用
rabbitmqctl reset # 清空队列
查看状态信息
rabbitmqctl status
# 得到如下的信息
[{pid,3086}, # rabbitmq服务运行的进程ID
{running_applications,
[{rabbit,"RabbitMQ","3.6.10"},
{ranch,"Socket acceptor pool for TCP protocols.","1.3.0"},
{ssl,"Erlang/OTP SSL application","8.2"},
{public_key,"Public key infrastructure","1.4.1"},
{asn1,"The Erlang ASN1 compiler version 5.0","5.0"},
{os_mon,"CPO CXC 138 46","2.4.2"},
{rabbit_common,
"Modules shared by rabbitmq-server and rabbitmq-erlang-client",
"3.6.10"},
{syntax_tools,"Syntax tools","2.1.2"},
{xmerl,"XML parser","1.3.15"},
{crypto,"CRYPTO","4.0"},
{mnesia,"MNESIA CXC 138 12","4.15"},
{compiler,"ERTS CXC 138 10","7.1"},
{sasl,"SASL CXC 138 11","3.0.4"},
{stdlib,"ERTS CXC 138 10","3.4"},
{kernel,"ERTS CXC 138 10","5.3"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe] [kernel-poll:true]\n"},
{memory, # 内存
[{total,56444960}, # 总共消耗的内存,单位字节
{connection_readers,0}, # tcp订阅连接消耗
{connection_writers,0}, # tcp发布者连接消耗
{connection_channels,0}, # 信道消耗
{connection_other,0}, # 其他消耗
{queue_procs,2840}, # 队列进程消耗
{queue_slave_procs,0}, # 队列子进程消耗
{plugins,0}, # 插件消耗
{other_proc,22726336}, # 其他进程消耗
{mnesia,60944},
{metrics,184544},
{mgmt_db,0},
{msg_index,45048}, # 消息标记
{other_ets,1695784},
{binary,94472}, # 一些被引用的数据
{code,21374813}, # 代码
{atom,891849},
{other_system,9549962}]},
{alarms,[]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]}, # mq监听端口5672,erlang端口25672
{vm_memory_high_watermark,0.4}, # 开启流控的内存阀值
{vm_memory_limit,6568098201}, # 消息持久化阀值
{disk_free_limit,50000000}, # 磁盘开启流控阀值
{disk_free,48187891712}, # 磁盘空闲量
{file_descriptors, # 文件句柄
[{total_limit,924}, # 文件句柄上限
{total_used,2}, # 已使用
{sockets_limit,829}, # 允许的TCP连接上限
{sockets_used,0}]}, # 已使用连接数
{processes,
[{limit,1048576}, # 允许的最大进程数
{used,156}]}, # 已使用进程数
{run_queue,0}, # 运行的队列数
{uptime,97},
{kernel,{net_ticktime,60}}]