#!/usr/bin/env bash
echo "生成SSH免密码交互登录的密钥..."
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa

echo "复制公钥到其他服务器，请输入对应服务器的密码！"
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-master
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node1
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node2
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node3
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node4
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node5
ssh-copy-id -i ~/.ssh/id_rsa.pub root@dev-node6

echo "下载MySQL的驱动"
mkdir -p /usr/share/java/
wget https://repo.car-house.net/mysql/mysql-connector-java-5.1.47.jar -O /usr/share/java/mysql-connector-java.jar

echo "检查要安装的程序包是否存在"
yum search cloudera-manager-server

echo "正在安装CM的程序"
yum install -y cloudera-manager-daemons cloudera-manager-server

echo "初始化SCM的数据库，请输入SCM的数据库密码！"
# 执行SQL
/opt/cloudera/cm/schema/scm_prepare_database.sh mysql scm scm


echo "启动Cloudera Manager 服务器"
systemctl start cloudera-scm-server

echo "启动中。。。启动完成之后请访问http://本机IP地址:7180来登录管理后台，默认账号密码都是admin"

tail -f /var/log/cloudera-scm-server/cloudera-scm-server.log
#出现类似下面的日志的时候表明服务启动成功了
#2019-08-05 16:45:45,852 INFO WebServerImpl:org.eclipse.jetty.server.AbstractConnector: Started ServerConnector@6cdfc401{HTTP/1.1,[http/1.1]}{0.0.0.0:7180}
#2019-08-05 16:45:45,853 INFO WebServerImpl:org.eclipse.jetty.server.Server: Started @211380ms
#2019-08-05 16:45:45,853 INFO WebServerImpl:com.cloudera.server.cmf.WebServerImpl: Started Jetty server.


#以下为设置SSL使用自签名的证书，非必须
#echo "设置Auto-TLS"
#/opt/cloudera/cm-agent/bin/certmanager --location /opt/cloudera/CMCA setup --configure-services
#systemctl restart cloudera-scm-server