Graylog is a powerful open-source log management solution that easily collects, analyzes, and monitors log data. This guide will walk you through the installation of Graylog on CentOS. Before starting, make sure you have root or sudo privileges on your CentOS server.
Prerequisites
- CentOS 7 or 8: Graylog works well on both CentOS 7 and 8.
- Java (OpenJDK): Graylog requires Java to run.
- MongoDB: Graylog uses MongoDB to store data.
- Elasticsearch: Graylog needs Elasticsearch to index and search log data.
Step 1: Update the System
Before starting, it’s a good idea to update your system packages to the latest versions.
sudo yum update -y
Step 2: Install Java
Graylog requires Java to run. We’ll install OpenJDK 11.
sudo yum install java-11-openjdk-devel -y
Verify the Java installation:
java -version
Step 3: Install and Configure MongoDB
MongoDB is required by Graylog to store its configuration data.
- First, create a MongoDB repository file:
sudo vi /etc/yum.repos.d/mongodb-org.repo
- Add the following content to the file:
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
- Install MongoDB:
sudo yum install -y mongodb-org
- Start and enable MongoDB:
sudo systemctl start mongod
sudo systemctl enable mongod
Step 4: Install and Configure Elasticsearch
Graylog uses Elasticsearch to store log data, so you need to install it.
- Download the Elasticsearch repository:
sudo vi /etc/yum.repos.d/elasticsearch.repo
- Add the following content:
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
- Install Elasticsearch:
sudo yum install elasticsearch -y
- Open the Elasticsearch configuration file:
sudo vi /etc/elasticsearch/elasticsearch.yml
Uncomment the following lines and set them as follows:
cluster.name: graylog
network.host: 127.0.0.1
- Start and enable Elasticsearch:
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Step 5: Install and Configure Graylog
- First, download and install the Graylog repository:
sudo rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-4.3-repository_latest.rpm
- Install Graylog:
sudo yum install graylog-server -y
- Configure Graylog by editing the configuration file:
sudo vi /etc/graylog/server/server.conf
Set a password secret and a hashed password for the admin user. You can generate the password secret using the following command:
pwgen -N 1 -s 96
Place this generated string in the password_secret
field.
You can also generate an admin password hash:
echo -n yourpassword | sha256sum
Add this hash to the root_password_sha2
field.
Set the rest_listen_uri
and web_listen_uri
fields to the server’s IP or localhost, depending on your setup.
Step 6: Start and Enable Graylog
- Start the Graylog service:
sudo systemctl start graylog-server
- Enable Graylog to start on boot:
sudo systemctl enable graylog-server
Step 7: Access the Graylog Web Interface
Once Graylog is up and running, you can access the web interface by going to http://your-server-ip:9000
in your web browser. Use the admin
username and the password you set earlier to log in.
You have successfully installed Graylog on CentOS. You can begin configuring inputs to collect logs from various sources and start analyzing your data!