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 |
Just wanted to say thanks, it works really well! :-)
Not longer work with current CentOS Version 6.5
[root@localhost ~]# sh graylog2-bootstrap.sh
/etc/yum.repos.d/10gen-mongodb.repo found
/etc/yum.repos.d/CentOS-Base.repo found
/etc/yum.repos.d/epel.repo found
/etc/yum.repos.d/passenger.repo found
Installing MongoDB...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.copahost.com
* epel: mirrors.n-ix.net
* extras: ftp.plusline.de
* passenger: mirror.hmdc.harvard.edu
* updates: centos.copahost.com
Setting up Install Process
Package mongo-10gen-2.4.9-mongodb_1.x86_64 already installed and latest version
Package mongo-10gen-server-2.4.9-mongodb_1.x86_64 already installed and latest version
Nothing to do
Installing init script of MongoDB...
Starting MongoDB...
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 2624
all output going to: /var/log/mongo/mongod.log
ERROR: child process failed, exited with error number 100
[FAILED]
Installing ElasticSearch...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15.4M 100 15.4M 0 0 6570k 0 0:00:02 0:00:02 --:--:-- 7002k
Installing ElasticSearch service wrapper...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1998k 100 1998k 0 0 657k 0 0:00:03 0:00:03 --:--:-- 1314k
mv: cannot move `elasticsearch-elasticsearch-servicewrapper-8d9c6bb/service' to `./service': Directory not empty
useradd: user 'elasticsearch' already exists
Installing init script of ElasticSearch...
Detected RHEL or Fedora:
The ElasticSearch daemon is already installed.
Starting ElasticSearch...
Starting ElasticSearch...
Waiting for ElasticSearch......................
WARNING: ElasticSearch may have failed to start.
Installing graylog2-server...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8652k 100 8652k 0 0 7982k 0 0:00:01 0:00:01 --:--:-- 7982k
ln: creating symbolic link `graylog2.conf': File exists
sed: can't read /etc/graylog2.conf: No such file or directory
Installing init script of graylog2-server...
sed: -e expression #1, char 49: unterminated `s' command
Starting graylog2-server...
Cannot find /graylog2-server.jar
/graylog2-server.jar is absent or does not have read permission
Installing graylog2-web-interface...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.copahost.com
* epel: mirrors.n-ix.net
* extras: ftp.plusline.de
* passenger: mirror.hmdc.harvard.edu
* updates: centos.copahost.com
Setting up Install Process
Package ruby-1.8.7.352-13.el6.x86_64 already installed and latest version
Package ruby-devel-1.8.7.352-13.el6.x86_64 already installed and latest version
Package ruby-rdoc-1.8.7.352-13.el6.x86_64 already installed and latest version
Package rubygems-1.3.7-5.el6.noarch already installed and latest version
Nothing to do
Successfully installed bundler-1.5.2
1 gem installed
Installing ri documentation for bundler-1.5.2...
Installing RDoc documentation for bundler-1.5.2...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.copahost.com
* epel: mirrors.n-ix.net
* extras: ftp.plusline.de
* passenger: mirror.hmdc.harvard.edu
* updates: centos.copahost.com
Setting up Install Process
Package httpd-2.2.15-29.el6.centos.x86_64 already installed and latest version
Package 1:mod_passenger-3.0.19-1.el6.x86_64 already installed and latest version
Nothing to do
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 739k 100 739k 0 0 913k 0 --:--:-- --:--:-- --:--:-- 913k
The source :rubygems is deprecated because HTTP requests are insecure.
Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
Fetching gem metadata from http://rubygems.org/.......
Fetching additional metadata from http://rubygems.org/..
Using rake (0.9.2.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
creating Makefile
make
gcc -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-pr otector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing -fPIC -c system_timer_native.c
make: gcc: Command not found
make: *** [system_timer_native.o] Error 127
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/SystemTimer-1.2.3 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/SystemTimer-1.2.3/ext/system_timer/gem_make.out
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script worked well on my fresh CentOS 6.3 64bit box, but there were a few minor issues.
Prior to using your script, I did an install from source & ended up with errors because ruby was missing dependencies. Since it was a fresh install & I didn't want to spend a lot of time debugging the Ruby installation I just reformatted & went at it again.This time I made sure to install these dependencies prior to running your script:
libyaml-0.1.3-1.el6.x86_64
libyaml-devel-0.1.3-1.el6.x86_64
I also had to manually add user/auth in mongo (first I changed the db creds in graylog2.conf)
db.addUser('grayloguser', 'graylogpass')
db.auth('grayloguser', 'graylogpass')