Install REST Application
To install a REST API to interact with Metron, complete the following steps:
Create a file
/etc/yum.repos.d/HCP.repo
containing the following information. Make sure the information matches your installation, including the version number, etc.#VERSION_NUMBER=1.1.0.0-71 [HCP-1.1.0.0-71] name=HCP Version - HCP-1.1.0.0-71 baseurl=http://s3.amazonaws.com/dev.hortonworks.com/HCP/centos6/1.x/BUILDS/1.1.0.0-71 gpgcheck=1 gpgkey=http://s3.amazonaws.com/dev.hortonworks.com/HCP/centos6/1.x/BUILDS/1.1.0.0-71/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins enabled=1 priority=1
Install the REST package:
CentOS 6 and 7
yum install metron-rest
Ubuntu
apt-get install metron-rest
Connect to MySQL and create a Metron REST database:
mysql -uroot -p CREATE DATABASE IF NOT EXISTS metronrest;
Create a Metron user in MySQL with a password, then apply database access permission to the Metron user:
CREATE USER 'metron'@'REST_HOST' IDENTIFIED BY 'Myp@ssw0rd'; GRANT ALL PRIVILEGES ON metronrest.* TO 'metron'@'REST_HOST';
Create user and authorities tables:
use metronrest; create table if not exists users( username varchar(50) not null primary key, password varchar(50) not null, enabled boolean not null ); create table authorities ( username varchar(50) not null, authority varchar(50) not null, constraint fk_authorities_users foreign key(username) references users(username) ); create unique index ix_auth_username on authorities (username,authority);
Add one or more users to the REST application:
use metronrest; insert into users (username, password, enabled) values ('your_username','your_password',1); insert into authorities (username, authority) values ('your_username', 'ROLE_USER');
Exit MySQL:
quit
Create the
$METRON_HOME/config/application.yml
file containing the following:server: port: 8082 spring: datasource: driverClassName: org.h2.Driver url: jdbc:h2:file:./metrondb username: root password: root platform: h2 jpa: hibernate: ddl-auto: update zookeeper: url: ${ZOOKEEPER} kafka: broker: url: ${BROKERLIST} hdfs: namenode: url: ${HDFS_URL} grok: path: temp: ./patterns/temp default: /apps/metron/patterns storm: ui: url: ${STORM_REST_URL} parser: script.path: ${METRON_HOME}/bin/start_parser_topology.sh enrichment: script.path: ${METRON_HOME}/bin/start_enrichment_topology.sh indexing: script.path: ${METRON_HOME}/bin/start_elasticsearch_topology.sh
Replace the H2 connection information in the
$METRON_HOME/config/application.yml
file with MySQL connection information:spring: datasource: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://mysql_host:3306/metronrest username: metron_rest_user password: metron_rest_password
Install the appropriate MySQL client library for your version of MySQL. For example:
cd $METRON_HOME/lib wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.41.tar.gz tar xf mysql-connector-java-5.1.41.tar.gz
Start the REST application:
nohup java -Dloader.path=$METRON_HOME/lib/mysql-connector-java-5.1.41/mysql-connector-java-5.1.41-bin.jar -jar $METRON_HOME/lib/metron-rest-$METRON_VERSION.jar --spring.config.location=$METRON_HOME/config/application.yml > rest-api.log 2>&1 &
where:
- nohup
No hangup. The
nohup
command is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is used, by convention, by a terminal to warn dependent processes of logout. Output that would normally go to the terminal goes to a file callednohup.out
if it has not already been redirected.- 2>&1
Redirect all
stderr
output tostdout
. File descriptor 1 isstdout
, file descriptor 2 isstderr
. The ampersand instructs the shell to interpret the 1 as a file descriptor instead of as a file named "1".- &
Background the process
To add additional users:
use metronrest; insert into users (username, password, enabled) values ('your_username','your_password',1); insert into authorities (username, authority) values ('your_username', 'ROLE_USER'); commit;
In a cluster with Kerberos enabled, update the security settings in
/etc/sysconfig/metron
.METRON_SPRING_PROFILES_ACTIVE="vagrant,dev" METRON_JVMFLAGS="Djava.security.auth.login.config=$METRON_HOME/client_jaas.confg" METRON_SPRING_OPTIONS="--kerberos.enables=true"
Make sure you can access the Swagger UI at http://host:port/swagger-ui.html#/.
The exposed REST endpoints can be accessed with the Swagger UI at http://host:port/swagger-ui.html#/. The default port is 8082 but can be changed in the
$METRON_HOME/config/application.yml
file by setting "server.port" to the desired port.