Tag Archives: java

centos install kafka


yum install java wget -y
wget https://downloads.apache.org/kafka/2.4.0/kafka_2.13-2.4.0.tgz
tar xvf kafka_2.13-2.4.0.tgz
mv -v kafka_2.13-2.4.0 /opt/kafka
adduser kafka
chown -R kafka.kafka /opt/kafka

vi /etc/systemd/system/kafka.service

[Unit]
Description=Apache Kafka
Requires=zookeeper.service
After=zookeeper.service

[Service]
Type=simple

User=kafka
Group=kafka

ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

vi /etc/systemd/system/zookeeper.service

[Unit]
Description=zookeeper
After=syslog.target network.target

[Service]
Type=simple

User=kafka
Group=kafka

ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh

[Install]
WantedBy=multi-user.target

systemctl start kafka zookeeper

Loaded: loaded (/etc/systemd/system/kafka.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-02-18 11:01:54 UTC; 3min 58s ago
Process: 1991 ExecStop=/opt/kafka/bin/kafka-server-stop.sh (code=exited, status=0/SUCCESS)
Main PID: 2014 (java)
Tasks: 64 (limit: 9189)
Memory: 323.1M
CGroup: /docker/a5855c3d46b38df0737879ebf1b5bc90a11d9a2c0604ae3bac810683aeb0e44e/system.slice/kafka.service
└─2014 java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Xloggc:/opt/kafka/bin/../logs/kafkaServer-gc.log -verbose>

Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,391] INFO [TransactionCoordinator id=0] Starting up. (kafka.coordinator.transaction.TransactionCoordinator)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,411] INFO [TransactionCoordinator id=0] Startup complete. (kafka.coordinator.transaction.TransactionCoordinator)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,431] INFO [Transaction Marker Channel Manager 0]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,579] INFO [ExpirationReaper-0-AlterAcls]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,742] INFO [/config/changes-event-process-thread]: Starting (kafka.common.ZkNodeChangeNotificationListener$ChangeEventProcessThread)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,928] INFO [SocketServer brokerId=0] Started data-plane processors for 1 acceptors (kafka.network.SocketServer)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,935] INFO Kafka version: 2.4.0 (org.apache.kafka.common.utils.AppInfoParser)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,935] INFO Kafka commitId: 77a89fcf8d7fa018 (org.apache.kafka.common.utils.AppInfoParser)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,935] INFO Kafka startTimeMs: 1582023721929 (org.apache.kafka.common.utils.AppInfoParser)
Feb 18 11:02:01 a5855c3d46b3 kafka-server-start.sh[2014]: [2020-02-18 11:02:01,937] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)

● zookeeper.service - zookeeper
Loaded: loaded (/etc/systemd/system/zookeeper.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-02-18 11:01:54 UTC; 3min 58s ago
Process: 2003 ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh (code=exited, status=0/SUCCESS)
Main PID: 2013 (java)
Tasks: 26 (limit: 9189)
Memory: 74.0M
CGroup: /docker/a5855c3d46b38df0737879ebf1b5bc90a11d9a2c0604ae3bac810683aeb0e44e/system.slice/zookeeper.service
└─2013 java -Xmx512M -Xms512M -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Xloggc:/opt/kafka/bin/../logs/zookeeper-gc.log -verbo>

Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,502] INFO maxSessionTimeout set to 60000 (org.apache.zookeeper.server.ZooKeeperServer)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,502] INFO Created server with tickTime 3000 minSessionTimeout 6000 maxSessionTimeout 60000 datadir /tmp/zookeeper/version-2 snapdir /tmp/zookeeper/versio>
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,534] INFO Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory (org.apache.zookeeper.server.ServerCnxnFactory)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,545] INFO Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 2 worker threads, and 64 kB direct buffers. (>
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,565] INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,657] INFO zookeeper.snapshotSizeFactor = 0.33 (org.apache.zookeeper.server.ZKDatabase)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,670] INFO Reading snapshot /tmp/zookeeper/version-2/snapshot.0 (org.apache.zookeeper.server.persistence.FileSnap)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,731] INFO Snapshotting: 0x1d to /tmp/zookeeper/version-2/snapshot.1d (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
Feb 18 11:01:57 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:57,853] INFO Using checkIntervalMs=60000 maxPerMinute=10000 (org.apache.zookeeper.server.ContainerManager)
Feb 18 11:01:58 a5855c3d46b3 zookeeper-server-start.sh[2013]: [2020-02-18 11:01:58,606] INFO Creating new log file: log.1e (org.apache.zookeeper.server.persistence.FileTxnLog)

create glassfish jdbc resource

#!/bin/bash
# Shell script to create the GlassFish 4 JDBC Connection pool for Mysql

# http://stackoverflow.com/questions/6572895/how-can-i-create-a-mysql-connection-pool-using-asadmin-tool-in-glassfish-server
echo "Create JDBC connection pool"
asadmin create-jdbc-connection-pool \
--datasourceclassname \
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource \
--restype javax.sql.DataSource \
--property User=arquillian:Password=arquillian:URL=\"jdbc:mysql://localhost:3306/arquillian\" \
ArquillianPool

# An alternative command line
# asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --restype javax.sql.DataSource
# --property user=root:password=test:DatabaseName=test:ServerName=localhost:port=3306 test-pool

echo "Create JDBC resource"
asadmin create-jdbc-resource --connectionpoolid ArquillianPool jdbc/arquillian

java – jre vs jdk

JRE
(Java Runtime Environment)

Computer users who run applets and applications written using Java technology
An environment required to run applets and applications written using the Java programming language
It is an implementation of the Java Virtual Machine* which actually executes Java programs.
Java Runtime Environment is a plug-in needed for running java programs.
The JRE is smaller than the JDK so it needs less Disk space.
It includes the JVM , Core libraries and other additional components to run applications and applets written in Java.

Java SE
(Java Platform, Standard Edition)

Software developers who write applets and applications using Java technology
A software development kit used to write applets and applications using the Java programming language

JDK
(Java Development Kit)
It is a bundle of software that you can use to develop Java based applications.
Java Development Kit is needed for developing java applications.
The JDK needs more Disk space as it contains the JRE along with various development tools.
It includes the JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java applets and applications.

java resources usage

The goal of JavaMelody is to monitor Java or Java EE application servers in QA and production environments. It is not a tool to simulate requests from users, it is a tool to measure and calculate statistics on real operation of an application depending on the usage of the application by users.

JavaMelody is opensource (LGPL) and production ready: in production in an application of 25 person years. JavaMelody is easy to integrate in most applications and is lightweight (no profiling and no database).

JavaMelody is mainly based on statistics of requests and on evolution charts.

It allows to improve applications in QA and production and helps to:

give facts about the average response times and number of executions
make decisions when trends are bad, before problems become too serious
optimize based on the more limiting response times
find the root causes of response times
verify the real improvement after optimizations
It includes summary charts showing the evolution over time of the following indicators:

Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsf actions, struts actions, jsp pages or methods of business façades (if EJB3, Spring or Guice)
Java memory
Java CPU
Number of user sessions
Number of jdbc connections
These charts can be viewed on the current day, week, month, year or custom period.

JavaMelody includes statistics of predefined counters (currently http requests, sql requests, jsf actions, struts actions, jsp pages and methods of business façades if EJB3, Spring or Guice) with, for each counter :

A summary indicating the overall number of executions, the average execution time, the cpu time and the percentage of errors.
And the percentage of time spent in the requests for which the average time exceeds a configurable threshold.
And the complete list of requests, aggregated without dynamic parameters with, for each, the number of executions, the mean execution time, the mean cpu time, the percentage of errors and an evolution chart of execution time over time.
Furthermore, each http request indicates the size of the flow response, the mean number of sql executions and the mean sql time.
It also includes statistics on http errors, on warnings and errors in logs, on data caches if ehcache and on batch jobs if quartz.

https://code.google.com/p/javamelody/

java GCJ

OpenJDK’s native Java compiler is, itself, written in Java; as a consequence, you need a working previous version of Java in order to build a new version.

If you’re starting from scratch on a platform for which no existing JDK binaries are readily available (or if you’re working within certain Free Software projects whose charters prohibit the use of proprietary build dependencies), then GCJ (or some of its underlying components) can be one potential solution to the chicken-and-egg problem of getting a working, albeit somewhat inefficient bootstrap Java in place, in order to move on to build the more desirable OpenJDK.

In fact, back when OpenJDK was first announced, significant effort (via the IcedTea project) was spent in fixing up GCJ to get it to the point where it was up to the task.

GCJ is obsolete. It was started a long time ago because people wanted an open-source alternative to the Sun JDK, and it was never particularly good. Now that Sun open-sourced their JDK, there’s absolutely no reason to use GCJ (but it still lurks in some Linux distros).