您的位置:首页 > 数据库 > SQL

openstack搭建--2--控制节点安装mysql和rabbitmq

2017-07-30 10:53 459 查看
生产中可以把mysql数据库单独安装到一台机器上,这里因为实验机器有限,就把mysql安装到了控制节点

其实openstack每个组件都可以安装到单独的机器上。

RabbitMQ介绍

RabbitMQ是一个消息队列产品

MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。

消息传递指的是程序之间通过在消息中发送数据进行通信,而不是通过直接调用彼此来通信,直接调用通常是用于诸如远程过程调用的技术。排队指的是应用程序通过 队列来通信。

队列的使用除去了接收和发送应用程序同时执行的要求

MQ是消费-生产者模型的一个典型的代表,一端往消息队列中不断写入消息,而另一端则可以读取或者订阅队列中的消息。

消息队列让程序做到异步处理,而这种异步处理的方式大大的节省了服务器的请求响应时间,从而提高了系统的吞吐量。

使用rabbitmq最多的一个子项目是nova
 
除了控制面板Dashboard的Horizon没用到mysql,其余组件都需要连接mysql,因此mysql数据尤为重要,生产中要做好主从以及备份



安装和配置mariadb

大多数 OpenStack 服务使用 SQL 数据库来存储信息。 典型地,数据库运行在控制节点上。OpenStack 服务也支持其他 SQL 数据库,包括PostgreSQL

安装下面3个包。

[root@node1 ~]# yum install mariadb-5.5.52-1.el7.x86_64  -y

[root@node1 ~]# yum install mariadb-server-5.5.52-1.el7.x86_64  -y

[root@node1 ~]# yum install  python2-PyMySQL -y

配置mysql:

[root@node1 ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

cp: overwrite ‘/etc/my.cnf’? y

[root@node1 ~]# vi /etc/my.cnf

[mysqld]

[root@node1 ~]# systemctl enable mariadb.service   #Centos7里面mysql叫maridb

[root@node1 ~]# systemctl start mariadb.service

[root@node1 ~]# mysql_secure_installation    #设置密码及初始化

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y

 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

[root@node1 ~]#

Openstack组件建库和授权

建库和授权,之前说过,除了Horizon,其它组件都用到了数据库。 可以在安装响应组件之前建库和授权。

这里我们提前建好,复制下面语句,直接在命令行执行即可,注意root密码根据自己的密码。

这里M版本的openstack,除了新建nova库,还需要新建一个nova_api库。

创建数据库

[root@node1 ~]# mysql -p mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 16

Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE keystone;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'keystone';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CREATE DATABASE glance;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>  CREATE DATABASE nova;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CREATE DATABASE nova_api;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> CREATE DATABASE neutron;

Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]>  GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'neutron';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'neutron';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| glance             |

| keystone           |

| mysql              |

| neutron            |

| nova               |

| nova_api           |

| performance_schema |

+--------------------+

8 rows in set (0.00 sec)

安装和配置RabbitMQ

OpenStack 使用 message queue 协调操作和各服务的状态信息。消息队列服务一般运行在控制节点上。OpenStack支持好几种消息队列服务包括 RabbitMQ, Qpid, 和 ZeroMQ。

不过,大多数发行版本的OpenStack包支持特定的消息队列服务。本指南安装 RabbitMQ 消息队列服务,因为大部分发行版本都支持它。

1. 安装包:

[root@node1 ~]# yum install rabbitmq-server  -y
2. 启动消息队列服务并将其配置为随系统启动:

[root@node1 ~]# systemctl enable rabbitmq-server.service

Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.

[root@node1 ~]# systemctl start rabbitmq-server.service

3. 添加 openstack 用户,并设置密码(这里我实验环境设置密码也是openstack):

[root@node1 ~]# rabbitmqctl add_user openstack openstack

Creating user "openstack" ...
4. 给openstack用户配置写和读权限:

[root@node1 ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*"

Setting permissions for user "openstack" in vhost "/" ...

5.查看端口:rabbitmq的端口是5672

[root@node1 ~]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      14396/mysqld        

tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      1/systemd           

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1057/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1610/master         

tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      14635/beam          

tcp6       0      0 :::22                   :::*                    LISTEN      1057/sshd           

tcp6       0      0 ::1:25                  :::*                    LISTEN      1610/master         

tcp6       0      0 :::5672                 :::*                    LISTEN      14635/beam          

[root@node1 ~]#

6.rabbitmq默认带了个web的插件,可以通过web来看rabbit的状态,它有下面这么多插件,列出rabbitmq的插件:

[root@node1 ~]# rabbitmq-plugins list #查看支持的插件

Configured: E = explicitly enabled; e = implicitly enabled

 | Status:   * = running on rabbit@node1

 |/

[  ] amqp_client                       3.6.5

[  ] cowboy                            1.0.3

[  ] cowlib                            1.0.1

[  ] mochiweb                          2.13.1

[  ] rabbitmq_amqp1_0                  3.6.5

[  ] rabbitmq_auth_backend_ldap        3.6.5

[  ] rabbitmq_auth_mechanism_ssl       3.6.5

[  ] rabbitmq_consistent_hash_exchange 3.6.5

[  ] rabbitmq_event_exchange           3.6.5

[  ] rabbitmq_federation               3.6.5

[  ] rabbitmq_federation_management    3.6.5

[  ] rabbitmq_jms_topic_exchange       3.6.5

[  ] rabbitmq_management               3.6.5   #使用此插件实现 web 管理

[  ] rabbitmq_management_agent         3.6.5

[  ] rabbitmq_management_visualiser    3.6.5

[  ] rabbitmq_mqtt                     3.6.5

[  ] rabbitmq_recent_history_exchange  1.2.1

[  ] rabbitmq_sharding                 0.1.0

[  ] rabbitmq_shovel                   3.6.5

[  ] rabbitmq_shovel_management        3.6.5

[  ] rabbitmq_stomp                    3.6.5

[  ] rabbitmq_top                      3.6.5

[  ] rabbitmq_tracing                  3.6.5

[  ] rabbitmq_trust_store              3.6.5

[  ] rabbitmq_web_dispatch             3.6.5

[  ] rabbitmq_web_stomp                3.6.5

[  ] rabbitmq_web_stomp_examples       3.6.5

[  ] sockjs                            0.3.4

7.开机自启动rabbitmq的管理插件

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

The following plugins have been enabled:

  mochiweb

  webmachine

  rabbitmq_web_dispatch

  amqp_client

  rabbitmq_management_agent

  rabbitmq_management

Applying plugin configuration to rabbit@node1... started 6 plugins.

8.重新启动rabbitmq:

[root@node1 ~]# systemctl restart rabbitmq-server.service

9.再次查看监听的端口

[root@node1 ~]# lsof -i:15672

访问RabbitMQ,访问地址是http://192.168.1.2:15672

默认用户名密码都是guest,浏览器添加openstack用户到组并登陆测试,连不上情况一般是防火墙没有关闭所致!

10.用guest登陆



11.guest 登陆后界面



rabbitmq在openstack通信过程中扮演通信的交通枢纽的作用,它也是支持集群的
很多地方都用到了它,比如你下完订单,查询订单时提示订单正在处理中,很有可能就是写到了消息队列里,还没写到数据库里面,这样可以缓解数据库压力的问题
双十一,一下订单就写到数据库里,什么数据库也扛不住的。它们就可以使用分布式消息队列
使用消息队列还可以用于分布式的事务,12306很明显就用到消息队列了。订单处理中

12.怎么让openstack也能登陆呢,

     点击Admin



点击openstack这个用户,tags设置为下面这种,密码改成openstack



点击update之后



之后退出使用 openstack 登录

如何使用 zabbix 监控?

左下角有 HTTP API 的介绍,可以实现 zabbix 的监控
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: