Last active
October 1, 2021 09:46
-
-
Save SeonghoonKim/4378896 to your computer and use it in GitHub Desktop.
graylog2 install script for RHEL/CentOS 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MONGODB_REPO="/etc/yum.repos.d/10gen-mongodb.repo" | |
CENTOS_REPO="/etc/yum.repos.d/CentOS-Base.repo" | |
EPEL_REPO="/etc/yum.repos.d/epel.repo" | |
PASSENGER_REPO="/etc/yum.repos.d/passenger.repo" | |
APP_ROOT="/opt" | |
[ -f "$APP_ROOT" ] || mkdir -p $APP_ROOT | |
if [ -f ${MONGODB_REPO} ]; then | |
echo "$MONGODB_REPO found" | |
else | |
cat << 'EOF' > ${MONGODB_REPO} | |
[10gen] | |
name=10gen Repository | |
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/$basearch | |
gpgcheck=0 | |
EOF | |
fi | |
if [ -f ${CENTOS_REPO} ]; then | |
echo "$CENTOS_REPO found" | |
else | |
echo "Creating $CENTOS_REPO" | |
cat << 'EOF' > ${CENTOS_REPO} | |
# CentOS-Base.repo for RHEL6 | |
[base] | |
name=CentOS-6 - Base | |
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os | |
#baseurl=http://mirror.centos.org/centos/6/os/$basearch/ | |
gpgcheck=1 | |
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 | |
#released updates | |
[update] | |
name=CentOS-6 - Updates | |
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates | |
#baseurl=http://mirror.centos.org/centos/6/updates/$basearch/ | |
gpgcheck=1 | |
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 | |
EOF | |
fi | |
if [ -f ${EPEL_REPO} ]; then | |
echo "$EPEL_REPO found" | |
else | |
echo "Creating $EPEL_REPO" | |
cat << 'EOF' > ${EPEL_REPO} | |
[epel] | |
name=Extra Packages for Enterprise Linux 6 - $basearch | |
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch | |
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch | |
failovermethod=priority | |
enabled=1 | |
gpgcheck=0 | |
EOF | |
fi | |
if [ -f ${PASSENGER_REPO} ]; then | |
echo "$PASSENGER_REPO found" | |
else | |
echo "Creating $PASSENGER_REPO" | |
cat << 'EOF' > ${PASSENGER_REPO} | |
### Name: Phusion Passenger RPM Repository for Red Hat Enterprise 6 | |
### URL: http://passenger.stealthymonkeys.com/ | |
[passenger] | |
name = Red Hat Enterprise $releasever - Phusion Passenger | |
baseurl = http://passenger.stealthymonkeys.com/rhel/$releasever/$basearch | |
mirrorlist = http://passenger.stealthymonkeys.com/rhel/mirrors | |
#mirrorlist = file:///etc/yum.repos.d/mirrors-passenger | |
enabled = 1 | |
gpgcheck = 0 | |
EOF | |
fi | |
echo "Installing MongoDB..." | |
yum install -y mongo-10gen mongo-10gen-server | |
echo "Installing init script of MongoDB..." | |
chkconfig --level 2345 mongod on | |
echo "Starting MongoDB..." | |
service mongod start | |
echo "Installing ElasticSearch..." | |
cd $APP_ROOT | |
curl -L http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.1.tar.gz | tar -xz | |
ln -s elasticsearch-0.20.1/ elasticsearch | |
echo "Installing ElasticSearch service wrapper..." | |
cd elasticsearch/bin | |
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz | |
mv elasticsearch-elasticsearch-servicewrapper-*/service . | |
rm -rf elasticsearch-elasticsearch-servicewrapper-* | |
cd $APP_ROOT | |
useradd elasticsearch -d $APP_ROOT/elasticsearch | |
chown -R elasticsearch:elasticsearch elasticsearch* | |
sed -i -e "s|# cluster.name: elasticsearch|cluster.name: graylog2|" $APP_ROOT/elasticsearch/config/elasticsearch.yml | |
sed -i -e "s|set.default.ES_HOME=<Path to ElasticSearch Home>|set.default.ES_HOME=$APP_ROOT/elasticsearch|" $APP_ROOT/elasticsearch/bin/service/elasticsearch.conf | |
sed -i -e "s|#RUN_AS_USER=|RUN_AS_USER=elasticsearch|" $APP_ROOT/elasticsearch/bin/service/elasticsearch | |
echo "Installing init script of ElasticSearch..." | |
$APP_ROOT/elasticsearch/bin/service/elasticsearch install | |
echo "Starting ElasticSearch..." | |
service elasticsearch start | |
echo "Installing graylog2-server..." | |
cd $APP_ROOT | |
curl -L https://github.com/downloads/Graylog2/graylog2-server/graylog2-server-0.9.6p1.tar.gz | tar -xz | |
ln -s graylog2-server-0.9.6p1 graylog2-server | |
cd graylog2-server | |
mv graylog2.conf.example graylog2.conf | |
cd /etc | |
ln -s /windmill/graylog2-server/graylog2.conf graylog2.conf | |
sed -i -e 's|mongodb_useauth = true|mongodb_useauth = false|' /etc/graylog2.conf | |
echo "Installing init script of graylog2-server..." | |
cat << 'EOF' > /etc/init.d/graylog2-server | |
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: gaylog2-server | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Graylog2-server init script | |
# Description: Graylog2-server init script | |
### END INIT INFO | |
## Source function library. | |
. /etc/init.d/functions | |
NAME="graylog2-server" | |
GRAYLOG2_HOME= | |
GRAYLOG2_JAR=$GRAYLOG2_HOME/graylog2-server.jar | |
GRAYLOG2_CONF="/etc/graylog2.conf" | |
GRAYLOG2_OUT="/var/log/graylog2.log" | |
PID_DIR="/var/run/graylog2" | |
PID_FILE="${PID_DIR}/${NAME}.pid" | |
LOCK_FILE="/var/lock/subsys/${NAME}" | |
JAVA="/usr/bin/java" | |
JAVA_OPTS="-server -Xms512m -Xmx512m" | |
RUN_AS_USER=root | |
if [ ! -d "$PID_DIR" ]; then | |
mkdir "$PID_DIR" | |
chown $RUN_AS_USER "$PID_DIR" | |
fi | |
if [ ! -r "$GRAYLOG2_JAR" ]; then | |
echo "Cannot find $GRAYLOG2_JAR" | |
echo "${GRAYLOG2_JAR} is absent or does not have read permission" | |
exit 1 | |
fi | |
touch "$GRAYLOG2_OUT" | |
chown $RUN_AS_USER "$GRAYLOG2_OUT" | |
start() { | |
echo "Starting $NAME: " | |
COMMAND="$JAVA $JAVA_OPTS -jar $GRAYLOG2_JAR -f $GRAYLOG2_CONF -p $PID_FILE >> \"$GRAYLOG2_OUT\" 2>&1 &" | |
daemon --check=${NAME} --user=${RUN_AS_USER} --pidfile=${PID_FILE} ${COMMAND} | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && touch $LOCK_FILE | |
return $RETVAL | |
} | |
stop() { | |
echo "Stoping $NAME: " | |
killproc -p ${PID_FILE} -d 5 ${NAME} | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE | |
return $RETVAL | |
} | |
restart() { | |
stop | |
sleep 1 | |
start | |
} | |
dump() { | |
echo "Dumping $NAME: " | |
PID=`cat $PID_FILE` | |
kill -3 $PID | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && success $"Dumped $NAME." || failure $"Failed to dump $NAME." | |
return $RETVAL | |
} | |
rh_status() { | |
status -p ${PID_FILE} ${NAME} | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
start | |
;; | |
stop) | |
rh_status_q || exit 0 | |
stop | |
;; | |
restart) | |
restart | |
;; | |
status) | |
rh_status | |
;; | |
dump) | |
rh_status_q || exit 0 | |
dump | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
restart | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|dump}" | |
exit 1 | |
esac | |
exit $? | |
EOF | |
sed -i -e "s|GRAYLOG2_HOME=|GRAYLOG2_HOME=$APP_ROOT/elasticsearch" /etc/init.d/graylog2-server | |
chmod u+x /etc/init.d/graylog2-server | |
chkconfig graylog2-server on | |
echo "Starting graylog2-server..." | |
service graylog2-server start | |
echo "Installing graylog2-web-interface..." | |
yum install -y ruby ruby-devel ruby-rdoc rubygems | |
gem install bundler | |
yum install -y httpd mod_passenger | |
cd $APP_ROOT | |
curl -L https://github.com/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-0.9.6p1.tar.gz | tar -xz | |
ln -s graylog2-web-interface-0.9.6p1 graylog2-web-interface | |
cd graylog2-web-interface | |
bundle install | |
chown -R apache:apache $APP_ROOT/graylog2-web-interface* | |
cat << EOF >> /etc/httpd/conf.d/passenger.conf | |
<VirtualHost *:80> | |
ServerName graylog2.example.com | |
ServerAlias graylog2.example.com | |
DocumentRoot $APP_ROOT/graylog2-web-interface/public | |
SetEnv MONGOID_HOST 'localhost' | |
SetEnv MONGOID_PORT '27017' | |
SetEnv MONGOID_DATABASE 'graylog2' | |
<Directory $APP_ROOT/graylog2-web-interface/public> | |
Allow from all | |
Options -MultiViews | |
</Directory> | |
</VirtualHost> | |
EOF | |
chkconfig --level 2345 httpd on | |
service httpd restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not longer work with current CentOS Version 6.5