这套安装脚本是单节点安装 Kaa (v0.10.0) ,如果有问题或者安装的是其他版本,请参考官方文档。官方文档的几个坑还都比较小,都是下载文件404问题,我这里都做了更新。
主要流程
1. 安装第三方运行环境和中间件
JDK 8
PostgreSQL 9.4 or MariaDB 5.5.本文选用MariaDB
MongoDB 2.6.9 or Cassandra 3.5本文选用MongoDB
Zookeeper 3.4.5
注意事项
1. 推荐用安装管理员
2. Kaa下载比较慢,建议先用迅雷下好,搭建个局域网Web服务,再下到CentOS7里。
1.安装必备组件
>yum install wget nc gzip
2.安装JDK 8
cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm
yum localinstall jdk-8u151-linux-x64.rpm
选择你电脑里的java版本
cd /usr/java/jdk1.8.0_151/
sudo alternatives --install /usr/java java /usr/java/jdk1.8.0_151/bin/java 2
sudo alternatives --config java
会出现下面的选项(每个人的情况可能稍有不同),选择刚才安装的java版本:
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/java/jdk1.8.0_151/jre/bin/java
+ 2 /usr/java/jdk1.8.0_151/bin/java
按 Enter 保留当前选项[+],或者键入选项编号:
输入 2
2.1 设置环境变量
cat >> /etc/profile <<EOF
export JAVA_HOME=/usr/java/jdk1.8.0_151
export JRE_HOME=\$JAVA_HOME/jre
export CLASSPATH=.:\$JAVA_HOME/lib:\$JRE_HOME/lib:\$CLASSPATH
export PATH=\$JAVA_HOME/bin:$PATH
EOF
source /etc/profile
2.2 检查java安装状态
java -version
3.安装MariaDB
3.1 添加yum 源
cat >/etc/yum.repos.d/MariaDB.repo<<EOF
[mariadb]
name = MariaDB
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-5.5.53/yum/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
3.2 防止冲突,卸载mysql(可跳过)
yum -y update
service mysqld stop
yum -y remove mysql-server mysql
3.3 安装MariaDB
yum -y install MariaDB-server MariaDB-client
service mysql start
3.4 检查MariaDB运行情况
netstat -ntlp | grep 3306
3.5 配置MariaDB并创建数据库
mysql -u root -p
CREATE USER 'sqladmin'@'localhost' IDENTIFIED BY 'admin'; GRANT ALL PRIVILEGES ON *.* TO 'sqladmin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;
CREATE DATABASE kaa
CHARACTER SET utf8
COLLATE utf8_general_ci;
exit
4.安装zookeeper
4.1 下载zookeeper
cd /opt
wget http://www.eu.apache.org/dist/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar zxvf zookeeper-3.4.11.tar.gz
cp zookeeper-3.4.11/conf/zoo_sample.cfg zookeeper-3.4.11/conf/zoo.cfg
4.2 配置zookeeper
mkdir /var/zookeeper
vi /opt/zookeeper-3.4.11/conf/zoo.cfg
修改其中的 dataDir=/var/zookeeper
5.安装supervisor
5.1 安装epel
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
yum -y install supervisor
5.2 配置
cat >>/etc/supervisord.conf<<EOF
[program:zookeeper]
command=/opt/zookeeper-3.4.11/bin/zkServer.sh start-foreground
autostart=true
autorestart=true
startsecs=1
startretries=999
redirect_stderr=false
stdout_logfile=/var/log/zookeeper-out
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_events_enabled=true
stderr_logfile=/var/log/zookeeper-err
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=10
stderr_events_enabled=true
EOF
5.3启动服务
systemctl enable supervisord
systemctl start supervisord
5.4检查状态
supervisorctl
netstat -ntlp | grep 2181
6.安装mongodb
6.1 添加下载源
cat >/etc/yum.repos.d/mongodb.repo<<EOF
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
EOF
6.2 安装
yum install -y mongodb-org
6.3 启动数据库
systemctl start mongod
chkconfig mongod on
6.4 检查mongodb运行状态
cat /var/log/mongodb/mongod.log | grep "waiting for connections on port"
2017-12-21T19:10:35.427+0800 [initandlisten] waiting for connections on port 27017
7.进入正题,安装Kaa
7.1 下载Kaa 安装包
wget https://github.com/kaaproject/kaa/releases/download/v0.10.0/kaa-rpm-0.10.0.tar.gz
7.2安装kaa
tar -xvf kaa-rpm-0.10.0.tar.gz
rpm -i rpm/kaa-node-0.10.0.rpm
7.3 检查Kaa Sql数据库配置
cat /etc/kaa-node/conf/admin-dao.properties | grep jdbc_username
jdbc_username=sqladmin
cat /etc/kaa-node/conf/admin-dao.properties | grep jdbc_password
jdbc_password=admin
cat /etc/kaa-node/conf/sql-dao.properties | grep jdbc_username
jdbc_username=sqladmin
cat /etc/kaa-node/conf/sql-dao.properties | grep jdbc_password
jdbc_password=admin
7.4 如果你使用的数据库密码和上面的配置一致可跳过此步骤,否则在下面的文件里修改
//修改上面的配置
vi /etc/kaa-node/conf/admin-dao.properties
vi /etc/kaa-node/conf/sql-dao.properties
7.5 检查Kaa NoSql数据库配置,同样的在这个文件里修改
cat /etc/kaa-node/conf/nosql-dao.properties | grep nosql_db_provider_name
显示
nosql_db_provider_name=mongodb
7.6 修改网络配置
默认kaa的配置连接是localhost的,没法让Kaa生成SDK,并将SDK用于设备与服务器的通信
vi /etc/kaa-node/conf/kaa-node.properties
找到下面这行
transport_public_interface=localhost
把localhost替换成你的外网地址
8.配置网络和防火墙
systemctl stop firewalld
systemctl mask firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables
sudo iptables -I INPUT -p tcp -m tcp --dport 22 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 9888 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 9889 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 9997 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 9999 -j ACCEPT
sudo service iptables save
9.启动Kaa
service kaa-node start
10.检查启动时有没有错误日志
cat /var/log/kaa/* | grep ERROR
如果没有输出说明运行良好,所有的日志文件都在/var/log/kaa/这个目录
。