OpenStack install MySQL RabbitMQ
2020-05-28虚拟化90root428°c
A+ A-除了Horizon, OpenStack其它组件都需要连接数据库
除了Horizone和KeyStone, 其它组件都需要连接RabbitMQ
一、MySQL
1. 安装MySQL(2台机器都安装)
[[email protected] ~]# useradd -s /sbin/nologin mysql [[email protected] ~]# yum install -y cmake ncurses-devel perl [[email protected] ~]# cd /usr/local/src [[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.32.tar.gz [[email protected] src]# tar zxf mysql-5.6.32.tar.gz [[email protected] mysql-5.6.32]# cd mysql-5.6.32 [[email protected] mysql-5.6.32]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 -DMYSQL_DATADIR=/usr/local/mysql-5.6/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci [[email protected] mysql-5.6.32]# echo $? 0 [[email protected] mysql-5.6.32]# make [[email protected] mysql-5.6.32]# echo $? 0 [[email protected] mysql-5.6.32]# make install [[email protected] mysql-5.6.32]# echo $? 0 [[email protected] mysql-5.6.32]# echo "PATH=$PATH:/usr/local/mysql-5.6/bin" >> /etc/profile [[email protected] mysql-5.6.32]# source /etc/profile [[email protected] mysql-5.6.32]# cd /usr/local/mysql-5.6/scripts [[email protected] scripts]# ./mysql_install_db --basedir=/usr/local/mysql-5.6 --datadir=/usr/local/mysql-5.6/data --user=mysql [[email protected] scripts]# echo $? 0 [[email protected] scripts]# cp /usr/local/mysql-5.6/my.cnf /etc/my.cnf [[email protected] scripts]# sed -i '/^\[mysqld\]$/a\user = mysql\ndatadir = /usr/local/mysql-5.6/data\ndefault_storage_engine = InnoDB\n' /etc/my.cnf [[email protected] scripts]# cp /usr/local/mysql-5.6/support-files/mysql.server /etc/init.d/mysqld [[email protected] scripts]# sed -i 's#^datadir=#datadir=/usr/local/mysql-5.6/data#' /etc/init.d/mysqld [[email protected] scripts]# sed -i 's#^basedir=#basedir=/usr/local/mysql-5.6#' /etc/init.d/mysqld [[email protected] scripts]# chown -R mysql:mysql /usr/local/mysql-5.6/data [[email protected] scripts]# chown -R mysql:mysql /usr/local/mysql-5.6 [[email protected] scripts]# chkconfig --add mysqld [[email protected] scripts]# chkconfig mysqld on [[email protected] scripts]# /etc/init.d/mysqld start [[email protected] scripts]# netstat -anpt | grep "3306" tcp 0 0 :::3306 :::* LISTEN 5081/mysqld
2. 配置MySQL
[[email protected] ~]# cat /etc/my.cnf [mysqld] ### 以下内容为新增 default-storage-engine = innodb innodb_file_per_table collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 server-id= 11 log-slave-updates log-bin= /usr/local/mysql-5.6/data/mysql-bin [[email protected] ~]# /etc/init.d/mysqld restart [[email protected] ~]# cat /etc/my.cnf [mysqld] ### 以下内容为新增 default-storage-engine = innodb innodb_file_per_table collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 server-id= 12 log-slave-updates log-bin= /usr/local/mysql-5.6/data/mysql-bin [[email protected]_215 ~]# /etc/init.d/mysqld restart
3. 设置mysql root 密码
[[email protected] ~]# mysqladmin -u root password openstack
4. 搭建主主复制生产环境做高可用和主主复制
4.1 node1节点数据库授权主主账号
[[email protected] ~]# mysql -uroot -popenstack mysql> grant replication slave,reload,super on *.* to 'slave'@'192.168.15.%' identified by 'openstack'; mysql> flush privileges; mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 425 | | | | +------------------+----------+--------------+------------------+-------------------+
4.2 node2节点配置主主复制
[[email protected] ~]# mysql -uroot -popenstack mysql> change master to master_host='192.168.15.11',master_port=3306,master_user='slave',master_password='openstack',MASTER_LOG_FILE='mysql-bin.000001',master_log_pos=425; mysql> start slave; mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.15.11 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 425 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 588 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 425 Relay_Log_Space: 762 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 214 Master_UUID: 5c036911-71aa-11e6-96e2-a6e86f19c264 Master_Info_File: /usr/local/mysql-5.6/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 639 | | | | +------------------+----------+--------------+------------------+-------------------+
4.3. node1节点配置主主复制
[[email protected] ~]# mysql -uroot -popenstack mysql> change master to master_host='192.168.15.12' ,master_port=3306,master_user='slave',master_password='openstack',MASTER_LOG_FILE='mysql-bin.000001',master_log_pos=639; mysql> start slave; mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.15.12 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 639 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 283 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 639 Relay_Log_Space: 457 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 215 Master_UUID: 0a35bf4a-71d2-11e6-971f-9afa43b76c9a Master_Info_File: /data/local/mysql-5.6/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0
4.4 主主复制验证
[[email protected] ~]# mysql -uroot -popenstack mysql> create database 90root; #214节点创建测试数据库90root mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | 90root | | mysql | | performance_schema | | test | +--------------------+ [[email protected]_215 ~]# mysql -uroot -popenstack mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | 90root | | mysql | | performance_schema | | test | +--------------------+ mysql> drop database 90root; #215节点删除测试数据库90root mysql> show databases; #214节点查看数据库 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+
主主复制搭建完成.
5. 创建openstack所需数据库
mysql> create database nova; #创建计算服务数据库 mysql> grant all on nova.* to 'nova'@'192.168.15.%' identified by 'nova'; mysql> create database neutron; #创建网络服务数据库 mysql> grant all on neutron.* to 'neutron'@'192.168.15.%' identified by 'neutron'; mysql> create database keystone; #创建认证服务数据库 mysql> grant all on keystone.* to 'keystone'@'192.168.%' identified by 'keystone'; mysql> create database glance; #创建镜像服务数据库 mysql> grant all on glance.* to 'glance'@'192.168.15.%' identified by 'glance'; mysql> create database cinder; #创建块存储服务数据库 mysql> grant all on cinder.* to 'cinder'@'192.168.15.%' identified by 'cinder'; mysql> flush privileges;
配置了主主复制, 两个节点数据库会保持一致.
二、RabbitMQ安装(控制节点)
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。消息传递指的是程序之间通过在消息中发送数据进行通信,而不是通过直接调用彼此来通信,直接调用通常是用于诸如远程过程调用的技术。
1. yum安装RabbitMQ
[[email protected] ~]# yum -y install erlang rabbitmq-server
2. 启动RabbitMQ
[[email protected] ~]# /etc/init.d/rabbitmq-server start Starting rabbitmq-server: SUCCESS rabbitmq-server. [[email protected] ~]# chkconfig --add rabbitmq-server [[email protected] ~]# chkconfig rabbitmq-server on [[email protected] ~]# netstat -anpt | grep "beam" tcp 0 0 :::5672 :::* LISTEN 2873/beam.smp
3. 启用Web监控插件
[[email protected] ~]# /usr/lib/rabbitmq/bin/rabbitmq-plugins list #查看RabbitMQ所有插件 [ ] amqp_client 3.1.5 [ ] cowboy 0.5.0-rmq3.1.5-git4b93c2d [ ] eldap 3.1.5-gite309de4 [ ] mochiweb 2.7.0-rmq3.1.5-git680dba8 [ ] rabbitmq_amqp1_0 3.1.5 [ ] rabbitmq_auth_backend_ldap 3.1.5 [ ] rabbitmq_auth_mechanism_ssl 3.1.5 [ ] rabbitmq_consistent_hash_exchange 3.1.5 [ ] rabbitmq_federation 3.1.5 [ ] rabbitmq_federation_management 3.1.5 [ ] rabbitmq_jsonrpc 3.1.5 [ ] rabbitmq_jsonrpc_channel 3.1.5 [ ] rabbitmq_jsonrpc_channel_examples 3.1.5 [ ] rabbitmq_management 3.1.5 [ ] rabbitmq_management_agent 3.1.5 [ ] rabbitmq_management_visualiser 3.1.5 [ ] rabbitmq_mqtt 3.1.5 [ ] rabbitmq_shovel 3.1.5 [ ] rabbitmq_shovel_management 3.1.5 [ ] rabbitmq_stomp 3.1.5 [ ] rabbitmq_tracing 3.1.5 [ ] rabbitmq_web_dispatch 3.1.5 [ ] rabbitmq_web_stomp 3.1.5 [ ] rabbitmq_web_stomp_examples 3.1.5 [ ] rfc4627_jsonrpc 3.1.5-git5e67120 [ ] sockjs 0.3.4-rmq3.1.5-git3132eb9 [ ] webmachine 1.10.3-rmq3.1.5-gite9359c7 [[email protected] ~]# /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management #启动rabbitMQ的web插件 The following plugins have been enabled: mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent rabbitmq_management Plugin configuration has changed. Restart RabbitMQ for changes to take effect. [[email protected] ~]# /etc/init.d/rabbitmq-server restart #重启rabbitMQ Restarting rabbitmq-server: SUCCESS rabbitmq-server. [[email protected] ~]# chkconfig rabbitmq-server on [[email protected] ~]# netstat -anpt |grep beam tcp 0 0 0.0.0.0:52872 0.0.0.0:* LISTEN 3207/beam.smp tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 3207/beam.smp tcp 0 0 0.0.0.0:55672 0.0.0.0:* LISTEN 3207/beam.smp tcp 0 0 127.0.0.1:39708 127.0.0.1:4369 ESTABLISHED 3207/beam.smp tcp 0 0 :::5672 :::* LISTEN 3207/beam.smp
4. 浏览器登陆RabbitMQ
默认用户名和密码为: guest/guest
打开浏览器,输入http://Compute node IP:15672
笔者在家和在公司都会写OpenStack文档,所以实验环境的IP会发生变化,忘大家谅解。 iamge iamge
1. 修改默认用户的gueset密码
[[email protected] ~]# rabbitmqctl --help #查看帮助 [[email protected] ~]# rabbitmqctl change_password guest rabbitmq #将guest用户的密码设置为rabbitmq Changing password for user "guest" ... ...done.
2. RabbitMQ用户管理
[[email protected] ~]# rabbitmqctl add_user 90root 90root #创建90root用户并设置密码为90root Creating user "90root" ... ...done. [[email protected] ~]# rabbitmqctl set_user_tags 90root administrator #将90root用户加入到管理员组 Setting tags for user "90root" to [administrator] ... ...done. [[email protected] ~]# rabbitmqctl list_users #查看rabbitmq所有用户 Listing users ... 90root[administrator] guest[administrator]