为Cloudera Software安装和配置MySQL
要使用MySQL数据库,请按照以下过程操作。有关MySQL数据库兼容版本的信息,请参阅CDH和Cloudera Manager支持的数据库。
安装MySQL服务器
注意:
- 如果您已经设置了MySQL数据库,则可以跳到配置和启动MySQL服务器部分,以验证您的MySQL配置是否满足Cloudera Manager的要求。
- 对于MySQL 5.6和5.7,您必须安装MySQL-shared-compat或MySQL-shared软件包。这是Cloudera Manager Agent软件包安装所必需的。
- 重要的是 datadir 目录,默认情况下是 /var/lib/mysql,位于具有足够可用空间的分区上。
- 如果在MySQL中启用了基于GTID的复制,则Cloudera Manager安装将失败。
安装MySQL数据库。
OS
|
命令 |
---|---|
RHEL |
RHEL不再包含MySQL。您必须从MySQL站点下载存储库并直接安装它。您可以使用以下命令安装MySQL。有关更多信息,请访问MySQL网站。 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
sudo yum update
sudo yum install mysql-server
sudo systemctl启动mysqld
|
SLES |
sudo zypper install mysql libmysqlclient_r17
注意:使用前面的内容时,某些SLES系统会遇到错误zypper安装命令。有关解决此问题的详细信息,请参阅Novell知识库主题,运行chkconfig时出错。 |
Ubuntu的 |
sudo apt-get install mysql-server
|
配置和启动MySQL服务器
注意:如果要对现有数据库进行更改,请确保在继续之前停止使用该数据库的任何服务。
- 如果MySQL服务器正在运行,请将其停止。
OS 命令 RHEL 7兼容 sudo systemctl stop mysqld
RHEL 6兼容 sudoservice mysqld stopSLES,Ubuntu sudo service mysql stop - 移动旧的InnoDB日志文件 /var/lib/mysql/lib_logfile0 和 /var/lib/mysql/ib_logfile1在......之外 /var/lib/mysql/ 到备份位置。
- 确定选项文件的位置,my.cnf中 (/etc/my.cnf默认)。
- 更新 my.cnf中 这样它符合以下要求:
- 要防止死锁,请将隔离级别设置为 READ-COMMITTED。
- 配置 InnoDB的发动机。如果Cloudera Manager的表配置了MyISAM引擎,它将无法启动。(通常,如果InnoDB引擎配置错误,表将恢复为MyISAM。)要检查表所使用的引擎,请从MySQL shell运行以下命令:
mysql> show table status;
- 大多数发行版中MySQL安装中的默认设置使用保守的缓冲区大小和内存使用情况。Cloudera Management Service角色需要高写入吞吐量,因为它们可能会在数据库中插入许多记录。Cloudera建议你设置innodb_flush_method 财产 O_DIRECT。
- 设置 MAX_CONNECTIONS 根据群集大小的属性:
-
- 少于50台主机 - 您可以在同一主机上存储多个数据库(例如,活动监视器和服务监视器)。如果你这样做,你应该:
-
- 将每个数据库放在自己的存储卷上。
- 为每个数据库允许100个最大连接,然后添加50个额外连接。例如,对于两个数据库,将最大连接数设置为250.如果在一个主机(Cloudera Manager Server,活动监视器,报告管理器,Cloudera Navigator和Hive Metastore的数据库)上存储五个数据库,请将最大连接数设置为550 。
- 超过50台主机 - 不要在同一主机上存储多个数据库。为每个数据库/主机对使用单独的主机。主机不需要专门为数据库保留,但每个数据库应位于单独的主机上。
- Cloudera Manager安装不需要二进制日志记录。二进制日志记录提供了诸如MySQL复制或数据库恢复后的时间点增量恢复等优势。以下是此配置的示例。有关更多信息,请参阅二进制日志。
-
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
transaction-isolation = READ-COMMITTED
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
symbolic-links = 0
key_buffer_size = 32M
max_allowed_packet = 32M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
max_connections = 550
#expire_logs_days = 10
#max_binlog_size = 100M
#log_bin should be on a disk with enough free space.
#Replace '/var/lib/mysql/mysql_binary_log' with an appropriate path for your
#system and chown the specified folder to the mysql user.
log_bin=/var/lib/mysql/mysql_binary_log
#In later versions of MySQL, if you enable the binary log and do not set
#a server_id, MySQL will not start. The server_id must be unique within
#the replicating group.
server_id=1
binlog_format = mixed
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
# InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sql_mode=STRICT_ALL_TABLES - 如果AppArmor在安装了MySQL的主机上运行,则可能需要配置AppArmor以允许MySQL写入二进制文件。
- 确保MySQL服务器在启动时启动:
OS 命令 RHEL 7兼容 sudo systemctl start mysqld
RHEL 6兼容 sudo chkconfig mysqld on
SLES sudo chkconfig --add mysql
Ubuntu的 sudo chkconfig mysql on
注意: chkconfig的最近的Ubuntu版本可能无法使用。您可能需要使用Upstart将MySQL配置为在系统引导时自动启动。有关更多信息,请参阅Ubuntu文档或Upstart Cookbook。 - 启动MySQL服务器:
OS 命令 RHEL 7兼容 sudo systemctl start mysqld
RHEL 6兼容 sudo service mysqld start
SLES,Ubuntu sudo service mysql start - 跑 在/ usr / bin中/ mysql_secure_installation设置MySQL root密码和其他与安全相关的设置。在新的安装中,根密码为空。当系统提示您输入root密码时,请按Enter键。对于其余提示,请以粗体输入下面列出的响应:
sudo / usr / bin / mysql_secure_installation
[...]
Enter current password for root (enter for none):
OK, successfully used password, moving on...
[...]
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[...]
Disallow root login remotely? [Y/n] N
[...]
Remove test database and access to it [Y/n] Y
[...]
Reload privilege tables now? [Y/n] Y
All done!
Enter current password for root (enter for none):
OK, successfully used password, moving on...
[...]
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[...]
Disallow root login remotely? [Y/n] N
[...]
Remove test database and access to it [Y/n] Y
[...]
Reload privilege tables now? [Y/n] Y
All done!
安装MySQL JDBC驱动程序
在Cloudera Manager Server主机上以及运行需要数据库访问的服务的任何其他主机上安装JDBC驱动程序。有关使用数据库的Cloudera软件的详细信息,请参阅必需的数据库。
注意:如果已在需要它的主机上安装了JDBC驱动程序,则可以跳过本节。但是,MySQL 5.6需要驱动程序版本5.1.26或更高版本。Cloudera建议您在有限数量的主机上合并所有需要数据库的角色,并在这些主机上安装驱动程序。建议在同一主机上定位所有此类角色,但不是必需的。确保在运行访问数据库的角色的每个主机上安装JDBC驱动程序。注意: Cloudera建议仅使用JDBC驱动程序的5.1版。
OS
|
命令 |
---|---|
RHEL | 重要提示:请勿使用yum install 命令安装MySQL驱动程序包,因为它安装了OpenJDK,然后使用Linux alternatives 命令将系统JDK设置为OpenJDK。
|
SLES |
sudo zypper install mysql-connector-java
|
Ubuntu或Debian |
sudo apt-get install libmysql-java
|
为Cloudera软件创建数据库
Create databases and service accounts for components that require databases:
- Cloudera Manager Server
- Cloudera Management Service roles:
-
- Activity Monitor (if using the MapReduce service in a CDH 5 cluster)
- Reports Manager
- Each Hive metastore
- Sentry Server
- Cloudera Navigator Audit Server
- Cloudera Navigator Metadata Server
The databases must be configured to support the MySQL utf8 character set encoding.
Record the values you enter for database names, usernames, and passwords. The Cloudera Manager installation wizard requires this information to correctly connect to these databases.
- Log in as the root user, or another user with privileges to create database and grant privileges:
mysql -u root -p
Enter password: 123
- Create databases for each service you are using from the below table:
CREATE DATABASE <database> DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
GRANT ALL ON <database>.* TO '<user>'@'%' IDENTIFIED BY '<password>';
Query OK, 0 rows affected (0.00 sec)
You can use any value you want for <database>, <user>, and <password>. The following examples are the default names provided in the Cloudera Manager configuration settings, but you are not required to use them:Databases for Cloudera Software Service Database User Cloudera Manager Server scm scm Activity Monitor amon amon Reports Manager rman rman Hue hue hue Hive Metastore Server metastore hive Sentry Server sentry sentry Cloudera Navigator Audit Server nav nav Cloudera Navigator Metadata Server navms navms Oozie oozie oozie
CREATE DATABASE scm DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON scm.* TO'scm'@'%'IDENTIFIED BY 'scm';
CREATE DATABASE amon DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON amon.* TO'amon'@'%'IDENTIFIED BY 'amon';
CREATE DATABASE rman DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON rman.* TO'rman'@'%'IDENTIFIED BY 'rman';
CREATE DATABASE hue DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON hue.* TO'hue'@'%'IDENTIFIED BY 'hue';
CREATE DATABASE metastore DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON metastore.* TO'hive'@'%'IDENTIFIED BY 'hive';
CREATE DATABASE sentry DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON sentry.* TO'sentry'@'%'IDENTIFIED BY 'sentry';
CREATE DATABASE nav DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON nav.* TO'nav'@'%'IDENTIFIED BY 'nav';
CREATE DATABASE navms DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON navms.* TO'navms'@'%'IDENTIFIED BY 'navms';
CREATE DATABASE oozie DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL ON oozie.* TO 'oozie'@'%' IDENTIFIED BY 'oozie';
3. Confirm that you have created all of the databases:
SHOW DATABASES;
You can also confirm the privilege grants for a given user by running:
SHOW GRANTS FOR '<user>'@'%';