Category: Linux

  • oneinstack

    oneinstack is a free hosting management software available at

    https://oneinstack.com/

    Documentation available at

    https://oneinstack.com/docs/lampstack-image-guide-en/

    To find MySQL root password, run

    cd /root/oneinstack
    grep dbrootpwd options.conf
    

    Nginx configuration files

    /usr/local/nginx/conf/vhost
    

    Restart Nginx

    systemctl restart nginx
    

    See Hosting Control Panels

  • geekbench

    To benchmark a server with GeekBench, you can run

    wget https://raw.githubusercontent.com/serverok/server-setup/master/benchmark/geekbench-6.sh
    bash ./geekbench-6.sh

    You can create an account on https://browser.geekbench.com and keep all your benchmarks in one place. Here are my Geekbanch benchmarks

    https://browser.geekbench.com/user/55314

    If you get an error installing, you may need to install dependency with

    yum install libgcc.i386 libstdc++.i386 libgcc.i686 libstdc++.i686 -y

    How to Benchmark Cpanel server

    See Benchmark

  • aaPanel – Free Hosting Control Panel

    aaPanel is a free hosting control panel written in Python.

    https://www.aapanel.com/new/index.html
    install php redis extension in aaPanel

    Install aaPanel

    wget -O install.sh http://www.aapanel.com/script/install-ubuntu_6.0_en.sh && sudo bash install.sh forum
    

    Login url

    http://IP_ADDR:9514/login
    

    To reload nginx, run

    /www/server/nginx/sbin/nginx -s reload
    

    Nginx configuration file location

    /www/server/nginx/conf/nginx.conf
    /www/server/panel/vhost/nginx/
    

    Web site files in

    /www/wwwroot/
    

    See Hosting Control Panel

  • sudo

    Linux Run Command as another user
    usermod
    sudo: command not found

    To allow a user to run sudo commands without a password, run

    visudo

    Find

    %sudo   ALL=(ALL:ALL) ALL

    Add below

    USERNAME_HERE    ALL=(ALL:ALL) NOPASSWD:ALL

    This needs to be added after generic rules.

    Example

    boby    ALL=(ALL:ALL) NOPASSWD:ALL
  • Linux Run Command as another user

    To run command as another user on Linux, you can use

    su USER_NAME_HERE -s /bin/bash -c COMMAND_HERE
    

    Or

    sudo -u USER_NAME_HERE COMMAND_HERE
    

    Or

    runuser -l  USER_NAME_HERE -c 'COMMAND_HERE'
    

    See sudo

  • Bash check if a program is running or not

    You can find process id for a running program with command

    pidof BINARY_NAME_HERE
    

    Example

    boby@sok-01:~$ pidof gedit
    22057
    boby@sok-01:~$ ps aux | grep gedit
    boby       22057  4.4  0.7 822760 60280 ?        Sl   14:29   0:00 /usr/bin/gedit --gapplication-service
    boby       22071  0.0  0.0   8904   644 pts/0    S+   14:29   0:00 grep --color=auto gedit
    boby@sok-01:~$ 
    

    We can use pidof command in bash script to find if a program is running or not

    if [ "$(pidof chrome)" ]
    then
    	echo "chrome already running."
    fi
    

    See bash

  • CWP not working after hostname SSL install

    On a CentOS Web Panel (CWP) server, control panel stopped working after installing SSL certficate for hostname.

    When starting cwpsrv service, i get following error.

    [root@nvme ~]# systemctl start cwpsrv
    Job for cwpsrv.service failed because the control process exited with error code. See "systemctl status cwpsrv.service" and "journalctl -xe" for details.
    [root@nvme ~]# systemctl status cwpsrv.service
    ● cwpsrv.service - CentOS Web Panel service (daemon)
       Loaded: loaded (/usr/lib/systemd/system/cwpsrv.service; enabled; vendor preset: disabled)
       Active: activating (auto-restart) (Result: exit-code) since Wed 2021-02-10 04:51:53 CET; 1s ago
      Process: 3779 ExecStartPre=/usr/local/cwpsrv/bin/cwpsrv -t (code=exited, status=1/FAILURE)
    
    Feb 10 04:51:53 nvme.ssdnodo.com systemd[1]: Failed to start CentOS Web Panel service (daemon).
    Feb 10 04:51:53 nvme.ssdnodo.com systemd[1]: Unit cwpsrv.service entered failed state.
    Feb 10 04:51:53 nvme.ssdnodo.com systemd[1]: cwpsrv.service failed.
    [root@nvme ~]# /usr/local/cwpsrv/bin/cwpsrv -t
    cwpsrv: [emerg] annot load certificate key "/etc/pki/tls/private/hostname.key": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/pki/tls/private/hostname.key','r') error:2006D080:BIO routines:BIO_new_file:no such file)
    cwpsrv:configuration file /usr/local/cwpsrv/conf/cwpsrv.conf test failed
    [root@nvme ~]# 
    

    To fix this, i run

    /usr/local/cwpsrv/htdocs/resources/scripts/generate_hostname_ssl
    

    This generated the self signed SSL for hostname. After this CWP control panel started working.

    Apache still was down, fixed it by removing SSL virtualhost config for server hostname form folder

    /usr/local/apache/conf.d/vhosts/
    

    You can see hostname auto SSL logs at

    /var/log/cwp/autossl.log
    

    See CWP

  • Auto restart newrelic-daemon if crashed

    On a web server with Newrelic APM installed, graph stopped showing new data. On checking the newrelic log file, i get following error

    root@new-website-2:~# tail -f /var/log/newrelic/php_agent.log
    2021-02-08 17:21:27.453 +0000 (680439 680439) warning: daemon connect(fd=13 uds=@newrelic) returned -1 errno=ECONNREFUSED. Failed to connect to the newrelic-daemon. Please make sure that there is a properly configured newrelic-daemon running. For additional assistance, please see: https://newrelic.com/docs/php/newrelic-daemon-startup-modes
    

    This is because newrelic-daemon stopped working. To auto restart newrelic-daemon if it crash, do the following

    mkdir -p /usr/serverok
    vi /usr/serverok/newrelic
    

    Add following to the file

    #!/bin/bash
    # Author: ServerOK
    # Web: https://serverok.in/auto-restart-newrelic-daemon
    
    CURRENT_STATUS="$(/etc/init.d/newrelic-daemon status)"
    
    TIME_STAMP="$(date "+%Y-%m-%d %H:%M:%S")"
    
    if [[ ! "${CURRENT_STATUS}" =~ "newrelic-daemon is running" ]]
    then
        /etc/init.d/newrelic-daemon start
        echo -e "${TIME_STAMP} newrelic-daemon down\n"
    fi
    

    Make the script executable

    chmod 755 /usr/serverok/newrelic 
    

    Create a cronjob

    crontab -e
    

    Add following cronjob

    */5 * * * * /usr/serverok/newrelic > /var/log/newrelic/monitor.log 2>&1
    

    See Server Monitoring, Application Performance Monitor (APM)

  • bash check if a folder is empty or not

    To check if a folder is empty of not, you can use

    if [ "$(ls -A /home/boby/1/ )" ]
    then
        echo "Files found"
    else
        echo 'No files found'
    fi
    

    If you want to reverse the checking, you can use !

    if [ ! "$(ls -A /home/boby/1/ )" ]
    then
        echo "No files found"
    else
        echo 'Files found.'
    fi
    

    See bash

  • Ant Media Server Ubuntu firewall configuration

    Ant Media Server Ubuntu firewall configuration

    To enable firewal for Ant Media Server on Ubnuntu server, use following rules

    ufw allow ssh
    ufw allow http
    ufw allow https
    ufw allow 1935/tcp
    ufw allow 5080/tcp
    ufw allow 5443/tcp
    ufw allow 5000:65000/udp
    enable ufw
    

    After enabling, you will have following status

    root@server:~# ufw status
    Status: active
    
    To                         Action      From
    --                         ------      ----
    22/tcp                     ALLOW       Anywhere                  
    80/tcp                     ALLOW       Anywhere                  
    443/tcp                    ALLOW       Anywhere                  
    1935/tcp                   ALLOW       Anywhere                  
    5080/tcp                   ALLOW       Anywhere                  
    5443/tcp                   ALLOW       Anywhere                  
    5000:65000/udp             ALLOW       Anywhere                  
    22/tcp (v6)                ALLOW       Anywhere (v6)             
    80/tcp (v6)                ALLOW       Anywhere (v6)             
    443/tcp (v6)               ALLOW       Anywhere (v6)             
    1935/tcp (v6)              ALLOW       Anywhere (v6)             
    5080/tcp (v6)              ALLOW       Anywhere (v6)             
    5443/tcp (v6)              ALLOW       Anywhere (v6)             
    5000:65000/udp (v6)        ALLOW       Anywhere (v6)             
    
    root@server:~# 
    

    Port forwarding

    You can forward port 80 and 443 to Ant Media Server, so you don’t have to use ports.

    You can use following iptables commands

    sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 5080
    sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 5443
    

    To make it permanent, edit

    vi /etc/ufw/before.rules
    

    In the beginning of the file, find

    *filter
    

    Add above

    *nat
    :PREROUTING ACCEPT [0:0]
    -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 5080
    -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 5443
    COMMIT
    

    Restart ufw firewall

    ufw disable
    ufw enable
    

    See Ant Media Server