安装ansible工具
yum -y install epel-release
yum -y install ansible
更改主机hosts
cat >> /etc/ansible/hosts << EOF
[cdh]
172.20.50.170
172.20.50.171
172.20.50.172
EOF
设置主机名
hostnamectl set-hostname cdh701.cdh.com
hostnamectl set-hostname cdh702.cdh.com
hostnamectl set-hostname cdh703.cdh.com
配置主机名解析
cat >> /etc/hosts <<EOF
172.20.50.170 cdh701.cdh.com cdh701
172.20.50.172 cdh702.cdh.com cdh702
172.20.50.173 cdh703.cdh.com cdh703
EOF
配置主机免密登录
ssh-keygen -f ~/.ssh/id_rsa -N '' -t rsa -q -b 2048
ssh-copy-id -i cdh701
scp -r .ssh cdh702:~/
scp -r .ssh cdh703:~/
同步主机 hosts 解析文件
ansible all -m copy -a "src=/etc/hosts dest=/etc/"
停止&&禁用防火墙
ansible all -m systemd -a "name=firewalld state=stopped"
ansible all -m systemd -a "name=firewalld enabled=no"
禁用 selinux
ansible all -m selinux -a "state=disabled"
禁用 swap 分区
ansible all -m shell -a "swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab "
设置时区
ansible all -m shell -a "timedatectl set-timezone Asia/Shanghai"
安装时钟同步服务并启动
ansible all -m package -a "name=chrony state=present"
ansible all -m systemd -a "name=chronyd enabled=yes"
ansible all -m systemd -a "name=chronyd state=started"
安装依赖工具
ansible all -m package -a "name=epel-release,wget,vim,net-tools,unzip,lrzsz,rpcbind state=present"
ansible all -m shell -a "systemctl enable rpcbind && systemctl restart rpcbind "
挂载磁盘
ansible all -m shell -a "fdisk -l |grep Disk|grep dev"
ansible all -m shell -a "mkdir /data"
ansible all -m shell -a "mkfs.ext4 /dev/sdb"
添加自动挂载
UUID="00008d25-1904-47ce-8b40-e801748ba01a" /data ext4 defaults 0 0
ansible all -m shell -a "mount -a "
关闭透明大页
ansible all -m shell -a "echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag ' >> /etc/rc.d/rc.local"
ansible all -m shell -a "echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled ' >> /etc/rc.d/rc.local"
ansible all -m shell -a "chmod +x /etc/rc.d/rc.local"
ansible all -m systemd -a "name=rc-local state=restarted"
ansible all -m systemd -a "name=rc-local enabled=yes"
资源限制与内核修改
cat >> /etc/security/limits.conf <<EOF
* soft nofile 200000
* hard nofile 200000
* soft nproc 200000
* hard nproc 200000
EOF
同步到其他节点
ansible all -m copy -a "src=/etc/security/limits.conf dest=/etc/security/limits.conf"
内核修改
cat >> /etc/sysctl.conf <<EOF
vm.swappiness = 0
EOF
同步到其他节点
ansible all -m copy -a "src=/etc/sysctl.conf dest=/etc/sysctl.conf"
立即生效
ansible all -m shell -a "sysctl -p /etc/sysctl.conf"
部署CDH7
下载CDH7 CMrpm包
https://archive.cloudera.com/p/cm7/7.1.4/redhat7/yum/RPMS/x86_64/
ansible all -m copy -a "src=/root/cm7 dest=/root/cm7"
安装java
ansible all -m shell -a "yum install -y /root/cm7/openjdk8-8.0+232_9-cloudera.x86_64.rpm"
配置java 环境变量
cat >> /etc/profile <<EOF
#JDK
export JAVA_HOME=/usr/java/jdk1.8.0_232-cloudera
export CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib:\$CLASSPATH
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH
export LD_LIBRARY_PATH=\$JAVA_HOME/jre/lib/amd64:\$JAVA_HOME/jre/lib/amd64/server:\$JAVA_HOME/jre/lib/amd64/jli:\$LD_LIBRARY_PATH
EOF
同步环境变量到其他节点
ansible all -m copy -a "src=/etc/profile dest=/etc"
在第二个节点安装数据库并做简单的配置
yum -y install mariadb-server
开机启动
systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
启动mariadb
systemctl start mariadb
执行安装配置向导
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!
mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6938
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'Cloudera' WITH GRANT OPTION ;
CREATE DATABASE hive CHARACTER SET utf8 COLLATE utf8_general_ci ;
GRANT ALL PRIVILEGES ON hive.* TO hive@'%' IDENTIFIED BY 'hive' WITH GRANT OPTION ;
部署数据库驱动
ansible all -m file -a "path=/usr/share/java state=directory"
wget -c https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.46.tar.gz
tar zxf mysql-connector-java-5.1.46.tar.gz
同步到其他节点
ansible all -m copy -a "src=/usr/share/java/mysql-connector-java-5.1.46-bin.jar dest=/usr/share/java/"
创建软链接
ansible all -m shell -a "cd /usr/share/java && ln -s mysql-connector-java-5.1.46-bin.jar mysql-connector-java.jar"
部署CM server
1.安装CM server(cdh702节点)
ansible all -m shell -a "yum install -y /root/cm7/cloudera-manager-server-7.1.4-6363010.el7.x86_64.rpm"
2.初始化CM server(cdh702节点)
/opt/cloudera/cm/schema/scm_prepare_database.sh mysql -hcdh702.cdh.com -uroot -pCloudera --scm-host '%' scm scm scm
3.设置开机启动
systemctl enable cloudera-scm-server
4.启动CM server
systemctl start cloudera-scm-server
部署CM agent
1.各节点安装 CM agent
ansible all -m shell -a "yum install -y /root/cm7/cloudera-manager-daemons-7.1.4-6363010.el7.x86_64.rpm"
ansible all -m shell -a "yum install -y /root/cm7/cloudera-manager-agent-7.1.4-6363010.el7.x86_64.rpm"
2.修改CM agent配置
vim /etc/cloudera-scm-agent/config.ini
[General]
# Hostname of the CM server.
server_host=cdh702.cdh.com # 可以是CM server 主机名,也可以是IP地址,并同步到其他节点
3.同步agent配置到其他节点
ansible all -m copy -a "src=/etc/cloudera-scm-agent/config.ini dest=/etc/cloudera-scm-agent/config.ini"
4.设置开机启动
ansible all -m shell -a "systemctl enable cloudera-scm-agent "
5.启动agent服务
ansible all -m systemd -a "name=cloudera-scm-agent state=restarted"
通过http://CMserverIP:7180页面上的向导分别安装如下角色: