Category: Linux

  • Nginx vs Apache

    I recently added nginx as front end for apache. Now nginx serve static content, PHP requests are peroxided to Apache.

    Nginx frontend, Apache backend

    [root@server12 ~]# ab -n 1000 -c 100 http://netfree.netfreehost.com/
    This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Copyright 2006 The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking netfree.netfreehost.com (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Completed 500 requests
    Completed 600 requests
    Completed 700 requests
    Completed 800 requests
    Completed 900 requests
    Finished 1000 requests
    
    
    Server Software:        nginx/1.1.0
    Server Hostname:        netfree.netfreehost.com
    Server Port:            80
    
    Document Path:          /
    Document Length:        16844 bytes
    
    Concurrency Level:      100
    Time taken for tests:   5.463353 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      17357000 bytes
    HTML transferred:       16844000 bytes
    Requests per second:    183.04 [#/sec] (mean)
    Time per request:       546.335 [ms] (mean)
    Time per request:       5.463 [ms] (mean, across all concurrent requests)
    Transfer rate:          3102.49 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.8      0       5
    Processing:    44  518  93.9    534     719
    Waiting:       44  517  94.0    533     718
    Total:         47  518  93.2    534     719
    
    Percentage of the requests served within a certain time (ms)
      50%    534
      66%    553
      75%    566
      80%    574
      90%    592
      95%    606
      98%    642
      99%    665
     100%    719 (longest request)
    [root@server12 ~]#
    

    Apache Only

    [root@server12 ~]# ab -n 1000 -c 100 http://netfree.netfreehost.com:81/
    This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Copyright 2006 The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking netfree.netfreehost.com (be patient)
    Completed 100 requests
    Completed 200 requests
    Completed 300 requests
    Completed 400 requests
    Completed 500 requests
    Completed 600 requests
    Completed 700 requests
    Completed 800 requests
    Completed 900 requests
    Finished 1000 requests
    
    
    Server Software:        Apache/2.2.3
    Server Hostname:        netfree.netfreehost.com
    Server Port:            81
    
    Document Path:          /
    Document Length:        16844 bytes
    
    Concurrency Level:      100
    Time taken for tests:   7.102347 seconds
    Complete requests:      1000
    Failed requests:        1
       (Connect: 0, Length: 1, Exceptions: 0)
    Write errors:           0
    Total transferred:      17351384 bytes
    HTML transferred:       16827683 bytes
    Requests per second:    140.80 [#/sec] (mean)
    Time per request:       710.235 [ms] (mean)
    Time per request:       7.102 [ms] (mean, across all concurrent requests)
    Transfer rate:          2385.69 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   1.1      0       6
    Processing:    34  676 174.9    669    1261
    Waiting:       32  675 175.0    668    1260
    Total:         34  676 174.4    669    1261
    
    Percentage of the requests served within a certain time (ms)
      50%    669
      66%    696
      75%    732
      80%    754
      90%    893
      95%    974
      98%   1081
      99%   1128
     100%   1261 (longest request)
    [root@server12 ~]#
    

    See Apache, Nginx

  • Git stdin is not a tty

    When i push to get respo, i get error

    stdin: is not a tty
    

    Other than this error on push and pull, everything worked fine.

    SOLUTION 1

    Add following to top of file /home/git/.bashrc

    if [ $(expr index "$-" i) -eq 0 ]; then
        return
    fi
    

    Modified .bashrc on my server

    root@server70 [~]# cat /home/git/.bashrc
    # .bashrc
    
    if [ $(expr index "$-" i) -eq 0 ]; then
        return
    fi
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
            . /etc/bashrc
    fi
    
    # User specific aliases and functions
    root@server70 [~]#
    

    SOLUTION 2

    The problem is fixed by

    cd /home/git
    mv .bashrc .bashrc_old
    

    This is caused on cpanel servers (i have installed gitosis on a cpanel less server a day before and it worked with out any error, this server have cpanel dns only installed.) as cpanel adds

    mesg y
    

    in file /etc/bashrc

    It also adds

    export EDITOR="pico"
    export VISUAL="pico"
    

    i replace it with following as i prefer vi

    export EDITOR="vi"
    export VISUAL="vi"
    

    See Git

  • Linux Commands

    General

    System

    strace
    lsof
    lspci

    Networking

    nmtui – configure networking

    Disk/Storage

    blkid – show UUID for disks.
    vgcreate

    Load

  • strace: command not found

    # strace -p 17723
    -bash: strace: command not found
    # 
    

    This is because strace not installed on the server. Install it with yum

    # yum install strace
    Loading "installonlyn" plugin
    Setting up Install Process
    Setting up repositories
    Reading repository metadata in from local files
    Parsing package install arguments
    Resolving Dependencies
    --> Populating transaction set with selected packages. Please wait.
    ---> Downloading header for strace to pack into transaction set.
    strace-4.5.16-1.el5.1.i38 100% |=========================|  15 kB    00:00
    ---> Package strace.i386 0:4.5.16-1.el5.1 set to be updated
    --> Running transaction check
    
    Dependencies Resolved
    
    =============================================================================
     Package                 Arch       Version          Repository        Size
    =============================================================================
    Installing:
     strace                  i386       4.5.16-1.el5.1   base              163 k
    
    Transaction Summary
    =============================================================================
    Install      1 Package(s)
    Update       0 Package(s)
    Remove       0 Package(s)
    
    Total download size: 163 k
    Is this ok [y/N]: y
    Downloading Packages:
    (1/1): strace-4.5.16-1.el 100% |=========================| 163 kB    00:00
    Running Transaction Test
    Finished Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing: strace                       ######################### [1/1]
    
    Installed: strace.i386 0:4.5.16-1.el5.1
    Complete!
    #
    
  • strace

    strace command is used to trace system calls. This is useful to see what a process is doing.

    To see what a process doing, run

    strace -p PID_HERE

    To run a command and strace

    strace cat 1.txt

    Debug apache start up

    strace -Ff -o output.txt -e open /etc/init.d/httpd restart
    cat output.txt | grep '= -1'

    log strace out put to a file when running a command

    strace -f -o debug.log npm install
  • MariaDB Repository Setup Script

    This script configure MariaDB repository on your server. You can find more details on offical page

    https://mariadb.com/kb/en/library/mariadb-package-repository-setup-and-usage/

    To setup mariadb repo, run

    curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
    

    I was expecting it ask me what version of MariaDB i like to setup. But it just setup MariaDB 10.4. I wanted to upgrade MariaDB to version 10.2, anyway i did upgrade to 10.4 and everything worked fine.

    If you need a speicfic version, you can run like

    curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.3"
    

    Availabe versions are

    mariadb-5.5
    mariadb-10.0
    mariadb-10.1
    mariadb-10.2
    mariadb-10.3
    mariadb-10.4
    

    When i run the script on Debian 9 server, i get following error

    root@server:~# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
    [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
    [info] Adding trusted package signing keys...
    Executing: /tmp/apt-key-gpghome.TKjSzTY6ww/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x8167EE24 0xE3C94F49 0xcbcb082a1bb943db 0xF1656F24C74CD1D8 0x135659e928c12247
    gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
    gpg: connecting dirmngr at '/run/user/0/gnupg/d.3y8gtbm7kaj8h4royj6yoyug/S.dirmngr' failed: No such file or directory
    gpg: keyserver receive failed: No dirmngr
    [error] Failed to add trusted package signing keys.
    root@server:~# 
    

    This is fixed by running

    apt -y install dirmngr
    
  • Enable Remote Desktop in Ubuntu 18.04

    Enable Remote Desktop in Ubuntu 18.04

    To enable remote desktop on Ubuntu 18.04 (works with newer Ubuntu versions), go to settings.

    Ubuntu 18.04 settings

    Click on Sharing

    Ubuntu Enable Remote Desktop

    Click on ON/OFF button on title bar to enable Desktop Sharing. Once enabled, click on “Screen Sharing” to See Desktop sharing option, you need to enable it for network connection.

    Ubuntu 18.04 desktop sharing

    Ubuntu use vino package to allow remote desktop over VNC.

    See Ubuntu, VNC, remote desktop

  • Install iftop from source on CentOS

    Install iftop from source on CentOS

    iftop allow you to monitor network traffic like top command. You can download iftop source from

    http://www.ex-parrot.com/~pdw/iftop/

    Before installing, install required packages

    yum -y install libpcap libpcap-devel
    

    To install iftop, run

    cd /usr/local/src
    wget http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.17.tar.gz
    tar xvf iftop-0.17.tar.gz
    cd iftop-0.17
    ./configure --prefix=/usr/local
    make
    make install
    

    To run iftop, type

    iftop
    

    iftop

    See iftop

  • configure: error: can’t find pcap.h

    When installing a software from source, i get error

    configure: error: can't find pcap.h
      You're not going to get very far without libpcap.
    

    To fix this on CentOS 7 server, run

    yum -y install libpcap libpcap-devel
    
  • Linux add a user to group with adduser

    adduser command like useradd, used to add a user to linux server.

    adduser is more interactive, while useradd require all options passed using command line options.

     adduser  [options]  [--home  DIR]  [--shell  SHELL] [--no-create-home] [--uid ID] [--firstuid ID] [--lastuid ID] [--ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] [--gecos GECOS] [--add_extra_groups] user
    

    For creating system user, run

    adduser --system [options] [--home DIR] [--shell SHELL] [--no-create-home] [--uid ID] [--group | --ingroup GROUP | --gid ID] [--disabled-password] [--disabled-login] [--gecos GECOS] user
    

    To add a user, run

    useradd USERNAME_HERE
    

    To delete a user, run

    deladd USERNAME_HERE
    
  • Scan a folder with clamscan

    To scan a folder, run

    clamscan -r /path/to/folder/

    -r will scan sub folders too.

    To Scan a Folder (Only Show Infected)

    clamscan -ri /path/to/folder/

    To exclude a folder from search, use

    clamscan -ri --exclude-dir="^/opt/zimbra/store" /opt/zimbra/

    See clamav