Cloudera Managerを使って本番用のHadoopクラスタ環境を構築して運用している。アップデート時など調査・検証のためテスト環境を度々繰り返し構築しなおすことがあるため、ある程度構築を自動化しておきたいと思い、今回Ansibleを使ってCloudera Managerのインストールから起動までの手順を書いてみた。
目次
構成
構成は以下の通り。
- MySQL 5.6
- Cloudera Manager 5.x
- CentOS6
- Running on a Virtual Machine with Vagrant
ディレクトリ構成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ tree . ├── Vagrantfile ├── cdh.yml ├── roles │ └── cm │ ├── files │ │ └── mysql-connector-java-5.1.39-bin.jar │ ├── tasks │ │ └── main.yml │ ├── templates │ │ ├── cloudera-manager.repo │ │ └── dot.my.cnf │ └── vars │ └── main.yml ├── vagrant.yml └── vansible.sh |
mysql-connector-javaは、事前に以下のページからダウンロードして配置しておく。
MySQL :: Download Connector/J
各種設定
Vagrantfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Vagrant.configure(2) do |config| config.vm.box = "centos/6" config.vm.network "forwarded_port", guest: 22, host: 2225 config.vm.network "forwarded_port", guest: 7180, host: 7180 config.vm.network "private_network", ip: "192.168.10.10" config.hostmanager.enabled = false config.hostmanager.manage_host = true config.hostmanager.manage_guest = true config.hostmanager.ignore_private_ip = false config.vm.hostname = "scm" config.vm.provider :virtualbox do |vb| vb.name = "scm" vb.memory = 4096 vb.cpus = 2 end config.vm.provision "ansible" do |ansible| ansible.verbose = true ansible.playbook = "vagrant.yml" end config.vm.provision :shell, :inline => 'echo "127.0.0.1 localhost" > /etc/hosts' config.vm.provision :hostmanager end |
vagrant.yml
1 2 3 4 5 6 7 |
- hosts: all become: yes tasks: - name: Stop iptables service: name=iptables state=stopped - name: Install libselinux-python yum: name=libselinux-python |
cdh.yml
1 2 3 4 5 6 7 8 9 |
- hosts: default become: yes pre_tasks: - name: Disable selinux selinux: state=disabled - name: Start ntpd service: name=ntpd state=started enabled=yes roles: - cm |
vansible.sh
これは、vagrantマシンへのアクセスを簡易化するためのただのスクリプト。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#!/usr/bin/env bash set -u usage() { cat <<EOF Usage: $0 [playbook <playbook>|update-inventory] [ANSIBLE OPTIONS] EOF } test $# -eq 0 && usage && exit INVENTORY_FILE=".vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory" SUB_COMMAND="$1" # Merge vagrant-inventory test "$SUB_COMMAND" = "update-inventory" && shift && { sed -i -e '/Generated by vansible/,$d' $INVENTORY_FILE cat vagrant-inventory >> $INVENTORY_FILE cat $INVENTORY_FILE exit $? } # Run playbook test "$SUB_COMMAND" = "playbook" && shift && { if [ $# -eq 0 ]; then echo "<playbook> is not specified." usage && exit 1 fi playbook="$1" shift ansible-${SUB_COMMAND} $playbook \ -i $INVENTORY_FILE \ $@ exit $? } # Run ansible ansible default -i $INVENTORY_FILE $@ |
templates
cloudera-manager.repo
cm_version
からfilterを使ってバージョン指定している。
1 2 3 4 5 6 |
[cloudera-manager] # Packages for Cloudera Manager, Version 5, on RedHat or CentOS 6 x86_64 name=Cloudera Manager baseurl=https://archive.cloudera.com/cm{{ cm_version | regex_replace('^([0-9])\\.(.+)$', '\\1') }}/redhat/6/x86_64/cm/{{ cm_version }}/ gpgkey =https://archive.cloudera.com/cm{{ cm_version | regex_replace('^([0-9])\\.(.+)$', '\\1') }}/redhat/6/x86_64/cm/RPM-GPG-KEY-cloudera gpgcheck = 1 |
dot.my.cnf
1 2 3 |
[client] user = root password = {{ mysql_root_password }} |
vars
main.yml
以下例でパスワードを平文で設定ファイルに書いているが、必要に応じてansible-vaultで暗号化しておく。
1 2 3 4 5 |
cm_version: 5.7.1 mysql_connector_java_ver: 5.1.39 mysql_root_password: secret mysql_cm_password: secret mysql_cm_service_password: secret |
tasks
main.yml
Cloudera Managerのインストール手順については、公式ドキュメントの『Installation Path B – Manual Installation Using Cloudera Manager Packages』のセクションを参照。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
--- # https://www.cloudera.com/documentation/enterprise/5-5-x/topics/cm_ig_install_path_b_auto.html - name: Install Cloudera Manager Repository template: src=cloudera-manager.repo dest=/etc/yum.repos.d/cloudera-manager.repo owner=root group=root mode=0644 - name: Install Cloudera Manager yum: name={{ item }} with_items: - oracle-j2sdk1.7 - cloudera-manager-server - cloudera-manager-daemons - name: Make directory /usr/share/java file: path=/usr/share/java state=directory owner=root group=root mode=0755 - name: Copy mysql-connector-java to /usr/share/java copy: src=mysql-connector-java-{{ mysql_connector_java_ver }}-bin.jar dest=/usr/share/java/mysql-connector-java.jar - name: Install MySQL Respository yum: name=http://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm - name: Install mysql yum: name={{ item }} with_items: - mysql-community-server - name: Start mysql service: name=mysqld state=started enabled=yes - name: Install MySQL-python yum: name=MySQL-python - name: Check if MySQL is initialized shell: mysql -e "use test;" ignore_errors: True register: not_prepared_mysql - name: Remove anonymous user mysql_user: name= state=absent when: not_prepared_mysql|success - name: Remove remote hosts shell: | mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" when: not_prepared_mysql|success - name: Drop test database shell: | mysql -e "DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db = 'test' OR Db='test\\_%';" when: not_prepared_mysql|success - name: Set root password for MySQL mysql_user: name=root password={{ mysql_root_password }} - name: Write /root/.my.cnf template: src=dot.my.cnf dest=/root/.my.cnf owner=root group=root mode=0600 - name: Create database for cloudera management services mysql_db: name={{ item }} encoding=utf8 with_items: - amon - rman - nav - name: Create users for cloudera management services mysql_user: name={{ item.user }} password={{ item.password }} priv={{ item.user }}.*:ALL host=% with_items: - { user: amon, password: "{{ mysql_cm_service_password }}" } - { user: rman, password: "{{ mysql_cm_service_password }}" } - { user: nav, password: "{{ mysql_cm_service_password }}" } - name: Check if scm database exists shell: mysql -e "use scm;" ignore_errors: True register: prepared_scm - name: Prepare database for Cloudera Manager shell: /usr/share/cmf/schema/scm_prepare_database.sh -uroot -p{{ mysql_root_password }} mysql scm scm {{ mysql_cm_password }} when: prepared_scm|failed - name: Start Cloudera Manage Server service: name=cloudera-scm-server state=started |
実行
1 2 3 |
$ vagrant plugin install vagrant-hostmanager $ vagrant up $ ./vansible.sh playbook cdh.yml -vvv |
無事起動できたら、以下のリンクにアクセスするとCloudera Managerのログイン画面が表示される。
http://localhost:7180/
参考リンク
- http://www.cloudera.com/documentation/enterprise/5-5-x/topics/installation_installation.html
- https://github.com/ymc-geko/ansible-cdh-cluster
- https://dev.mysql.com/doc/refman/5.6/ja/linux-installation-yum-repo.html
- http://qiita.com/KisaragiZin/items/e241f189c83580f92e9c
- http://docs.ansible.com/ansible/mysql_db_module.html
コメント