1. 程式人生 > >openstack搭建--2--控制節點安裝mysql和rabbitmq

openstack搭建--2--控制節點安裝mysql和rabbitmq



安裝和配置mariadb

大多數 OpenStack 服務使用 SQL 資料庫來儲存資訊。 典型地,資料庫執行在控制節點上。OpenStack 服務也支援其他 SQL 資料庫,包括PostgreSQL
安裝下面3個包。
[[email protected] ~]# yum install mariadb-5.5.52-1.el7.x86_64  -y
[[email protected] ~]# yum install mariadb-server-5.5.52-1.el7.x86_64  -y
[[email protected] ~]# yum install  python2-PyMySQL -y

配置mysql:
[
[email protected]
~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[[email protected] ~]# vi /etc/my.cnf
[mysqld]
default-storage-engine = innodb   預設儲存引擎innodb innodb_file_per_table        設定獨享的表空間,如果不設定,會是共享表空間 collation-server = utf8_general_ci     校對規則 init-connect =
'SET NAMES utf8'    連結字符集 character-set-server = utf8         資料庫建庫字符集 max_connections = 4096      最大連線數 bind-address = 0.0.0.0         mysql監聽地址
[[email protected] ~]# systemctl enable mariadb.service   #Centos7裡面mysql叫maridb

[[email protected] ~]# systemctl start mariadb.service
[[email protected]
~]# 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!
[[email protected] ~]#

Openstack元件建庫和授權

建庫和授權,之前說過,除了Horizon,其它元件都用到了資料庫。 可以在安裝響應元件之前建庫和授權。

這裡我們提前建好,複製下面語句,直接在命令列執行即可,注意root密碼根據自己的密碼。

這裡M版本的openstack,除了新建nova庫,還需要新建一個nova_api庫。



建立資料庫
[[email protected] ~]# 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. 安裝包:
[[email protected] ~]# yum install rabbitmq-server  -y

2. 啟動訊息佇列服務並將其配置為隨系統啟動:

[[email protected] ~]# 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.
[[email protected] ~]# systemctl start rabbitmq-server.service

3. 新增 openstack 使用者,並設定密碼(這裡我實驗環境設定密碼也是openstack):

[[email protected] ~]# rabbitmqctl add_user openstack openstack
Creating user "openstack" ...

4. 給openstack使用者配置寫和讀許可權:

[[email protected] ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*"
Setting permissions for user "openstack" in vhost "/" ...

5.檢視埠:rabbitmq的埠是5672

[[email protected] ~]# 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          
[[email protected] ~]#

6.rabbitmq預設帶了個web的外掛,可以通過web來看rabbit的狀態,它有下面這麼多外掛,列出rabbitmq的外掛:

[[email protected] ~]# rabbitmq-plugins list #檢視支援的外掛
Configured: E = explicitly enabled; e = implicitly enabled
 | Status:   * = running on [email protected]
 |/
[  ] 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的管理外掛
[[email protected] ~]# 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 [email protected] started 6 plugins.

8.重新啟動rabbitmq:
[[email protected] ~]# systemctl restart rabbitmq-server.service

9.再次檢視監聽的埠
[[email protected] ~]# 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 的監控