Рубрики
Linux samba

Samba

Install and configure samba on CentOS7:

Install samba and tools:

yum install -y samba samba-client samba-common

firewalld add service (if using firewalld):
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

backup original samba config:
cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

Add group and Linux user:
groupadd smbgrp
useradd smbuser
passwd smbuser


Add samba user to samba group and change samba user passwd:
usermod smbuser -aG smbgrp
smbpasswd -a


Change samba share permissions:
chmod -R 0770 /samba/share
chown -R root:smbgrp /samba/share


Change SELinux context:

chcon -t samba_share /samba/share

Add samba share to config file:
vi /etc/samba/smb.conf

[data]
comment = File Server Share
path = /data
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes


Execute the test command to check if any errors acquired:
testparm

Enable smb and nmb and start services:
systemctl enable smb.service
systemctl enable nmb.service
systemctl start smb.service
systemctl start nmb.service



Done.
Mount it on remote PC with smbuser credentials.

Рубрики
Ansible Linux

Ansible

Install ansible on CentOS7:

yum install epel-release
yum install -y ansible

Standard directory structure:
[root@lab-1 ansible_playbooks]# tree
.
├── fs_servers.yml
├── inventories
│   ├── production
│   │   ├── group_vars
│   │   └── host_vars
│   └── staging
│   ├── group_vars
│   ├── hosts
│   └── host_vars
├── roles
│   └── fileserver
│   ├── files
│   ├── tasks
│   ├── templates
│   └── vars
└── site.yml

When using git with GitHub create (touch) .gitkeep file in each directory to sync the directory structure.

To provide ssh_key use next parameter in the hosts file:
ansible_ssh_private_key_file=/root/.ssh/id_rsa

List all information about ansible inventory:
[root@lab-1 ansible_playbooks]# ansible-inventory --list -i ./inventories/staging/hosts

Tree-like inventory info:
ansible-inventory --graph -i ./inventories/staging/hosts

Check information of the server:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m setup

Execute shell command on remote servers:
ansible -i ./inventories/staging/hosts staging_lab_servers -m shell -a "uptime"

Copy file from source VM to all servers:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m copy -a "src=/home/file.txt dest=/home mode=777" -b

Delete file from all servers:
[root@lab-1 ansible_playbooks]#ansible -i ./inventories/staging/hosts staging_lab_servers -m file -a "path=/home/file.txt state=absent"

Download file from URL to all servers:
[root@lab-1 ansible_playbooks]#ansible -i ./inventories/staging/hosts staging_lab_servers -m get_url -a "url=https://ya.ru dest=/home" -b

Make Get request to URL:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m uri -a "url=https://ya.ru"

Make Get request with content to URL:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m uri -a "url=https://ya.ru return_content=true"

Install yum package on all servers:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m yum -a "name=tree state=latest" -b

Remove yum package from all servers:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m yum -a "name=tree state=removed" -b

Enable service and start it:
[root@lab-1 ansible_playbooks]# ansible -i ./inventories/staging/hosts staging_lab_servers -m service -a "name=httpd state=started enabled=yes" -b

Initialize role in the current folder (will create a subfolder with provided role name):
ansible-galaxy init ROLE_NAME

********************************************************************
********************************************************************
********************************************************************

Ansible vault encrypt a file:
ansible-vault encrypt FILE

Ansible decrypt the encrypted file:
ansible-vault decrypt FILE

Cat encrypted file:
ansible-vault view FILE

Edit encrypted file:
ansible-vault edit FILE

Run encrypted playbook:
ansible-playbook FILE.yml --ask-vault-pass

Run encrypted playbook with predefined passwd:
ansible-playbook FILE.yml --vault-password-file passwd_file.txt

Ansible encrypt variable:
ansible-vault encrypt_string
enter var: VAR_PASSWORD

copy the encrypted string to the playbook.
or
echo -n "VAR_PASSWORD" | ansible-vault encrypt_string

Prepare Windows Server for Ansible automation:
Set-Service -Name "WinRM" -StartupType Automatic
Start-Service -Name "WinRM"
winrm quickconfig
Enable-PSRemoting -SkipNetworkProfileCheck -Force

Рубрики
File system Linux

File systems

Check what is the logging type is used in the filesystem:

dmesg | grep EXT

If you need to change logging type remount partition with data=xxx specified (mount command or /etc/fstab) where xxx can be:
data=ordered
data=writeback
data=journal


data=ordered — first metadata is saved only then real data will be written to disk and confirmed as saved. (reliable but slower writeback)

data=writeback — async logging, saving data can be confirmed before real data is saved, software should end operations based on POSIX spec with fsync command.

data=journal — saving both metadata and data itself (slow)

Change file system fsck check period:

tune2fs -l /dev/sdb1 show current information
tune2fs -c 150 -i 80 /dev/sdb1 change it to 150 mount/remount operations («-c») or 80 days («-i»).

Manually recheck file system:
umount /dev/sdb1
fsck.ext4 -f /dev/sdb1
mount /dev/sdb1

Generate UUID for the file system:

tune2fs -U random /dev/sdb1 Generate random UUID

tune2fs -U 5cf24d64-b279-4565-9bfd-e6ec3436845b /dev/sdb1 Set exact UUID for FS

Check the current UUID:
blkid

Extend LVM volume and FS on it (to 30G):
lvextend -L 30G /dev/mapper/vg1-test
resize2fs /dev/mapper/vg1-test

1 st step expand the disk.
in VMware or another hypervisor.

2nd step:
Re-scan expanded disk on a fly (for example expanded vmware para-virtual drive):
echo "1" > /sys/class/block/sdX/device/rescan

3rd step:
resize the partition using fdisk

fdisk /dev/sdX

Delete partition:
Command (m for help): d
Selected partition 1
Partition 1 is deleted

Create a new primary partition:
Command (m for help): n
Select (default p):
Using default response p

Write changes to disk:
Command (m for help): w
The partition table has been altered!

Rescan partitions:
#partprobe

4th step:
check type of filesystem with blkid
if filesystem id «xfs»
to expand partition use:
#xfs_growfs -d /dev/sdX1

check new «xfs» file system info:
xfs_info /dev/sdX1

If the partition is GPT:
use
#partprobe
if you see an error similar to this:
Error: The backup GPT table is not at the end of the disk, as it should be.
Fix partition at first:
parted -l
fix
fix

Now you can use fdisk to recreate the partition:
#fdisk /dev/sdX
d
n
w


Resize file system (ext4)
resize2fs /dev/sdX1

Done

Рубрики
terraform

Terraform

Dry run inside project folder:
terraform plan

Рубрики
Linux

tar

Show contents of the package:
root# tar -tzf archiv.tar.gz

Extract files here:
root# tar -xzf archiv.tar.gz

Extract only some file by mask:
root# tar -xzf archiv.tar.gz "*.log"

Extract to a directory:
root# tar -xzf archiv.tar.gz -C dir



Show contents of the bzip2 package:
tar -tjf archiv.tar.bz2

Extract files here:
root# tar -xjf archiv.tar.gz

Рубрики
apt-get Linux

apt-get

To make 1 machine cache apt packages for hole net install apt-cacher (or apt-cacher-ng, squid-deb-proxy, apt-proxy, approx)

You do NOT need httpd (apache) for standard configuration (port 3142).
Logs file location: /var/log/apt-cacher

root# apt-get install apt-cacher

# File /etc/default/apt-cacher
vi /etc/default/apt-cacher
AUTOSTART=1


# File /etc/apt-cacher/apt-cacher.conf
vi  /etc/apt-cacher/apt-cacher.conf
...
daemon_addr=192.168.0.1
allowed_hosts=192.168.0.0/24
...


root# service apt-cacher start

#Import already downloaded apt packages to apt-chacher
root# cd /usr/share/apt-cacher
root# ./apt-cacher-import.pl /var/cache/apt/archives

Client-side configuration.
Check if
http://apt-cacher:3142
http://apt-cacher:3142/report
are reachable. (with curl or browser)

And change apt conf file:

# File /apt/apt.conf.d/01proxy
vi /apt/apt.conf.d/01proxy
Acquire::http::Proxy "http://apt-cacher:3142/"
Рубрики
Bash Linux ping

ping

Log ping to host with timestamp.

@echo off

set /p host=HOST ADDRESS: 
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL 
    GOTO Ping)

Ping some host with date every minute:

screen -dmS ping_from_edge1_to_edge2_eth0 bash -c 'while true; do date +"%Y-%m-%d  %T" ; ping -c 60 IP_ADDRESS; done >> /home/user/ping_edge1_to_edge2_eth0.log'