Ansible roles directory structure explained

Introduction

I will explain the ansible roles directory structure. The confusing using roles are understanding the file hierarch. Ansible provides a feature called Ansible galaxy that helps you play roles.

For example, Ansible roles directory will look like as below:

[vagrant@ansible_controller demo]$ tree nodejs
nodejs
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

8 directories, 8 files

You can be using ansible galaxy it creates a role.

$ sudo ansible-galaxy init <role-name>
# Example init nodejs role
$ sudo ansible-galaxy init nodejs

Explain Ansible directories

  • Tasks: The main list of tasks to be exectued by role. it contains the main.yml file.
  • Files: Contains files that can be deployed by this role
  • Handlers: Contains handlers which may be used by this role or even anywhere outside this role.
  • Defaults: Contains the default variables used by this role.
  • Vars: This directory consists of other variables that used by the roles. These variables can be defined in ansible playbook.
  • Meta: Defines metadata for this role. it contains file role dependencies.

Demo Using Ansible install nodejs

I use ansible-galaxy to download template nodejs role as command below:

[vagrant@ansible_controller demo]$ ansible-galaxy init nodejs

My Ansible structure folder and file as below:

[vagrant@ansible_controller ~]$ tree demo
demo
├── ansible.cfg
├── install-nodejs.yml
├── inventory
│   └── hosts
└── roles
    └── nodejs
        ├── defaults
        │   └── main.yml
        ├── files
        ├── handlers
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── README.md
        ├── tasks
        │   └── main.yml
        ├── templates
        └── vars
            └── main.yml

10 directories, 9 files

Write roles/nodejs/tasks/main.yml for nodejs role as below:

---
# Example, tasks file for nodejs
- name: Node.js - Get script
  get_url:
    url: "https://rpm.nodesource.com/setup_10.x"
    dest: "{{ var_node }}/nodejs.sh"

- name: Node.js - Set execution permission to script
  file:
    path: "{{ var_node }}/nodejs.sh"
    mode: "u+x"

- name: Node.js - Execute installation script
  shell: "{{ var_node }}/nodejs.sh"

- name: Node.js - Remove installation script
  file:
    path: "{{ var_node}}/nodejs.sh"
    state: absent

- name: Node.js - Install Node.js
  yum: name={{ item }} state=present update_cache=yes
  with_items:
    - epel-release
    - nodejs

- name: Node.js - Install bower and gulp globally
  npm: name={{ item }} state=present global=yes
  with_items:
    - bower
    - gulp

# check version
- name: "Check if nodejs is installed"
  package_facts:
    manager: "auto"
- name: "nodejs result"
  debug:
     msg: "nodejs found"
  when: "'nodejs' in ansible_facts.packages"
- name: "nodejs result"
  debug:
     msg: "nodejs NOT found"
  when: "'nodejs' not in ansible_facts.packages"

Write your main playbook. Example, install-nodejs.yml file.

---
- hosts: web-server
  become: yes
  vars:
    # variable needed during node installation
    var_node: /tmp
  roles:
       - nodejs

Ansible run command

[vagrant@ansible_controller demo]$ ansible-playbook -i inventory/hosts install-nodejs.yml

The result, install nodejs on the target server as below:

Conclusion

I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible copy template file to remote server

#Introduction

How to copy the template file to the remote server using Ansible. I use vagrant to create VMs. My example Ansible creates multiple servers here. In Ansible I use with_fileblob:

Ansible file and folder

[vagrant@ansible_controller ansible]$ tree .
.
├── ansible.cfg
├── copy-template.yml
├── hosts
└── roles
    └── copyfiles
        ├── tasks
        │   └── main.yml
        └── templates
            ├── devopsroles.conf.tmp
            ├── file1.conf.tmp
            └── file2.conf.tmp

4 directories, 7 files

Ansible copy template file to remote server script

copy-template.yml file.

---
- hosts: web-server
  become: yes
  roles:
       - copyfiles

Example: roles/copyfiles/tasks/main.yml file

---
- name: "Copy files template to remote server"
  template:
    src: "{{ item }}"
    dest: "/home/vagrant/dest/{{ item | basename | regex_replace('.tmp','') }}"
    owner: "root"
    group: "root"
    mode: 0644
  with_fileglob:
    - templates/*.tmp

Ansible run command 

[vagrant@ansible_controller ansible]$ ansible-playbook -i hosts copy-template.yml

The output terminal on the ansible controller

[vagrant@ansible_controller ansible]$ ansible-playbook -i hosts copy-template.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [web-server] ***************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [server1]

TASK [copyfiles : Copy files template to remote server] *************************************************************
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/devopsroles.conf.tmp)
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/file1.conf.tmp)
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/file2.conf.tmp)

PLAY RECAP **********************************************************************************************************
server1                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The result on remote server1.

[vagrant@server1 dest]$ pwd
/home/vagrant/dest
[vagrant@server1 dest]$ ll
total 12
-rw-r--r--. 1 root root 3 Jan 17 08:53 devopsroles.conf
-rw-r--r--. 1 root root 2 Jan 17 08:53 file1.conf
-rw-r--r--. 1 root root 2 Jan 17 08:53 file2.conf

Conclusion

You have to use Ansible copy template file to remote server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible check package installed in Linux

# Introduction

How to check for a package in the system using Ansible. I use vagrant to create VMs. My example Ansible creates multiple servers here. I will check the Apache package installed in Centos. Now, let’s go Ansible check package installed in Linux.

Ansible check package installed

Ansible file and folder

[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   └── hosts
└── check-package.yml

We use the ansible module package_facts

Ansible script

---
- hosts: apache-server
  become: yes
  tasks:
    - name: "Check if APACHE is installed"
      package_facts:
        manager: "auto"
    - name: "Apache result"
      debug:
         msg: "Apache found"
      when: "'httpd' in ansible_facts.packages"
    - name: "Apache result"
      debug:
         msg: "Apache NOT found"
      when: "'httpd' not in ansible_facts.packages"

Ansible run command to check

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml

The output terminal

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [apache-server] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Check if APACHE is installed] *********************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
ok: [server1] => {
    "msg": "Apache found"
}

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
skipping: [server1]

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
server1                  : ok=3    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

I will remove the apache package on server1 apache.

[vagrant@server1 ~]$ sudo yum remove httpd -y

Ansible runs the command to check again:

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml

The output terminal

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [apache-server] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Check if APACHE is installed] *********************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
skipping: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
ok: [server1] => {
    "msg": "Apache NOT found"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
server1                  : ok=3    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

Conclusion

You have to use the Ansible check package installed in Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Securing Sensitive Data with Ansible vault encrypt decrypt Guide

Introduction

In this tutorial, How to use Ansible vault encrypt decrypt to secure sensitive data. you’ll learn how to use Ansible Vault to secure sensitive data within your configurations, an essential skill for maintaining robust security protocols. Ansible Vault encrypts variables and files to protect sensitive information like passwords and credentials from unauthorized access.

The guide covers the initial setup of Ansible Vault, including detailed steps to encrypt your data effectively. You’ll gain insights into the practical applications of these security measures in real-world scenarios.

Finally, the tutorial provides practical tips for decrypting data when necessary for your deployments. Whether you are new to Ansible or have advanced experience, understanding how to manage Vault’s encryption and decryption processes is crucial for enhancing your operational security.

Ansible vault encrypt decrypt

Encrypted files use Ansible Vault

Ansible uses the AES256 algorithm for encrypting sensitivity. We will create an encrypted file using the ansible-vault utility tool as shown.

ansible-vault create pass-file.xml

The content before the Encrypted file is shown.

cat pass-file.xml
welcome to DevopsRoles.com site!

After the Encrypted file as shown.

cat pass-file.xml
$ANSIBLE_VAULT;1.1;AES256
37383139356630386365643264393833663535643534663962643664366634626334383735343861
6265633335646266363233333930303436633063373931380a613635373435366561353534663432
66366631336335393562333233363762633130393336646462633031383239363332616338376633
3630633835646238610a373431323839396636316463633564356535383065626663386135366338
3431

We will view an Encrypted file in Ansible using ansible-vault

ansible-vault view pass-file.xml

Edit an Encrypted file using ansible-vault

ansible-vault edit pass-file.xml

Encrypt an Existing file using the Ansible vault command

ansible-vault encrypt pass-file2.xml

For example the picture below

Decrypting files Ansible

Use an ansible vault to decrypt a file or revert to plain text.

ansible-vault decrypt pass-file2.xml

Reset the Ansible vault password

ansible-vault rekey pass-file2.xml

Encrypt a playbook file in Ansible

Example Ansible Setup NFS server here. I will Encrypt file exports.j2 the content as below:

[vagrant@ansible_controller ~]$ cat ./ansible/exports.j2
# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/home/vagrant/nfs_test            192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Encryption with vault_pass.txt as below:

[vagrant@ansible_controller ~]$ cat vault_pass.txt
123456789@
[vagrant@ansible_controller ~]$ ansible-vault encrypt ./ansible/exports.j2 --vault-password-file vault_pass.txt
Encryption successful
[vagrant@ansible_controller ~]$ cat ./ansible/exports.j2
$ANSIBLE_VAULT;1.1;AES256
38376166636635393464306333653230663865303966626137346536393231623862333532313061
6334326531333734663936336436323034643261666462640a353833363437633761656136306433
30383331633836346563323962346663373664646538636135663866346435643834613937643664
3763383131363761370a363632613539303239366166613339663133653938646665613530633633
64613233636434323031326137376636613536396330623338326230366664376339653431643831
63386431633837643265343662643338626339656630336666613565303738643038373131383530
61383637666462376663306536333736623339346364653462633730383961353531613830343534
66393339363061643861373162663832333561663763313339626365353139376433303333373133
65373461313531323735623135616535363638353963343563643439363461613236646433313461
39653733633638396663636236346638393036323831386535333933373764616334343431316234
31376537653434653931613931646465393638373039363335616364613638633264356531323332
65336164333334303765393361616233373138663530386466383032333334393465363632303435
64383332313635326661333431613561666431356331363963633137623965323963666338393865
3235393266326566663463363861613166643130313430653736

As a result, run the Ansible playbook as below:

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-server.yml --vault-password-file vault_pass.txt
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [nfs-server] ***************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [servernfs]

TASK [install nfs-utils] ********************************************************************************************
ok: [servernfs]

TASK [Create a mountable directory if it does not exist] ************************************************************
ok: [servernfs]

TASK [enable rpcbind nfslock nfs] ***********************************************************************************
ok: [servernfs] => (item=rpcbind)
ok: [servernfs] => (item=nfslock)
ok: [servernfs] => (item=nfs)

TASK [Copy exports file.] *******************************************************************************************
changed: [servernfs]

TASK [NFS system start] *********************************************************************************************
changed: [servernfs]

PLAY RECAP **********************************************************************************************************
servernfs                  : ok=6    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

File /etc/exports on server NFS as below:

[vagrant@servernfs ~]$ cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/home/vagrant/nfs_test            192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Conclusion

In conclusion, using Ansible Vault for encryption and decryption is a key skill for safeguarding your sensitive data in DevOps environments. The examples provided in this guide illustrate practical applications of Ansible Vault, enhancing your security practices. We hope you find this information beneficial. Thank you for reading on the DevopsRoles page!

Ansible Setup NFS server and client

#Introduction

In this tutorial, How to set up an NFS server and client using Ansible. I use Vagrant. In my example, Ansible creates multiple servers here. Now, let’s go to the Ansible Setup NFS server and client.

Ansible file and folder

[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   ├── exports.j2
│   └── hosts
├── nfs-client.yml
└── nfs-server.yml

1 directory, 5 files

Ansible script

nfs-server.yml file for NFS Server as below

---
- hosts: nfs-server
  become: yes
  tasks:
    - name: install nfs-utils
      yum: name=nfs-utils state=latest

    - name: Create a mountable directory if it does not exist
      file:
        path: /home/vagrant/nfs_test
        state: directory
        owner: vagrant
        group: vagrant
        mode: '0775'
    - name: enable rpcbind nfslock nfs
      service:
        name: "{{ item }}"
        enabled: yes
      with_items:
        - rpcbind
        - nfslock
        - nfs
    - name: Copy exports file.
      template:
        src: ./ansible/exports.j2
        dest: /etc/exports
        owner: root
        group: root
        mode: 0644
    - name: NFS apply change configrue
      shell: systemctl reload nfs;exportfs -a

nfs-client.yml file for nfs clients as below

---
- hosts: nfs-clients
  become: yes
  tasks:
    - name: install nfs-utils
      yum: name=nfs-utils state=latest

    - name: Create a mountable directory if it does not exist
      file:
        path: /mnt/web_storage
        state: directory
        owner: vagrant
        group: vagrant
        mode: '0775'
    - name: Mount volumn
      shell: sudo mount 192.168.3.9:/home/vagrant/nfs_test /mnt/web_storage

exports.j2 file with content as below

# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/mnt/nfs_test            *(rw,sync,no_root_squash,no_subtree_check)

My example hosts file as below

[nfs-server]
servernfs

[nfs-clients]
server1

File ansible/ansible.cfg example as below

[defaults]
inventory = ./hosts
forks = 15
log_path=$HOME/ansible/ansible.log
host_key_chcking = False
gathering = smart

Ansible run command for NFS server

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-server.yml

The output terminal as picture below

Ansible run command for NFS client

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-client.yml

The output terminal as picture below

Conclusion

You have to use ansible setup NFS server and NFS client. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Vagrant No VirtualBox Guest Additions installation found [Fixed]

Introduction

In this tutorial, How to fix the error Vagrant No VirtualBox Guest Additions installation is found. I use a laptop and run the command vagrant up for the NFS server then the error “umount: /mnt: not mounted

ERROR umount: /mnt: not mounted

E:\Vagrant_VMS\NFS_server>vagrant up 

Error: Nothing to do
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted
==> servernfs: Checking for guest additions in VM...
    servernfs: No guest additions were detected on the base box for this VM! Guest
    servernfs: additions are required for forwarded ports, shared folders, host only
    servernfs: networking, and more. If SSH fails on this machine, please install
    servernfs: the guest additions and repackage the box to continue.
    servernfs:
    servernfs: This is not an error message; everything may continue to work properly,
    servernfs: in which case you may ignore this message.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:



Stderr from the command:

umount: /mnt: not mounted

Vagrant No VirtualBox Guest Additions installation found fixed

I have uninstalled vagrant-vbguest and installed vagrant-vbguest.

vagrant plugin uninstall vagrant-vbguest
vagrant plugin install vagrant-vbguest --plugin-version 0.21

The output uninstall and install vagrant-vbguest as below

E:\Vagrant_VMS\NFS_server>vagrant plugin uninstall vagrant-vbguest
Uninstalling the 'vagrant-vbguest' plugin...
Successfully uninstalled micromachine-3.0.0
Successfully uninstalled vagrant-vbguest-0.27.0

E:\Vagrant_VMS\NFS_server>vagrant plugin install vagrant-vbguest --plugin-version 0.21
Installing the 'vagrant-vbguest --version '0.21'' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.21.0.gem
Installed the plugin 'vagrant-vbguest (0.21.0)'!

As a result, I have to fix it!

E:\Vagrant_VMS\NFS_server>vagrant reload
==> servernfs: Attempting graceful shutdown of VM...
==> servernfs: Checking if box 'centos/7' version '2004.01' is up to date...
==> servernfs: Clearing any previously set forwarded ports...
==> servernfs: Clearing any previously set network interfaces...
==> servernfs: Preparing network interfaces based on configuration...
    servernfs: Adapter 1: nat
    servernfs: Adapter 2: hostonly
==> servernfs: Forwarding ports...
    servernfs: 22 (guest) => 2222 (host) (adapter 1)
==> servernfs: Booting VM...
==> servernfs: Waiting for machine to boot. This may take a few minutes...
    servernfs: SSH address: 127.0.0.1:2222
    servernfs: SSH username: vagrant
    servernfs: SSH auth method: private key
    servernfs: Warning: Connection aborted. Retrying...
==> servernfs: Machine booted and ready!
[servernfs] GuestAdditions 6.1.14 running --- OK.
==> servernfs: Checking for guest additions in VM...
==> servernfs: Configuring and enabling network interfaces...
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/ => /vagrant
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/NFS_Volumn/ => /home/vagrant/nfs_test
==> servernfs: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> servernfs: flag to force provisioning. Provisioners marked to run always will still run.

Youtube Vagrant No VirtualBox Guest Additions installation found [Fixed]

Conclusion

You have fixed Vagrant No VirtualBox. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible get IP address remote server

#Introduction

In this tutorial, How to use Ansible get IP address remote server. There are many methods to obtain the IP address the current of remote hosts. so let us learn how to use Ansible to get an IP address to remote hosts’ servers.

Structure file and folder Ansible get IP address remote server

[vagrant@ansible_controller ~]$ pwd
/home/vagrant
[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   └── hosts
└── getIP.yml

1 directory, 3 files

Option 1: use hostvars

To retrieve the IP address of a remote server using Ansible, you can use the ansible_default_ipv4 variable. This variable provides information about the default IPv4 address of the target host.

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  tasks:
  - name: Test hosts list
    debug:
      msg: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"

The output on terminal

[vagrant@ansible_controller ~]$ ansible-playbook getIP.yml -i .ansible/hosts

PLAY [servers] *********************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [server1]

TASK [Test hosts list] *************************************************************************************************
ok: [server1] => {
    "msg": "10.0.2.15"
}

PLAY RECAP *************************************************************************************************************
server1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Here’s an example of how you can access the IP address:

Option 2: Other

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  gather_facts: yes
  tasks:
  - name: Get IP address remote server
    debug:
      msg: "{{ hostvars[inventory_hostname]['ansible_env'].SSH_CONNECTION.split(' ')[2] }}"

The output on terminal

[vagrant@ansible_controller ~]$ ansible-playbook getIP.yml -i .ansible/hosts

PLAY [servers] *************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [server1]

TASK [Get IP address remote server] ************************************************************************************
ok: [server1] => {
    "msg": "192.168.3.11"
}

PLAY RECAP *************************************************************************************************************
server1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Option 3: lookup and dig

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  tasks:
  - name: Test hosts list
    debug:
      msg: "{{ lookup('dig', ansible_host) }}"

Make sure you have proper SSH access to the remote server and the necessary permissions to gather facts from it.

Conclusion

You have to use Ansible get IP address remote server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Command creating a virtual machine in vagrant

#Introduction

In this tutorial, I have written The commands when creating a virtual machine in VirtualBox using Vagrant.

Prerequisites

  • VirtualBox Installed
  • Vagrant Installed

The first, command at the time of creating

The box is searched from Vagrant Cloud.

Create a directory for the virtual machine you want to create and change to it.

mkdir vagrant_test
cd vagrant_test

Initialize the directory and create a Vagrantfile.

vagrant init ubuntu/trusty64

The contents should be as follows. If the box name is different, rewrite it.

cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
end

Start the virtual machine. A box has been added at this time.

vagrant up

ssh connection

vagrant ssh

Other used commands Vagrant

Add box

vagrant box add your-box-name

Added box list

vagrant box list

Delete box

vagrant box remove your-box-name

Virtual machine shutdown

vagrant halt

Delete virtual machine

vagrant destroy

Check virtual machine status

vagrant status

Conclusion

You have to use Command creating a virtual machine in vagrant. 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 change MySQL Data Directory on Ubuntu: A Step-by-Step Guide

Introduction

In this tutorial, How To Move a MySQL Data Directory to a New Location on Ubuntu. I will change MySQL Data Directory on Ubuntu. Managing databases efficiently is crucial for any application, and sometimes this involves changing the data directory for MySQL. Whether you need to move your MySQL data to a different partition for better performance or to manage storage, this task can seem daunting.

This guide will walk you through the process of changing the MySQL data directory on an Ubuntu system, ensuring your database remains secure and operational. Let’s dive in and make this transition smooth and straightforward.

Change MySQL Data Directory on Ubuntu

Identify Current MySQL Data Directory

mysql -u username -p -e “SELECT @@datadir”

For example, the current data directory is ‘/var/lib/mysql

Stop MySQL service

service mysql stop

Backup existing MySQL data directory or copy recursively the contents of ‘/var/lib/mysql’ to ‘/data/mysql-data’

tar -cvf mysql.tar /var/lib/mysql
#or
cp -rap /var/lib/mysql/* /data/mysql-data

Create a new data directory with proper permissions

mkdir -p /data/mysql
chown mysql:mysql /data/mysql

Using the Rsync command Migrate existing data into the new location

nohup rsync -avp /var/lib/mysql/ /data/mysql

Configure the new MySQL Data Directory

Edit the MySQL default configuration file /etc/my.cnf

datadir = /data/mysql

Change the AppArmor data directory in file /etc/apparmor.d/usr.sbin.mysqld

# Replace the lines beginning with /var/lib/mysql into /data/mysql
:%s/\/var\/lib\/mysql/\/data\/mysql/g

Start MySQL service

service mysql start

Verify the location change of the new data directory as the command follows

mysql -u username -p -e “SELECT @@datadir”

Checking issue during MySQL startup check MySQL log file /var/log/mysqld.log for any errors.

Conclusion

You have change MySQL Data Directory on Ubuntu. By following this guide, you have learned how to safely relocate your MySQL data, ensuring your system’s efficiency and reliability. Regular maintenance and updates, along with proper data management, are key to sustaining the performance and security of your MySQL databases. Keep these practices in mind to maintain a robust and scalable database environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version