Category: Linux

  • Install PHP 7.2 on CentOS from yum

    First you need to install Remi repository

    https://rpms.remirepo.net

    Enable epel repo with

    yum install epel-release -y
    

    On CentOS 7

    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

    On CentOS 6

    rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-6.rpm
    

    Enable PHP 7.2

    yum install yum-utils
    yum-config-manager --enable remi-php72
    

    To install PHP, run

    yum install -y php php-bcmath php-cli php-common php-devel php-gd \
        php-imap php-intl php-json php-ldap php-lz4 php-mbstring php-mysqlnd \
        php-soap php-intl php-opcache php-xml php-pdo
    

    Downgrading PHP version

    if you ever want to change PHP version, lets say PHP 7.0, do the following. Remove current PHP

    rpm -qa | grep php | xargs yum remove -y
    

    Disable PHP 7.2 repo.

    yum-config-manager --disable remi-php72
    

    Enable PHP 7.0 repo

    yum-config-manager --enable remi-php70
    

    Now install PHP as above.

    PHp Binary

    PHP cli will be installed in /usr/bin/php72, you can create a symlink if you want.

    PHP-FPM

    To install php-fpm module, run

    yum install php72-php-fpm -y
    

    To start php-fpm, run

    systemctl start php72-php-fpm
    

    See CentOS, php

  • haproxy

    To install haproxy on Ubuntu, run

    apt install haproxy

    Haproxy config file is located at

    /etc/haproxy/haproxy.cfg

    Enable HTTP_X_FORWARDED_FOR in Haproxy
    Show X-Forwarded-For IP in Apache
    Haproxy Site With SSL
    Enable SSL in Haproxy Docker Container

  • Install Google Chrome on CentOS 7 64 bit

    To install Google Chrome on CentOS 7 (Chrome won’t work on CentOS 6 as it is using older version of libraries required for Chrome).

    First create repo file

    vi /etc/yum.repos.d/google-chrome.repo
    

    Add following content

    [google-chrome]
    name=google-chrome
    baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
    enabled=1
    gpgcheck=1
    gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
    

    Now you can install google chrome with command

    yum -y install google-chrome-stable
    

    See CentOS

  • screen

    screen allows you to run commands in the remote server even after you disconnect.

    disconnect from a session

    Press

    CTRL + A, then press CTRIL +D in quick succession.

    You can also close the terminal, the screen session will continue in the background.

    screen -lsList all available screen sessions
    screen -rReconnect to a disconnected screen session
  • OVH VPS Configure failover IP in Ubuntu

    On Ubuntu

    Default config look like

    root@zecurecode:~# cat /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # Source interfaces
    # Please check /etc/network/interfaces.d before changing this file
    # as interfaces may have been defined in /etc/network/interfaces.d
    # See LP: #1262951
    source /etc/network/interfaces.d/*.cfg
    
    root@zecurecode:~#
    

    /etc/network/interfaces.d/50-cloud-init.cfg is used to auto configure network interface with dhcp.

    root@zecurecode:~# cat /etc/network/interfaces.d/50-cloud-init.cfg 
    # This file is generated from information provided by
    # the datasource.  Changes to it will not persist across an instance.
    # To disable cloud-init's network configuration capabilities, write a file
    # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
    # network: {config: disabled}
    auto lo
    iface lo inet loopback
    
    auto ens3
    iface ens3 inet dhcp
    root@zecurecode:~# 
    

    First find the gateway used by the VPS.

    root@zecurecode:~# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         51.254.32.1     0.0.0.0         UG    0      0        0 ens3
    51.254.32.1     0.0.0.0         255.255.255.255 UH    0      0        0 ens3
    root@zecurecode:~# 
    

    We found the gateway IP 51.254.32.1

    The VPS had main IP of the server is 51.254.35.58 and secondary IPS 94.23.153.137, 178.32.52.159, 178.32.49.157

    Here is the modified /etc/network/interfaces

    root@zecurecode:~# cat /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # Source interfaces
    # Please check /etc/network/interfaces.d before changing this file
    # as interfaces may have been defined in /etc/network/interfaces.d
    # See LP: #1262951
    #source /etc/network/interfaces.d/*.cfg
    
    auto ens3
    iface ens3 inet static
        address 51.254.35.58
        netmask 255.255.255.255
        broadcast 51.254.35.58
        post-up route add 51.254.32.1 dev ens3
        post-up route add default gw 51.254.32.1
        post-down route del default gw 51.254.32.1
        post-down route del 51.254.32.1 dev ens3
    
    auto ens3:1
    iface ens3:1 inet static
        address 94.23.153.137
        netmask 255.255.255.255
        broadcast 94.23.153.137
    
    auto ens3:2
    iface ens3:2 inet static
        address 178.32.52.159
        netmask 255.255.255.255
        broadcast 178.32.52.159
    
    auto ens3:3
    iface ens3:3 inet static
        address 178.32.49.157
        netmask 255.255.255.255
        broadcast 178.32.49.157
    
    
    root@zecurecode:~# 
    

    Here is a PHP script to create OVH failover IP config for Ubuntu/Debian.

    https://gist.github.com/serverok/991f7ccd1be36cbc579e8d55caf39715

  • ssh-keygen

    To generate SSH key, run

    ssh-keygen -t ed25519

    If you need RSA key, run

    ssh-keygen -b 4096

    To create an SSH key in the current folder, run

    ssh-keygen -b 4096 -N "" -f NAME_OF_KEY

    This will create 2 files in the current directory. The “-N” option is for keyphrase. With -N “”, it won’t ask you for kayphrase.

    ssh-keygen

    See Change SSH Key Passphrase

  • Change SSH Key Passphrase

    To change SSH key passphrase, run

    ssh-keygen -p -f ~/.ssh/id_rsa
    

    Example

    root@ok:~/.ssh# ssh-keygen -p -f ~/.ssh/id_rsa
    Enter new passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved with the new passphrase.
    root@ok:~/.ssh# 
    

    See ssh-keygen

  • lsblk

    lsblk list all block level devices available on your system.

    Example

    root@ok:~# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0  100G  0 disk 
    ├─sda1   8:1    0   98G  0 part /
    ├─sda2   8:2    0    1K  0 part 
    └─sda5   8:5    0    2G  0 part [SWAP]
    sdb      8:16   0  700G  0 disk 
    └─sdb1   8:17   0  700G  0 part /backup
    sr0     11:0    1  655M  0 rom  
    loop0    7:0    0 36.4M  1 loop /snap/heroku/1513
    loop1    7:1    0 83.8M  1 loop /snap/core/3748
    loop2    7:2    0   16M  1 loop /snap/heroku/1527
    root@ok:~# 
    

    See fs

  • Add Server to R1Soft Server Backup Manager

    After installing r1soft backup agent, you need to add the server to R1Soft Server Backup Manager SE.

    Click on “Protected Machines” link on left side menu.

    Click on “New Machine” button.

    r1soft backup

    On this page, enter following details “Machine Name” and “Hostname / IP”. I used host name as Machine Name. Then used IP address. I don’t enable Encryption, you can enable it for added security.

    Click Save button.

    Now login to server where Backup Agent is installed (Protected Machine) and run

    serverbackup-setup --get-key http://url-of-backup-manager-server
    

    Example

    [root@server1 ~]# serverbackup-setup --get-key https://22536.r1softlicenses.com
    Key '22536.r1softlicenses.com' successfully installed
    [root@server1 ~]#
    

    Now verify key is added with command

    [root@server1 ~]# serverbackup-setup --list-keys
    Installed keys:
        22536.r1softlicenses.com
    1 keys installed
    
    [root@server1 ~]#
    

    Next, you need to Configure Server Backup in R1Soft Backup Manager

  • Install R1Soft Agent

    To install R1Soft Agent on CentOS, create a file

    vi /etc/yum.repos.d/r1soft.repo
    

    Add

    [r1soft]
    name=R1Soft Repository Server
    baseurl=http://repo.r1soft.com/yum/stable/$basearch/
    enabled=1
    gpgcheck=0
    

    Now you can install Agent with command

    yum install serverbackup-enterprise-agent -y
    

    You can stop/start agent with command

    service cdp-agent stop
    service cdp-agent start
    service cdp-agent status
    

    Once installed, verify connectivity with command

    serverbackup-setup --test-connection
    

    See r1soft