系统版本

CentOS Linux release 7.2.1511 (Core)

MySQL安装

一、下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

二、安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个MySQL的yum repo源:

/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo

三、安装mysql

sudo yum install mysql-server

四、启动MySQL

systemctl start mysql.service
# 开机自启动
systemctl enable mysql.service

五、修改MySQL默认密码

MySQL默认ROOT密码为空,修改为123456

mysqladmin -uroot password '123456'

Redis安装

一、Download, extract and compile Redis with:

wget http://download.redis.io/releases/redis-3.2.4.tar.gz
tar xzf redis-3.2.4.tar.gz
cd redis-3.2.4
make

二、启动redis:

nohup src/redis-server &

三、做个软链:

ln -s src/redis-cli /usr/bin/
ln -s src/redis-server /usr/bin

四、验证一下:

src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

RabbitMQ安装

运行用户:rabbitmq

YUM配置

wget https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
rpm -Uvh epel-release-7-8.noarch.rpm

安装软件包

yum -y install erlang librabbitmq* rabbitmq-server.noarch

修改ulimit配置

echo '''* soft nofile 655350
* hard nofile 655350
* soft stack 10240
* hard stack 10240
* soft nproc 655350
* hard nproc 655350''' >> /etc/security/limits.conf

修改配置

[root@A08-R16-I255-82 rabbitmq]# cat /etc/rabbitmq/rabbitmq.config
[
{rabbit, [{cluster_nodes, {['rabbit@A08-R16-I255-82.SQ01.SQGOV.LOCAL', 'rabbit@A08-R16-I255-83.SQ01.SQGOV.LOCAL', 'rabbit@A08-R16-I255-84.SQ01.SQGOV.LOCAL'], disc}},
{cluster_partition_handling, pause_minority}]},
{kernel, [{inet_dist_listen_min, 9100},{inet_dist_listen_max, 9200}]},
{rabbitmq_management, [{listener, [{port, 15672}, {ip, "10.239.253.82"}]}]}
]
[root@A08-R16-I255-82 ~]# cat /etc/rabbitmq/rabbitmq-env.conf
ERL_EPMD_ADDRESS=10.239.253.82
ERL_EPMD_PORT=4369
HOME=/export/rabbitmq
SNAME=rabbit
RABBITMQ_NODE_IP_ADDRESS=10.239.253.82
RABBITMQ_NODE_PORT=5672
HOSTNAME=A08-R16-I255-82.SQ01.SQGOV.LOCAL
RABBITMQ_NODENAME=rabbit@A08-R16-I255-82
RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq.config
RABBITMQ_MNESIA_BASE=/export/rabbitmq
RABBITMQ_MNESIA_DIR=/export/rabbitmq/mnesia
RABBITMQ_PLUGINS_DIR=/export/rabbitmq/plugins
RABBITMQ_LOG_BASE=/export/log/rabbitmq
RABBITMQ_USE_LONGNAME=true
另外两台服务器的配置修改一下IP和主机名就可以

创建相关目录

mkdir -p /export/rabbitmq/{mnesia,plugins} && chown rabbitmq.rabbitmq /export/rabbitmq -R
mkdir -p /export/log/rabbitmq && chown rabbitmq.rabbitmq /export/log/rabbitmq -R

启动rabbitmq服务

systemctl start rabbitmq-server.service

启用rabbitmq web管理插件

rabbitmq-plugins enable rabbitmq_management

RabbitMQ集群配置

PreDeploy

  1. 确保各节点已安装好 erlang、RabbitMQ.
  2. 修改hosts文件:
192.168.1.1 rabbit1
192.168.1.2 rabbit2
192.168.1.3 rabbit3

Rabbitmq的集群是依赖于erlang的集群来工作的,所以必须先构建起erlang的集群环境。

Erlang的集群中各节点是通过一个magic cookie来实现的,这个cookie存放在 /var/lib/rabbitmq/.erlang.cookie 中,文件是400的权限。

所以必须保证各节点cookie保持一致,否则节点之间就无法通信。

cat /var/lib/rabbitmq/.erlang.cookie
chown -R rabbitmq.rabbitmq /var/lib/rabbitmq/.erlang.cookie

停止所有节点RabbitMQ服务,然后使用detached参数独立运行:

# 在所有节点上都要执行
rabbitmqctl stop
rabbitmq-server -detached

组建集群:将node2、node3与node1组成集群

rabbit2 # rabbitmqctl stop_app
rabbit2 # rabbitmqctl join_cluster rabbit@rabbit1 # 此处组建集群不成功,把rabbit1改成本机默认的hostname即可。
rabbit2 # rabbitmqctl start_app
rabbit3 # rabbitmqctl stop_app
rabbit3 # rabbitmqctl join_cluster rabbit@rabbit1
rabbit3 # rabbitmqctl start_app

此时 node2 与 node3 也会自动建立连接;

# 在每个节点上查看集群各节点状态:
rabbitmqctl cluster_status

设置镜像队列策略,在任意节点上执行,如果不设置默认为集群策略:

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

将所有队列设置为镜像队列,即队列会被复制到各个节点,各个节点状态保持一致。

到此为止,RabbitMQ 高可用集群就已经搭建完成。

账号管理

添加普通账号(仅有生产和消费权限)

rabbitmqctl add_user username userpassword

设置角色

rabbitmqctl set_user_tags jdcloud administrator

设置权限

rabbitmqctl set_permissions -p '/' jcloud ".*" ".*" ".*"

在任何节点添加,然后会自动同步到集群其它节点

设置开机启动

systemctl enable rabbitmq-server.service

关于节点类型(ram |disk)

创建RAM节点

rabbit2# rabbitmqctl stop_app
Stopping node rabbit@rabbit2 ...done.
rabbit2# rabbitmqctl join_cluster --ram rabbit@rabbit1
Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done.
rabbit2# rabbitmqctl start_app
Starting node rabbit@rabbit2 ...done.

修改节点类型

rabbit2# rabbitmqctl stop_app
Stopping node rabbit@rabbit2 ...done.
rabbit2# rabbitmqctl change_cluster_node_type disc
Turning rabbit@rabbit2 into a disc node ...
...done.
Starting node rabbit@rabbit2 ...done.
rabbit1# rabbitmqctl stop_app
Stopping node rabbit@rabbit1 ...done.
rabbit1# rabbitmqctl change_cluster_node_type ram
Turning rabbit@rabbit1 into a ram node ...
rabbit1# rabbitmqctl start_app
Starting node rabbit@rabbit1 ...done.

安装HAProxy负载均衡器

yum install haproxy

修改配置文件:

/etc/haproxy/haproxy.cfg

defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000 listen rabbitmq_cluster 0.0.0.0:5672
mode tcp
balance roundrobin
server rqslave1 172.16.3.107:5672 check inter 2000 rise 2 fall 3
server rqslave2 172.16.3.108:5672 check inter 2000 rise 2 fall 3
server rqmaster 172.16.3.32:5672 check inter 2000 rise 2 fall 3

负载均衡器会监听5672端口,轮询我们的两个内存节点172.16.3.107、172.16.3.108的5672端口,172.16.3.32为磁盘节点,只做备份不提供给生产者、消费者使用,当然如果我们服务器资源充足情况也可以配置多个磁盘节点,这样磁盘节点除了故障也不会影响,除非同时出故障。

重启集群节点

Nodes that have been joined to a cluster can be stopped at any time. It is also ok for them to crash. In both cases the rest of the cluster continues operating unaffected, and the nodes automatically "catch up" with the other cluster nodes when they start up again.

We shut down the nodes rabbit@rabbit1 and rabbit@rabbit3 and check on the cluster status at each step:

rabbit1# rabbitmqctl stop
Stopping and halting node rabbit@rabbit1 ...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit3,rabbit@rabbit2]}]
...done.
rabbit3# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit3 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit3]}]
...done.
rabbit3# rabbitmqctl stop
Stopping and halting node rabbit@rabbit3 ...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit2]}]
...done.
Now we start the nodes again, checking on the cluster status as we go along:
rabbit1# rabbitmq-server -detached
rabbit1# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}]
...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}]
...done.
rabbit3# rabbitmq-server -detached
rabbit1# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit1,rabbit@rabbit3]}]
...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]
...done.
rabbit3# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit3 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit1,rabbit@rabbit3]}]
...done.

There are some important caveats:

When the entire cluster is brought down, the last node to go down must be the first node to be brought online. If this doesn't happen, the nodes will wait 30 seconds for the last disc node to come back online, and fail afterwards. If the last node to go offline cannot be brought back up, it can be removed from the cluster using the forget_cluster_node command - consult the rabbitmqctl manpage for more information.

If all cluster nodes stop in a simultaneous and uncontrolled manner (for example with a power cut) you can be left with a situation in which all nodes think that some other node stopped after them. In this case you can use the force_boot command on one node to make it bootable again - consult the rabbitmqctl manpage for more information.

Breaking up a cluster

Nodes need to be removed explicitly from a cluster when they are no longer meant to be part of it. We first remove rabbit@rabbit3 from the cluster, returning it to independent operation. To do that, on rabbit@rabbit3 we stop the RabbitMQ application, reset the node, and restart the RabbitMQ application.

rabbit3# rabbitmqctl stop_app
Stopping node rabbit@rabbit3 ...done.
rabbit3# rabbitmqctl reset
Resetting node rabbit@rabbit3 ...done.
rabbit3# rabbitmqctl start_app
Starting node rabbit@rabbit3 ...done.
Note that it would have been equally valid to list rabbit@rabbit3 as a node.
Running the cluster_status command on the nodes confirms that rabbit@rabbit3 now is no longer part of the cluster and operates independently:
rabbit1# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},
{running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}]
...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},
{running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}]
...done.
rabbit3# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit3 ...
[{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}]
...done.
We can also remove nodes remotely. This is useful, for example, when having to deal with an unresponsive node. We can for example remove rabbit@rabbi1 from rabbit@rabbit2.
rabbit1# rabbitmqctl stop_app
Stopping node rabbit@rabbit1 ...done.
rabbit2# rabbitmqctl forget_cluster_node rabbit@rabbit1
Removing node rabbit@rabbit1 from cluster ...
...done.
Note that rabbit1 still thinks its clustered with rabbit2, and trying to start it will result in an error. We will need to reset it to be able to start it again.
rabbit1# rabbitmqctl start_app
Starting node rabbit@rabbit1 ...
Error: inconsistent_cluster: Node rabbit@rabbit1 thinks it's clustered with node rabbit@rabbit2, but rabbit@rabbit2 disagrees
rabbit1# rabbitmqctl reset
Resetting node rabbit@rabbit1 ...done.
rabbit1# rabbitmqctl start_app
Starting node rabbit@mcnulty ...
...done.
The cluster_status command now shows all three nodes operating as independent RabbitMQ brokers:
rabbit1# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit1 ...
[{nodes,[{disc,[rabbit@rabbit1]}]},{running_nodes,[rabbit@rabbit1]}]
...done.
rabbit2# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit2 ...
[{nodes,[{disc,[rabbit@rabbit2]}]},{running_nodes,[rabbit@rabbit2]}]
...done.
rabbit3# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit3 ...
[{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}]
...done.
Note that rabbit@rabbit2 retains the residual state of the cluster, whereas rabbit@rabbit1 and rabbit@rabbit3 are freshly initialised RabbitMQ brokers. If we want to re-initialise rabbit@rabbit2 we follow the same steps as for the other nodes:
rabbit2# rabbitmqctl stop_app
Stopping node rabbit@rabbit2 ...done.
rabbit2# rabbitmqctl reset
Resetting node rabbit@rabbit2 ...done.
rabbit2# rabbitmqctl start_app
Starting node rabbit@rabbit2 ...done.

CentOS7安装MySQL、Redis、RabbitMQ的更多相关文章

  1. CentOS7安装mysql提示“No package mysql-server available.”

    针对centos7安装mysql,提示"No package mysql-server available."错误,解决方法如下: Centos 7 comes with Mari ...

  2. [CentOs7]安装mysql(2)

    摘要 之前安装过一次mysql,最后配置,发现在本地无法连接,重启服务的时候一直卡在那里不动,感觉是安装的过程出问题,最后没办法还是卸载了,然后重新安装一下. [CentOs7]安装mysql Mys ...

  3. centos7安装mysql

    centos7安装mysql 1 查找系统是否安装了myql rpm -q mysql mysql-server1.1如果安装了.就删除 sudo yum -y remove mysql mysql- ...

  4. centos7安装mysql(yum)

    centos7安装mysql(yum) ----安装环境----依赖安装----检查mysql是否已安装----安装----验证是否添加成功----选择要启用的mysql版本----通过Yum安装my ...

  5. CentOS7安装MySQL的方法之通用二进制格式

      CentOS7安装MySQL的方法之通用二进制格式          

  6. CentOS7安装MySQL的方法之RPM包方式

        CentOS7安装MySQL的方法之RPM包方式        

  7. 新服务器搭建-总结: 下载nginx,jdk8,docker-compose编排(安装mysql,redis) 附安装

    三明SEO: 前言 如题, 公司新买了一条4核16G的服务器, 不得不重新搭建环境, 只能一一重来, 做个记录 1.nginx : 手动安装 2.jdk8: 手动安装 3. 安装docker 及doc ...

  8. centos7安装Mysql爬坑记录

    centos7安装Mysql爬坑记录   查看是否已安装 使用下列命令查看是否已经安装过mysql/mariadb/PostgreSQL 如果未安装,不返回任何结果(ECS的centos镜像默认未安装 ...

  9. IDEA SpringBoot+JPA+MySql+Redis+RabbitMQ 秒杀系统

    先放上github地址:spike-system,可以直接下载完整项目运行测试 SpringBoot+JPA+MySql+Redis+RabbitMQ 秒杀系统 技术栈:SpringBoot, MyS ...

  10. Centos7 安装mysql服务器并开启远程访问功能

    大二的暑假,波波老师送了一个华为云的服务器给我作测试用,这是我程序员生涯里第一次以root身份拥有一台真实的云服务器 而之前学习的linux知识在这时也派上了用场,自己的物理机用的是ubuntu系统, ...

随机推荐

  1. 深入理解和应用display属性(二)

    四.inline-block 此类元素是inline + block的合体 1) margin和padding都有效:width和height都有效: .inline{ display: inline ...

  2. 关于WEB 性能优化 (摘抄)

    压缩源代码和图片 JavaScript文件源代码可以采用混淆压缩的方式,CSS文件源代码进行普通压缩,JPG图片可以根据具体质量来压缩为50%到70%,PNG可以使用一些开源压缩软件来压缩,比如24色 ...

  3. 编写可维护的CSS

    在参与规模庞大.历时漫长且参与人数众多的项目时,所有开发者遵守如下规则极为重要: 保持 CSS 便于维护 保持代码清晰易懂 保持代码的可拓展性 为了实现这一目标,我们要采用诸多方法. 本文档第一部分将 ...

  4. ECharts外部调用保存为图片操作及工作流接线mouseenter和mouseleave由于鼠标移动速度过快导致问题解决办法

    记录两个项目开发中遇到的问题,一个是ECharts外部调用保存为图片操作,一个是workflow工作流连接曲线onmouseenter和onmouseleave事件由于鼠标移动过快触发问题. 一.外部 ...

  5. iOS 如何获取屏幕大小

    UIScreen *currentScreen = [UIScreen mainScreen]; NSLog(@"applicationFrame.size.height = %f" ...

  6. 列表屏幕(List Screen)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  7. Android 窗体设置

    requestWindowFeature(Window.FEATURE_NO_TITLE);  getWindow().setFlags(WindowManager.LayoutParams.FLAG ...

  8. CoreData

    之前在学习使用SQLite时, 需要编写大量的sql语句,完成数据的增删改查,但对于不熟悉sql语句的开发人员来说,难度较大,调试程序比较困难. 由此出现CoreData框架,将sql的操作转换成为对 ...

  9. iOS 疑难杂症 — — Swift debugger 无法在控制台 po 变量值的问题

    前言 这个问题出现有好几个月了,一直没弄,以为是 Xcode 的问题后面版本升级应该就能好所以就不管了,今天心情好顺便查了一下. 声明  欢迎转载,但请保留文章原始出处:)  博客园:http://w ...

  10. IOS-WebViewJavascriptBridge使用说明

    下面来说一下WebViewJavascriptBridge在ios端怎么样使用. 首先确保一份已经配好功能的html文件. 1.初始化一个webview(viewdidload) UIWebView* ...