This directory contains shell scripts to start and stop the Ranger Audit Server services locally (outside of Docker).
The Ranger Audit Server consists of three microservices:
Each service has its own scripts folder with start/stop scripts in its main directory.
Before running these scripts, ensure you have:
JAVA_HOME setcd /path/to/ranger-audit-server mvn clean package -DskipTests
./scripts/start-all-services.sh
This script will start all three services in the correct order:
./scripts/stop-all-services.sh
This script will stop all three services in reverse order.
Each service can also be started/stopped individually:
# Start ./ranger-audit-server-service/scripts/start-audit-server.sh # Stop ./ranger-audit-server-service/scripts/stop-audit-server.sh
Default Ports: 7081 (HTTP), 7182 (HTTPS) Health Check: http://localhost:7081/api/audit/health
# Start ./ranger-audit-consumer-solr/scripts/start-consumer-solr.sh # Stop ./ranger-audit-consumer-solr/scripts/stop-consumer-solr.sh
Default Port: 7091 Health Check: http://localhost:7091/api/health
# Start ./ranger-audit-consumer-hdfs/scripts/start-consumer-hdfs.sh # Stop ./ranger-audit-consumer-hdfs/scripts/stop-consumer-hdfs.sh
Default Port: 7092 Health Check: http://localhost:7092/api/health
Each script supports the following environment variables:
AUDIT_SERVER_HOME_DIR - Home directory (default: target/)AUDIT_SERVER_CONF_DIR - Configuration directory (default: src/main/resources/conf/)AUDIT_SERVER_LOG_DIR - Log directory (default: logs/)AUDIT_SERVER_HEAP - JVM heap settings (default: -Xms512m -Xmx2g)AUDIT_SERVER_OPTS - Additional JVM optionsKERBEROS_ENABLED - Enable Kerberos authentication (default: false)AUDIT_CONSUMER_HOME_DIR - Home directory (default: target/)AUDIT_CONSUMER_CONF_DIR - Configuration directory (default: src/main/resources/conf/)AUDIT_CONSUMER_LOG_DIR - Log directory (default: logs/)AUDIT_CONSUMER_HEAP - JVM heap settings (default: -Xms512m -Xmx2g)AUDIT_CONSUMER_OPTS - Additional JVM optionsKERBEROS_ENABLED - Enable Kerberos authentication (default: false)# Set custom heap size and log directory export AUDIT_SERVER_HEAP="-Xms1g -Xmx4g" export AUDIT_SERVER_LOG_DIR="/var/log/ranger/range-audit-server" ./ranger-audit-server-service/scripts/start-audit-server.sh
Each service creates logs in its respective logs/ directory (or custom location if set):
Audit Server:
logs/ranger-audit-server.loglogs/catalina.outlogs/ranger-audit-server.pidSolr Consumer:
logs/ranger-audit-consumer-solr.loglogs/catalina.outlogs/ranger-audit-consumer-solr.pidHDFS Consumer:
logs/ranger-audit-consumer-hdfs.loglogs/catalina.outlogs/ranger-audit-consumer-hdfs.pid# Tail audit server logs tail -f ranger-audit-server-service/logs/ranger-audit-server.log # Tail Solr consumer logs tail -f ranger-audit-consumer-solr/logs/ranger-audit-consumer-solr.log # Tail HDFS consumer logs tail -f ranger-audit-consumer-hdfs/logs/ranger-audit-consumer-hdfs.log
To enable debug logging for troubleshooting, modify the logback.xml configuration file in the service's conf/ directory:
For Audit Server: Edit ranger-audit-server-service/src/main/resources/conf/logback.xml (or /opt/ranger-audit-server/conf/logback.xml in Docker):
<!-- Change the root logger level from INFO to DEBUG --> <root level="DEBUG"> <appender-ref ref="LogToConsole" /> <appender-ref ref="LogToRollingFile" /> </root> <!-- Or enable debug for specific packages --> <logger name="org.apache.ranger.audit" level="DEBUG" additivity="false"> <appender-ref ref="LogToConsole" /> <appender-ref ref="LogToRollingFile" /> </logger>
For Consumers (HDFS/Solr): Similarly, edit the logback.xml in their respective conf/ directories.
Available log levels: TRACE, DEBUG, INFO, WARN, ERROR
After modifying the logback configuration, restart the service for changes to take effect.
Check if already running:
ps aux | grep ranger-audit
Check for port conflicts:
lsof -i :7081 # Audit Server lsof -i :7091 # Solr Consumer lsof -i :7092 # HDFS Consumer
Verify WAR file exists:
find ./target -name "*.war"
Check logs for errors:
tail -100 logs/catalina.out
If a service doesn't stop gracefully, the script will force kill after 30 seconds. You can also manually kill:
# Find and kill the process ps aux | grep "AuditServerApplication" kill <PID> # Or force kill kill -9 <PID> # Remove stale PID file rm -f logs/ranger-audit-server.pid
If Java is not detected:
# Set JAVA_HOME export JAVA_HOME=/path/to/java export PATH=$JAVA_HOME/bin:$PATH # Verify java -version
Check Kafka bootstrap servers configuration in:
ranger-audit-server-service/src/main/resources/conf/ranger-audit-server-site.xmlranger-audit-consumer-solr/src/main/resources/conf/ranger-audit-consumer-solr-site.xmlranger-audit-consumer-hdfs/src/main/resources/conf/ranger-audit-consumer-hdfs-site.xml┌─────────────────────┐
│ Ranger Plugins │
│ (HDFS, Hive, etc.) │
└──────────┬──────────┘
│ REST API
▼
┌─────────────────────┐
│ Audit Server │ Port 7081
│ (Producer) │
└──────────┬──────────┘
│ Kafka
▼
┌──────────────┐
│ Kafka │
│ (Topic) │
└──────┬───────┘
│
┌────┴────┬──────┬─────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Solr │ │ HDFS │ │ New │ ... │ Nth │
│ Consumer │ │ Consumer │ │ Consumer │ │ Consumer │
│ (7091) │ │ (7092) │ │ (709N) │ │ (709N+1) │
└────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Solr │ │ HDFS │ │ New │ │ Nth │
│ (Index) │ │ (Storage)│ │(Dest) │ │ (Dest) │
└─────────┘ └──────────┘ └──────────┘ └──────────┘
To add a new audit destination (e.g., Elasticsearch, MongoDB, Cloud Storage, etc.), follow these steps:
Create a new Maven module in the ranger-audit-server directory:
cd ranger-audit-server mkdir ranger-audit-consumer-<destination> cd ranger-audit-consumer-<destination>
Create a pom.xml based on the existing consumers (Solr or HDFS). Key dependencies:
Create the main Spring Boot application class:
package org.apache.ranger.audit.consumer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class YourDestinationConsumerApplication { public static void main(String[] args) { SpringApplication.run(YourDestinationConsumerApplication.class, args); } }
Implement a Kafka consumer to read audit events:
package org.apache.ranger.audit.consumer; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Service; @Service public class YourDestinationConsumer { @KafkaListener(topics = "${ranger.audit.kafka.topic:ranger_audits}", groupId = "${ranger.audit.kafka.consumer.group:audit-consumer-your-destination}") public void consumeAudit(String auditEvent) { // Parse audit event // Transform if needed // Write to your destination } }
Create configuration files in src/main/resources/conf/:
ranger-audit-consumer--site.xml:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <property> <name>ranger.audit.kafka.bootstrap.servers</name> <value>localhost:9092</value> </property> <property> <name>ranger.audit.kafka.topic</name> <value>ranger_audits</value> </property> <property> <name>ranger.audit.your-destination.url</name> <value>http://localhost:PORT</value> </property> <!-- Add destination-specific configurations --> </configuration>
application.yml:
server: port: 709X # Choose next available port (e.g., 7093, 7094...) spring: kafka: bootstrap-servers: ${ranger.audit.kafka.bootstrap.servers:localhost:9092} consumer: group-id: audit-consumer-your-destination auto-offset-reset: earliest key-deserializer: org.apache.kafka.common.serialization.StringDeserializer value-deserializer: org.apache.kafka.common.serialization.StringDeserializer # Add destination-specific Spring configurations
Create a scripts directory with start/stop scripts:
scripts/start-consumer-.sh:
#!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SERVICE_DIR="$(dirname "$SCRIPT_DIR")" # Environment variables AUDIT_CONSUMER_HOME_DIR="${AUDIT_CONSUMER_HOME_DIR:-$SERVICE_DIR/target}" AUDIT_CONSUMER_CONF_DIR="${AUDIT_CONSUMER_CONF_DIR:-$SERVICE_DIR/src/main/resources/conf}" AUDIT_CONSUMER_LOG_DIR="${AUDIT_CONSUMER_LOG_DIR:-$SERVICE_DIR/logs}" AUDIT_CONSUMER_HEAP="${AUDIT_CONSUMER_HEAP:--Xms512m -Xmx2g}" AUDIT_CONSUMER_OPTS="${AUDIT_CONSUMER_OPTS:-}" KERBEROS_ENABLED="${KERBEROS_ENABLED:-false}" # Find WAR file WAR_FILE=$(find "$AUDIT_CONSUMER_HOME_DIR" -name "ranger-audit-consumer-<destination>*.war" | head -1) if [ -z "$WAR_FILE" ]; then echo "Error: WAR file not found in $AUDIT_CONSUMER_HOME_DIR" exit 1 fi # Start service java $AUDIT_CONSUMER_HEAP $AUDIT_CONSUMER_OPTS \ -Dlog.dir="$AUDIT_CONSUMER_LOG_DIR" \ -Dconf.dir="$AUDIT_CONSUMER_CONF_DIR" \ -jar "$WAR_FILE" > "$AUDIT_CONSUMER_LOG_DIR/catalina.out" 2>&1 & echo $! > "$AUDIT_CONSUMER_LOG_DIR/ranger-audit-consumer-<destination>.pid" echo "Started Ranger Audit Consumer (<destination>) with PID: $(cat $AUDIT_CONSUMER_LOG_DIR/ranger-audit-consumer-<destination>.pid)"
scripts/stop-consumer-.sh:
#!/bin/bash SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SERVICE_DIR="$(dirname "$SCRIPT_DIR")" AUDIT_CONSUMER_LOG_DIR="${AUDIT_CONSUMER_LOG_DIR:-$SERVICE_DIR/logs}" PID_FILE="$AUDIT_CONSUMER_LOG_DIR/ranger-audit-consumer-<destination>.pid" if [ -f "$PID_FILE" ]; then PID=$(cat "$PID_FILE") kill "$PID" echo "Stopped Ranger Audit Consumer (<destination>) with PID: $PID" rm -f "$PID_FILE" else echo "PID file not found. Service may not be running." fi
Make scripts executable:
chmod +x scripts/*.sh
Add the new module to the parent ranger-audit-server/pom.xml:
<modules> <module>ranger-audit-server-service</module> <module>ranger-audit-consumer-solr</module> <module>ranger-audit-consumer-hdfs</module> <module>ranger-audit-consumer-<destination></module> </modules>
Add your consumer to scripts/start-all-services.sh:
# Start Your Destination Consumer echo "Starting Ranger Audit Consumer (<destination>)..." cd "$BASE_DIR/ranger-audit-consumer-<destination>" ./scripts/start-consumer-<destination>.sh echo "Waiting 5 seconds for consumer to initialize..." sleep 5
Add to scripts/stop-all-services.sh:
# Stop Your Destination Consumer echo "Stopping Ranger Audit Consumer (<destination>)..." cd "$BASE_DIR/ranger-audit-consumer-<destination>" ./scripts/stop-consumer-<destination>.sh
# Build the new consumer cd ranger-audit-consumer-<destination> mvn clean package -DskipTests # Test individually ./scripts/start-consumer-<destination>.sh # Check health (implement a health endpoint) curl http://localhost:709X/api/health # View logs tail -f logs/ranger-audit-consumer-<destination>.log # Stop when done ./scripts/stop-consumer-<destination>.sh
Update this README to include:
# Build specific service cd ranger-audit-server-service mvn clean package cd ../ranger-audit-consumer-solr mvn clean package cd ../ranger-audit-consumer-hdfs mvn clean package
Add debug options to the OPTS environment variable:
export AUDIT_SERVER_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" ./ranger-audit-server-service/scripts/start-audit-server.sh
Then attach your IDE debugger to port 5005.