Thứ Năm, 26 tháng 7, 2018

Get Services with path to executable export to csv of windows

Powershell
Get-Service
Example 1: Get all services on the computer
Get-Service
This command gets all of the services on the computer. It behaves as though you typed Get-Service *. The default display shows the status, service name, and display name of each service.

Example 2: Get services that begin with a search string
Get-Service "wmi*"
This command retrieves services with service names that begin with WMI (the acronym for Windows Management Instrumentation).

Example 3: Display services that include a search string
Get-Service -Displayname "*network*"
This command displays services with a display name that includes the word network. Searching the display name finds network-related services even when the service name does not include "Net", such as xmlprov, the Network Provisioning Service.

Example 4: Get services that begin with a search string and an exclusion
Get-Service -Name "win*" -Exclude "WinRM"
These commands get only the services with service names that begin with win, except for the WinRM service.

Example 5: Display services that are currently active
Get-Service | Where-Object {$_.Status -eq "Running"}
This command displays only the services that are currently active. It uses the Get-Service cmdlet to get all of the services on the computer. The pipeline operator (|) passes the results to the Where-Object cmdlet, which selects only the services with a Status property that equals Running.

Get Services with path to executable export to csv of windows:

Get-WmiObject win32_service | ?{$_.Name -like '*'} | select Name, Pathname, State, StartMode, StartName | export-csv "C:\Services.csv" -NoTypeInformation -Encoding UTF8

Read More

Thứ Ba, 24 tháng 7, 2018

Monitoring tomcat using zabbix

Platform: CentOS 7 64bit, Tomcat 7


1. Install Zabbix Server

rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum install zabbix-web-mysql -y
yum install zabbix-java-gateway -y
yum -y install httpd
yum -y install mariadb-server

#mysql -uroot
mysql>create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> quit;
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

Edit /etc/zabbix/zabbix_server.conf:
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
JavaGateway=x.x.x.x
JavaGatewayPort=10052
StartJavaPollers=1
2. Config tomcat to enable jmx monitoring:
- Install Zabbix Agent:
rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum install zabbix-agent
- Download and install catalina-jmx-remote.jar 
 #wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.90/bin/extras/catalina-jmx-remote.jar
- mv the jar file to /usr/local/tomcat7/lib/ 
- edit /usr/local/tomcat7/conf/server.xml and add Listener


<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="8090" rmiServerPortPlatform="8090" />
- edit /usr/local/tomcat7/bin/setenv.sh and add the follow lines:
export JAVA_OPTS="$JAVA_OPTS -Xms128M -Xmx512M -server -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
Restart tomcat:
cd /opt/apache-tomcat-7.0.90/bin/
./shutdown.sh
./startup.sh

Configuring JMX interfaces and items in Zabbix frontend

With Java gateway running, server knowing where to find it and a Java application started with support for remote JMX monitoring, it is time to configure the interfaces and items in Zabbix GUI.
Configuring JMX interface
You begin by creating a JMX-type interface on the host of interest:

Adding JMX agent item
For each JMX counter you are interested in you add JMX agent item attached to that interface.
The key in the screenshot below says jmx["java.lang:type=Memory","HeapMemoryUsage.used"].

The fields that require specific information for JMX items are:
Type Set JMX agent here.
Key The jmx[] item key contains two parameters:
object name - the object name of an MBean;
attribute name - an MBean attribute name with optional composite data field names separated by dots.
See below for more detail on JMX item keys.
Since Zabbix 3.4, you may discover MBeans and MBean attributes using a jmx.discovery[] low-level discovery item.
JMX endpoint You may specify a custom JMX endpoint. Make sure that JMX endpoint connection parameters match the JMX interface. This can be achieved by using {HOST.*} macros as done in the default JMX endpoint.
This field is supported since 3.4.0. {HOST.*} macros and user macros are supported.
User name Specify the user name, if you have configured authentication on your Java application.
User macros are supported.
Password Specify the password, if you have configured authentication on your Java application.
User macros are supported.



Read More

Thứ Tư, 18 tháng 7, 2018

Apache Tomcat service Start , Shutdown , Restart script for RHEL , CentOS & Ubuntu

Step 1. Create script with name tomcat containing following code

#!/bin/sh
####################################################################
# Created by: Abhijit Sandhan
# Purpose: Start/Stop/Restart Apache Tomcat service
####################################################################
# Check the path of Tomcat and set environment variables as follows
# in the .bashrc profile
export CATALINA_HOME="/usr/local/tomcat7/apache-tomcat-7.0.37"
export CATALINA_BASE="/usr/local/tomcat7/apache-tomcat-7.0.37"
export JAVA_HOME="/usr/local/java/jdk1.7.0_17"
export JAVA_HOME=/usr/local/java/jdk1.7.0_17

#Use Case statement to start / stop /reset tomcat service
case $1 in
start)
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./startup.sh
;;
stop)
cd /usr/local/tomcat7/apache-tomcat-7.0.37bin/
./shutdown.sh
;;
restart)
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./shutdown.sh
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./startup.sh
;;
esac
exit 0

Note: Make sure to replace the tomcat, java directory paths & variables according to  your server settings in the above script.
Step 2. Copy the tomcat script under /etc/init.d directory

cp tomcat /etc/init.d/

Step 3.  Create symlinks to start/stop/restart tomcat service for desired Runlevel

Example: For Runlevel 2

 sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Step 4. Reboot server to verify if following commands are working or not

To start:

/etc/init.d/tomcat start

To stop:

/etc/int.d/tomcat stop

To restart:

/etc/init.d/tomcat restart

Step 5. Now enable Apache Tomcat service to start on every server boot
For RHEL / CentOS 6.x & Ubuntu

chkconfig tomcat on

To confirm if the service is added successfully:

chkconfig --list tomcat on

For RHEL / CentOS 7.x

systemctl enable tomcat

To confirm if the service is added successfully:

systemctl status tomcat

Hope this helps!
Read More

How to create a VirtualHost for Tomcat

To create Tomcat VirtualHost you just need to edit tomcat_dir/conf/server.xml and inside Engine tag place following code:

<Host appbase="/home/apache-tomcat-7.0.90/webapps/sample" autodeploy="true" name="virtual_host_name" unpackwars="true">
   <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="sample_catalina_logger." suffix=".txt" timestamp="true" />
   <Context path="" docBase="/home/apache-tomcat-7.0.90/webapps/sample" reloadable="true" />
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="sample_access_log." suffix=".txt" pattern="common" />
</Host>


Then you will be abble to access your like: virtual_host_name:8080.
Read More