Category Archives: Linux

Discover DevOps roles and learn Linux from basics to advanced at DevOpsRoles.com. Detailed guides and in-depth articles to master Linux for DevOps careers.

Mastering the lsof command example:Essential for Linux System Administration

Introduction

lsof command meaning “List open files“. This command will not find CentOS7/RHEL. We will install lsof command example as below:

$ sudo yum install lsof

In the realm of Linux administration, understanding the tools at your disposal is key to effective system management. The lsof command, which stands for “List Open Files”, is an indispensable utility that provides crucial visibility into the system’s file usage. By listing information about files opened by processes, lsof helps administrators manage resources, troubleshoot system issues, and ensure secure operations. This guide aims to demystify the lsof command through practical examples, enhancing your system management toolkit.

Basic Usage

lsof

This will display a list of all open files and the processes that are using them.

lsof command examples

List open files

$ lsof -n

Kill a process running on port 8443

$ lsof -i :8443 | awk '{print $2}' | tail -n 1 | xargs kill
# or
$ lsof -i :8443  | awk 'NR > 1 {print $2}' | xargs --no-run-if-empty kill

Show the 15 Largest Open Files in Linux.

$ lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 }' | sort -n -u | tail -n 15

List User-Specific Opened Files. This will display a list of all open files that are being used by the specified user.

$ lsof -u huupv

Search by PID

$ lsof -p 1

Exclude User with ^ Character

$ lsof -i -u^root

List TCP Port ranges 8000-9000

$ lsof -i TCP:8000-9000

Conclusion

The lsof command is a powerful tool in the Linux administrator’s arsenal, offering deep insights into the system’s interaction with files. From tracking down process-specific files to managing system resources, lsof facilitates a wide range of administrative tasks.

By mastering its usage through the examples provided, you enhance your capabilities in system management, contributing to the overall efficiency and security of your operations. Dive into these examples to leverage lsof effectively, ensuring your Linux systems run smoothly and securely. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Guide to Install Python 3.6 on Centos 6

Introduction

OS Centos 6 is the default Python version 2. How to Install Python 3.6 on Centos 6. Python is a powerful and flexible programming language widely used in various fields such as web development, data science, artificial intelligence, and DevOps. Python 3.6 brings many improvements and new features, enhancing performance and security.

In this article, we will guide you through the process of installing Python 3.6 on CentOS 6, one of the popular Linux operating systems for server environments. This installation will allow you to take full advantage of Python 3.6 in your projects.

Installation packages pre-requisites

sudo yum -y install gcc openssl-devel bzip2-devel wget

How to Install Python 3.6 on Centos 6

cd /tmp/
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
tar xzf Python-3.6.6.tgz
cd Python-3.6.6
./configure --enable-optimizations
sudo make altinstall

Create symbolic link

sudo ln -sfn /usr/local/bin/python3.6 /usr/bin/python3.6

Python verifying new version.

[huupv2@server1 ~]$ python -V
Python 3.6.6

The result is Python 3.6 on Centos 6.

[huupv2@server1 ~]$ cat /etc/redhat-release
CentOS release 6.5 (Final)
[huupv2@server1 ~]$ ll /usr/bin/python*
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python
lrwxrwxrwx 1 root root    6 Jul 19  2018 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python2.6
lrwxrwxrwx 1 root root    9 Mar  8 13:26 /usr/bin/python3 -> python3.4
-rwxr-xr-x 2 root root 6088 Oct  5  2019 /usr/bin/python3.4
-rwxr-xr-x 2 root root 6088 Oct  5  2019 /usr/bin/python3.4m
lrwxrwxrwx 1 root root   24 Mar  8 14:45 /usr/bin/python3.6 -> /usr/local/bin/python3.6

Configure alias python on .bashrc file

[huupv2@server1 ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias python='/usr/bin/python3.6'

Check Python version 3.6 on Centos 6

[huupv2@server1 ~]$ python
Python 3.6.6 (default, Mar  8 2021, 14:41:43)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[huupv2@server1 ~]$

Conclusion

You have to install Python 3.6 on Centos 6. Installing Python 3.6 on CentOS 6 may present some challenges, but with this detailed guide, you can easily accomplish it. Python 3.6 will open up many new opportunities for your projects, from web application development to data processing and automating DevOps workflows.

We wish you success in installing and leveraging the full potential of Python 3.6 on CentOS 6. If you encounter any difficulties, don’t hesitate to contact us or refer to community support resources. I hope will this your helpful. Thank you for reading the DevopsRoles page!

JIRA installing and configure on CentOS

Introduction

How to install and configure jira on Centos. Installing and configuring JIRA on CentOS involves a series of systematic steps to set up this popular project management tool effectively. Begin by preparing your CentOS system with the necessary prerequisites, including Java. Then, download and install the JIRA software from Atlassian’s official site. Configuration involves setting up a database, typically PostgreSQL or MySQL, and adjusting the JIRA setup wizard to connect to your newly prepared database. This process ensures that JIRA runs smoothly on CentOS, providing a robust platform for managing your projects. Now, let’s proceed with the JIRA installation and configuration on CentOS.

JIRA installing

Install Java

[vagrant@DevopsRoles ~]$ sudo yum install java-1.8.0-openjdk*

Install MySQL on Centos 7

Link refers to installing MySQL here.

Create a user for installation jira.

[vagrant@DevopsRoles ~]$ sudo useradd jira
[vagrant@DevopsRoles ~]$ sudo passwd jira
[vagrant@DevopsRoles ~]$ echo "jira ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
[vagrant@DevopsRoles ~]$ su -l jira
Password:
[jira@DevopsRoles ~]$

Create a temporary install directory:

[jira@DevopsRoles ~]$ mkdir jira && cd jira

Download jira

Link download here:

[jira@DevopsRoles jira]$ wget https://product-downloads.atlassian.com/software/jira/downloads/atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ ls -l
total 399948
-rw-rw-r--. 1 jira jira 409545222 Feb 15 11:02 atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ chmod u+x atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ ./atlassian-jira-software-8.13.4-x64.bin

The result is as follows:

[jira@DevopsRoles jira]$ ./atlassian-jira-software-8.13.4-x64.bin
Unpacking JRE ...
Starting Installer ...
You do not have administrator rights to this machine and as such, some installation options will not be available. Are you sure you want to continue?
Yes [y, Enter], No [n]
y

This will install Jira Software 8.13.4 on your computer.
OK [o, Enter], Cancel [c]
o
Click Next to continue, or Cancel to exit Setup.

Choose the appropriate installation or upgrade option.
Please choose one of the following:
Express Install (use default settings) [1], Custom Install (recommended for advanced users) [2, Enter], Upgrade an existing Jira installation [3]
1

Details on where Jira Software will be installed and the settings that will be used.
Installation Directory: /home/jira/atlassian/jira
Home Directory: /home/jira/atlassian/application-data/jira
HTTP Port: 8080
RMI Port: 8005
Install as service: No
Install [i, Enter], Exit [e]
i

Extracting files ...


Please wait a few moments while Jira Software is configured.

Installation of Jira Software 8.13.4 is complete
Start Jira Software 8.13.4 now?
Yes [y, Enter], No [n]
y

Please wait a few moments while Jira Software starts up.
Launching Jira Software ...

Installation of Jira Software 8.13.4 is complete
Your installation of Jira Software 8.13.4 is now ready and can be accessed
via your browser.
Jira Software 8.13.4 can be accessed at http://localhost:8080
Finishing installation ...
[jira@DevopsRoles jira]$

JIRA’s directory structure looks like this:

[jira@DevopsRoles jira]$ cd ../
[jira@DevopsRoles ~]$ ls -l
total 0
drwxrwxr-x. 4 jira jira 42 Feb 22 14:19 atlassian
drwxrwxr-x. 2 jira jira 52 Feb 22 14:20 jira
[jira@DevopsRoles ~]$ tree -d -L 3 atlassian/
atlassian/
├── application-data
│   └── jira
│       ├── caches
│       ├── data
│       ├── export
│       ├── import
│       ├── log
│       ├── plugins
│       └── tmp
└── jira
    ├── atlassian-jira
    │   ├── aui-examples
    │   ├── decorators
    │   ├── func
    │   ├── images
    │   ├── includes
    │   ├── META-INF
    │   ├── portlets
    │   ├── secure
    │   ├── static
    │   ├── static-assets
    │   ├── styles
    │   ├── template
    │   ├── templates
    │   ├── ui
    │   ├── views
    │   └── WEB-INF
    ├── bin
    ├── conf
    │   └── Catalina
    ├── external-source
    ├── jre
    │   ├── bin
    │   ├── lib
    │   └── man
    ├── lib
    ├── licenses
    ├── logs
    ├── temp
    ├── tomcat-docs
    ├── webapps
    └── work
        └── Catalina

43 directories
[jira@DevopsRoles ~]$

Go to JIRA Installation Directory:

[jira@DevopsRoles ~]$ cd ~/atlassian/jira/
[jira@DevopsRoles jira]$ sudo ./bin/start-jira.sh

start-jira.sh and stop-jira.sh in folder bin

Check JIRA should already be running.

[jira@DevopsRoles jira]$ ps ux | grep jira | grep java | grep -v grep
jira      3184 10.8 24.0 4971344 358732 pts/0  Sl   14:20   0:29 /home/jira/atlassian/jira/jre//bin/java -Djava.util.logging.config.file=/home/jira/atlassian/jira/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms384m -Xmx2048m -XX:InitialCodeCacheSize=32m -XX:ReservedCodeCacheSize=512m -Djava.awt.headless=true -Datlassian.standalone=JIRA -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -Dmail.mime.decodeparameters=true -Dorg.dom4j.factory=com.atlassian.core.xml.InterningDocumentFactory -XX:-OmitStackTraceInFastThrow -Djava.locale.providers=COMPAT -Datlassian.plugins.startup.options= -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Xloggc:/home/jira/atlassian/jira/logs/atlassian-jira-gc-%t.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20M -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintGCCause -XX:+ExplicitGCInvokesConcurrent -Dignore.endorsed.dirs= -classpath /home/jira/atlassian/jira/bin/bootstrap.jar:/home/jira/atlassian/jira/bin/tomcat-juli.jar -Dcatalina.base=/home/jira/atlassian/jira -Dcatalina.home=/home/jira/atlassian/jira -Djava.io.tmpdir=/home/jira/atlassian/jira/temp org.apache.catalina.startup.Bootstrap start

[vagrant@DevopsRoles ~]$ sudo netstat -nplt | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      3184/java

Create user MySQL

mysql -u root -p 
mysql> CREATE DATABASE jiradb CHARACTER SET utf8 COLLATE utf8_bin;
mysql> CREATE USER 'jiradb'@'localhost' IDENTIFIED BY 'Abc123!@#';
mysql> GRANT ALL PRIVILEGES ON jiradb.* TO 'jiradb'@'localhost' WITH GRANT OPTION;

we need a JDBC connector driver for MySQL

[jira@DevopsRoles ~]$ cd && mkdir tmp
[jira@DevopsRoles ~]$ cd tmp/
[jira@DevopsRoles tmp]$ wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.29.tar.gz
[jira@DevopsRoles tmp]$ tar xfp mysql-connector-java-5.1.29.tar.gz
[jira@DevopsRoles tmp]$ find mysql-connector-java-5.1.29 -name "mysql-connector-java-*-bin.jar"
mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar
[jira@DevopsRoles tmp]$ cp mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar ~/atlassian/jira/lib/
[jira@DevopsRoles tmp]$ cd

Restart JIRA

$ sudo ./atlassian/jira/bin/stop-jira.sh
$ sudo ./atlassian/jira/bin/start-jira.sh

Access Browser Jira

Conclusion

JIRA installing and configuring on CentOS. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install Apache cassandra on Centos 6

#Introduction

In this tutorial, How To Install Apache cassandra on Centos 6. Apache Cassandra is a NoSQL database for storing large amounts of data in a decentralized, high availability server cluster.

Step 1: Install Java

I will install Oracle java 7 instead of OpenJDK. Link download Oracle Java 7 here

rpm -ivh /home/huupv/jdk-7u79-linux-x64.rpm

I find both executable files – OpenJDK and Oracle:

find / -name "java" -type f

Check java version

java -version

Setting up the default JDK

alternatives --config java

Step 2: Install Apache cassandra

Cassandra will be installed from the Datastax repository. Create a repository file:/etc/yum.repos.d/datastax.repo

[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

Find the version

yum list dsc2*

Install

yum install dsc21

Start and add to the auto-launch:

service cassandra start
chkconfig cassandra on

Check

cqlsh
nodetool status

Conclusion

You have to Install Apache Cassandra on Centos 6. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to automatically mount a SMB/CIFS Share on CentOS

Introduction

In this tutorial, How to automatically mount a SMB/CIFS Share on CentOS.

Prerequisite

Install necessary packages

yum install samba-client samba-common

Automatically mount a SMB/CIFS Share on CentOS

Install the Automounter

yum install autofs

Create a mount point

mkdir /data/cifs_share

Add an entry to the file /etc/auto.master, as follow:

/data/cifs_share /etc/auto.cifs  --timeout=600 --ghost

create the file /etc/auto.cifs:

share_data -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt
    ://<Host Name>/<Folder Name>

Create /etc/credentials.txt file

username=DOMAIN/User
password=PASSWORD

Secure the credentials.txt file

chmod 0700 /etc/credentials.txt

Restart the automounter service

/etc/init.d/autofs restart

Confirm that the mount is being accessed correctly

mount

Conclusion

You have automatically mounted an SMB/CIFS Share on CentOS. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to install let’s Encrypt SSL on CentOS 7

#Introduction

In this tutorial, How to install Let’s Encrypt SSL on CentOS 7. Let’s Encrypt is a free, automated TLS/SSL certificate web server. In the previous post, I have installed Let’s Encrypt SSL on Centos 6 here.

Prerequisite

yum install -y epel-release mod_ssl

How to install Let’s Encrypt SSL on CentOS 7

yum install -y certbot

Generate a SSL certificate

sudo certbot certonly \
--manual \
--agree-tos \
--preferred-challenges=dns \
--server https://acme-v02.api.letsencrypt.org/directory \
--email huupv@devopsroles.com \
--domains devopsroles.com

Certificated will be available under the folder: /etc/letsencrypt/live/devopsroles.com

/etc/letsencrypt/live/devopsroles.com/fullchain.pem
/etc/letsencrypt/live/devopsroles.com/privkey.pem

Create SystemD service for certbot.service. New file /etc/systemd/system/certbot.service

[Unit]
Description=Renew Let's Encrypt certificates
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --renew-hook "/bin/systemctl --no-block reload nginx" --quiet --agree-tos

Create SystemD service for certbot.timer. New file /etc/systemd/system/certbot.timer

[Unit]
Description=Daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=daily
RandomizedDelaySec=1day
Persistent=true

[Install]
WantedBy=timers.target

Start and enable certbot.timer

systemctl daemon-reload
systemctl start certbot.timer
systemctl enable certbot.timer

List service certbot timer as follow

systemctl list-timers certbot.timer

Conclusion

You have installed Let’s Encrypt SSL on CentOS 7. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to install Let’s Encrypt SSL on CentOS 6

#Introduction

In this tutorial, How to install Let’s Encrypt SSL on CentOS 6. Let’s Encrypt is a free, automated TLS/SSL certificate web server.

Prerequisite

Your server has installed a Web server If it’s not then you can use the command to install a web server

For Nginx

# yum install nginx

For Apache

# yum install httpd mod_ssl

Install LetsEncrypt on Centos 6

curl -o /usr/local/sbin/certbot-auto https://dl.eff.org/certbot-auto
chmod a+x /usr/local/sbin/certbot-auto

Generate a SSL certificate

sudo /usr/local/sbin/certbot-auto certonly \
--manual \
--agree-tos \
--preferred-challenges=dns \
--server https://acme-v02.api.letsencrypt.org/directory \
--email huupv@devopsroles.com \
--domains devopsroles.com

certificated will be available under the folder: /etc/letsencrypt/live/devopsroles.com

/etc/letsencrypt/live/devopsroles.com/fullchain.pem
/etc/letsencrypt/live/devopsroles.com/privkey.pem

Setup a cron job for Let’s Encrypt SSL

# Setting up crontab
crontab -e

# Append the below line to the end of crontab
0 0 * * * /usr/local/sbin/certbot-auto renew --renew-hook "/sbin/service nginx reload" --quiet --agree-tos

HOW TO SETUP NGINX TO USE SSL WITH LETSENCRYPT

For example, as follow

server {
 listen 443;
 ssl on;
 server_name devopsroles.com;
 ssl_certificate /etc/letsencrypt/live/devopsroles.com/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/devopsroles.com/privkey.pem;
 root /etc/nginx/html;
 
}

Conclusion

You have installed Let’s Encrypt SSL on CentOS 6. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Build a repository use Nexus Repository

#Introduction

In this tutorial, How to build a repository use nexus repository. In the previous post, I have installed the Nexus repository here.

Maven build a repository with Nexus Repository

Hosted repository

Create a new repository as below:

Name: maven2-hosted

proxy repository

Create a new proxy repository as below

  • Name: maven2-proxy
  • Remote storage: https://repo1.maven.org/maven2/

group repository

Create a new group repository as below

  • Name: maven2-group
  • Members: maven2-private-example maven2-proxy-example

How to get package from Nexus Repository

I will create a maven project in eclipse.

Edit the pom.xml file. I will get a poi package.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>nexus-devopsroles</groupId>
  <artifactId>maven2</artifactId>
  <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>poi</groupId>
            <artifactId>poi</artifactId>
            <version>2.5.1</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>maven-group</id>
            <name>My Maven Group Repository</name>
            <url>http://192.168.3.4:8081/repository/maven2-group/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>maven-group</id>
            <name>My Maven Group Repository</name>
            <url>http://192.168.3.4:8081/repository/maven2-group/</url>
        </pluginRepository>
    </pluginRepositories>

    <distributionManagement>
        <repository>
            <id>maven2-private-example</id>
            <name>My Maven Hosted Repository</name>
            <url>http://192.168.3.4:8081/repository/maven2-private-example/</url>
        </repository>
    </distributionManagement>
</project>

Maven does not download packages that have already been acquired from the web, so packages are not stored in the proxy repository

NPM build a repository with Nexus Repository

Hosted repository

Create a new repository as below

Name: npm-hosted

proxy repository

Create a new proxy repository as below

group repository

Create a new group repository as below

  • Name: npm-group
  • Members: npm-proxy-example npm-private-example

How to get the package

Create the following two files in any directory

.npmrc file

email=HuuPV@devopsroles.com
always-auth=true
_auth=YWRtaW46YWRtaW4xMjMxMjM=

registry=http://192.168.3.4:8081/repository/npm-proxy/

package.json file

{
  "name": "npm-hosted",
  "version": "1.0.0",
  "description": "for nexus3",
  "dependencies": {
  }
}

Authentication information generated by the following method

echo -n 'admin:admin123123' | openssl base64

Output

YWRtaW46YWRtaW4xMjMxMjM=

Get the required packages from a repository on the Internet via the Nexus3 proxy repository. By acquiring via the proxy repository, it is automatically saved to Nexus3 as well as downloaded.

npm install --save <package name>
# Example
npm install --save bower

As a result of executing the above command, the package is saved.

Conclusion

You have to Build a repository use Nexus Repository. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install Nexus Repository OSS on CentOS 7

#Introduction

In this tutorial, How to Install Nexus Repository OSS on CentOS 7. There are three types of Nexus3 repositories.

  • A hosted repository that constitutes a repository by itself.
  • Proxy repository that relays access to another repository.
  • Group repository that aggregates hosted and proxy.

Prerequisites

yum install -y epel-release unzip vim wget net-tools
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

Disable SELinux on Centos as follows

[root@DevopsRoles ~]# cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

Install Nexus Repository OSS on Centos 7

# Creating necessory folder structure
mkdir -p /Data/nexus-data /opt/nexus

# Download latest Nexus artifact
wget -O /tmp/nexus.tar.gz http://download.sonatype.com/nexus/3/latest-unix.tar.gz

# Extract it to /opt/nexus
tar xvfz /tmp/nexus.tar.gz -C /opt/nexus --strip-components 1

# Adding a service account for nexus
useradd --system --no-create-home nexus

# Provide necessory folder permissions
chown -R nexus:nexus /opt/nexus
chown -R nexus:nexus /Data/nexus-data

Configure environment for Nexus repository OSS on CentOS 7

# Setting up the default JDK
alternatives --config java 

# Setting up JAVA_HOME and NEXUS_HOME
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64
export NEXUS_HOME=/opt/nexus
source /etc/bashrc

# Check the JAVA version
java -version

Change Nexus default values as follows

[root@DevopsRoles ~]# cat $NEXUS_HOME/bin/nexus.vmoptions
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=4G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=/Data/nexus-data/nexus3/log/jvm.log
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=/Data/nexus-data/nexus3
-Djava.io.tmpdir=/Data/nexus-data/nexus3/tmp
-Dkaraf.startLocalConsole=false

#
# additional vmoptions needed for Java9+
#
# --add-reads=java.xml=java.logging
# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED
# --patch-module=java.base=lib/endorsed/org.apache.karaf.specs.locator-4.2.9.jar
# --patch-module=java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-4.2.9.jar
# --add-opens=java.base/java.security=ALL-UNNAMED
# --add-opens=java.base/java.net=ALL-UNNAMED
# --add-opens=java.base/java.lang=ALL-UNNAMED
# --add-opens=java.base/java.util=ALL-UNNAMED
# --add-opens=java.naming/javax.naming.spi=ALL-UNNAMED
# --add-opens=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED
# --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED
# --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED
#
# comment out this vmoption when using Java9+
#
-Djava.endorsed.dirs=lib/endorsed

Configure application-host as follows

[root@DevopsRoles ~]# cat $NEXUS_HOME/etc/nexus-default.properties
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=192.168.3.4
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

nexus.hazelcast.discovery.isEnabled=true

Configure the nexus service account

[root@DevopsRoles ~]# cat $NEXUS_HOME/bin/nexus.rc
#run_as_user=""
run_as_user="nexus"

Create SystemD service as follows

[root@DevopsRoles ~]# cat /etc/systemd/system/nexus.service
[Unit]
Description=Nexus Server
After=syslog.target network.target

[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Group=nexus
Restart=on-failure

[Install]
WantedBy=multi-user.target

Increasing the open file limit of nexus user

[root@DevopsRoles ~]# grep nexus /etc/security/limits.conf
nexus    -    nofile    65536

Start and Enable Nexus service

systemctl daemon-reload
systemctl start nexus.service
systemctl enable nexus.service

Check nexus service is running

netstat -npltu | grep 8081

Nexus log files for issues

tail -f /Data/nexus-data/nexus3/log/nexus.log

Nexus Initial Login Information

  • URL: http://192.168.3.4:8081
  • User: admin
  • Password: admin123

Conclusion

You have to Install Nexus Repository OSS and configure Nexus Repository OSS on CentOS 7. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Change WordPress URLs in MySQL Database

Introduction

In this tutorial, How to Change WordPress URLs in MySQL Database using the command line. WordPress uses the MySQL database to store all its data, including site URLs.

Determining the Name of WordPress MySQL Database

WordPress stores the MySQL database name and its credentials in the wp-config.php file. Example below

[devopsroles@server1 ~]$ egrep -A 10 DB_NAME /Wordpress/web/wp-config.php 
define('DB_NAME', 'wordpressdb');

/** MySQL database username */
define('DB_USER', 'HuuPV');

/** MySQL database password */
define('DB_PASSWORD', 'devopsroles.com');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Change WordPress URLs

I will change from the Old site: https://linuxoperatingsystem.net to the New site: http://192.168.122.229

Determining the site URL currently with the command below

mysql> SELECT * FROM wp_options WHERE option_name='siteurl';
+-----------+-------------+----------------------------------+----------+
| option_id | option_name | option_value                     | autoload |
+-----------+-------------+----------------------------------+----------+
|         1 | siteurl     | https://linuxoperatingsystem.net | yes      |
+-----------+-------------+----------------------------------+----------+
1 row in set (0.00 sec)

mysql> 

Command-line change WordPress URLs in MySQL Database

mysql -u root -p Database_Name
mysql> UPDATE wp_options SET option_value = replace(option_value, 'https://linuxoperatingsystem.net', 'http://192.168.122.229') WHERE option_name = 'home' OR option_name = 'siteurl';
mysql> UPDATE wp_posts SET guid = replace(guid, 'https://linuxoperatingsystem.net','http://192.168.122.229');
mysql> UPDATE wp_posts SET post_content = replace(post_content, 'https://linuxoperatingsystem.net', 'http://192.168.122.229');
mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://linuxoperatingsystem.net','http://192.168.122.229');

The output is as below:

mysql> show databases;
+-------------------------+
| Database                |
+-------------------------+
| information_schema      |
| mysql                   |
| performance_schema      |
| sys                     |
| wordpressdb             |
+-------------------------+
6 rows in set (0.00 sec)

mysql> use wordpressdb;
Database changed
mysql> 


mysql> UPDATE wp_options SET option_value = replace(option_value, 'https://linuxoperatingsystem.net', 'http://192.168.122.229') WHERE option_name = 'home' OR option_name = 'siteurl';
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> UPDATE wp_posts SET guid = replace(guid, 'https://linuxoperatingsystem.net','http://192.168.122.229');
Query OK, 43 rows affected (0.03 sec)
Rows matched: 43  Changed: 43  Warnings: 0

mysql> UPDATE wp_posts SET post_content = replace(post_content, 'https://linuxoperatingsystem.net', 'http://192.168.122.229');
Query OK, 29 rows affected (0.01 sec)
Rows matched: 43  Changed: 29  Warnings: 0

mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://linuxoperatingsystem.net','http://192.168.122.229');
Query OK, 0 rows affected (0.00 sec)
Rows matched: 73  Changed: 0  Warnings: 0

Conclusion

If you’re managing a WordPress site, you may find yourself needing to change the URLs directly in the MySQL database, especially after a migration or domain change. This process involves accessing your MySQL database through a command line interface and using SQL commands to update the site URL across different tables such as wp_options, wp_posts, and wp_postmeta. It’s a crucial skill for maintaining the integrity of your WordPress site links. Always back up your database before making such changes to avoid any potential data loss. For detailed guidance, consider visiting DevOpsRoles for tutorials.