Wednesday, September 14, 2022

mongodump command for backup

 mongodump -d dbname -u username -p password --authenticationDatabase=admin -o /backuplocation/ --gzip

Saturday, January 8, 2022

port scanner python script

import socket
from concurrent import futures
def check_port(targetIp, portNumber, timeout):
TCPsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
TCPsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
TCPsock.settimeout(timeout)
try:
TCPsock.connect((targetIp, portNumber))
return (portNumber)
except:
return
def port_scanner(targetIp, timeout):
threadPoolSize = 500
portsToCheck = 10000
executor = futures.ThreadPoolExecutor(max_workers=threadPoolSize)
checks = [
executor.submit(check_port, targetIp, port, timeout)
for port in range(0, portsToCheck, 1)
]
for response in futures.as_completed(checks):
if (response.result()):
print('Listening on port: {}'.format(response.result()))
def main():
targetIp = input("Enter the target IP address: ")
timeout = int(input("How long before the connection times out: "))
port_scanner(targetIp, timeout)
if __name__ == "__main__":

    main() 

Thursday, December 2, 2021

How to change file extension in Linux.

 

Command line:

Open terminal and type following command "#mv filename.oldextension filename.newextension"

For example if you want to change "index.html" to "index.php" you would type the following command.

#mv index.html index.php

Graphical Mode:

Same as Microsoft Windows right click and rename its extension.

Multiple file extension change.

for x in *.html; do mv "$x" "${x%.html}.php"; done

This script will change all files in current directory ending with html extension to

php extension. (*.html to *.php), You can customize it as per your requirment.

Saturday, August 7, 2021

Connect to mysql through ssh tunnel from php

 

Connect to mysql through ssh tunnel from php

 

shell_exec("ssh -fNg -L 3307:$dbServerHost:3306 user@remote_host");
$conection = new mysqli($dbServerHost, $username, $password, $dbname, 3307);

 

Friday, August 28, 2020

show composer file current version

Composer show is the command that will provide the list of packages i.e. installed by you or your team member.

 

command is

 

 "composer show -i"

Tuesday, August 25, 2020

ELK enterprise application - elk quick build - logstash

 

ELK enterprise application - elk quick build - logstash

 

1, install JDK
elasticsearch, the operation of logstash depends on the java environment.
Download and unzip the jdk binary package.

  1. tar xf jdk-8u144-linux-x64.tar.gz -C /usr/local
  2. mv /usr/local/jdk1.8.0_144 /usr/local/java
  3. cd ~

Configure the java environment variable.
Add the following at the end of the ~/.bashrc file:

  1. export JAVA_HOME=/usr/local/java
  2. export JRE_HOME=$JAVA_HOME/jre
  3. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/bin/tools.jar:$JRE_HOME/lib
  4. export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

Make the configuration take effect.

source ~/.bashrc

2, install Logstash

It is recommended that the Linux class server download the rmp package installation.
2.1. Download the logstash installation package

  1. touch /etc/default/logstash
  2. ln -s /usr/local/java/bin/java /usr/bin/java
  3. rpm -ivh logstash-6.2.4.rpm
  4. cd ~

2.2. Configure systemd to start

When installing rpm, the configuration file for creating the startup script is /etc/logstash/startup.options

/usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd

Note: When the script fails to start, you can create your own startup script.

  1. [root@l ~]# cat /etc/systemd/system/logstash.service
  2. [Unit]
  3. Description=logstash
  4. [Service]
  5. Type=simple
  6. ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
  7. ExecStop=/bin/kill -s QUIT $MAINPID
  8. ExecReload=/bin/kill -s HUP $MAINPID
  9. WorkingDirectory=/usr/share/logstash/bin
  10. [Install]
  11. WantedBy=multi-user.target
  12. [root@l ~]# systemctl daemon-reload #####Update
  13. [root@l ~]#
  14. [root@l ~]# systemctl list-unit-files |grep logstash
  15. logstash.service                              disabled
  16. [root@l ~]#
  17. [root@l ~]# systemctl restart logstash.service #### Restart

 

2.3. Errors encountered

[root@l opt]# /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd
Using provided startup.options file: /etc/logstash/startup.options
Manually creating startup for specified platform: systemd
/usr/share/logstash/vendor/jruby/bin/jruby: Line 401: /usr/bin/java: No such file or directory
Unable to install system startup script for Logstash.

Solution

  1. ln -s /usr/local/java/bin/java /usr/bin/java
  2. /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd

3, configuration

  1. cd /etc/logstash/conf.d/
  2. chown -R logstash /etc/logstash/conf.d
  3. mkdir /opt/logstash
  4. touch /opt/logstash/messages
  5. chown -R logstash /opt/logstash
  6. chown -R logstash /opt/logstash/messages
  7. chown -R logstash /var/log/messages

Shipper configuration file (logstash_shipper.conf)

 
  1. vim logstash_shipper.conf
  2. ###########################################3
  3. input{
  4.   file{
  5.       type => "messages"
  6.       path => "/var/log/messages"
  7.       start_position => "beginning"
  8.       sincedb_path => "/dev/null"
  9.   }
  10. }
  11. output{
  12.    if [type] == "messages"{
  13.       redis{
  14.           host => "10.0.0.132"
  15.           data_type => "list"
  16.           key => "messages"
  17.           port => 6379
  18.           db => 2
  19.           password => "123456"
  20.       }
  21.   }
  22. }

Indexer configuration file (logstash_indexer.conf) Note: This configuration file must be re-node node, otherwise the two output will repeat the output log, plus the redis cache will be infinite output.

 
  1. vim logstash_indexer.conf
  2. ######################################
  3. input{
  4.   redis{
  5.       host => "10.0.0.132"
  6.       data_type => "list"
  7.       key => "messages"
  8.       password => "123456"
  9.       db => 2
  10.   }
  11. }
  12. output{
  13.    if [type] == "messages" {
  14.       elasticsearch{
  15.           hosts => ["10.0.0.130"]
  16.           index => "messages-%{+YYYY-MM-dd}"
  17.       }
  18.   }
  19. }

4, test

 
  1. cd /usr/share/logstash/bin/
  2. ./logstash --path.settings /etc/logstash/ -r /etc/logstash/conf.d/ --config.test_and_exit
  3. [root@l bin]# ./logstash --path.settings /etc/logstash/ -r /etc/logstash/conf.d/ --config.test_and_exit
  4. Sending Logstash's logs to /var/log/logstash which is now configured via log4j2.properties
  5. Configuration OK

5, start

 
  1. systemctl start logstash.service
  2. systemctl enable logstash.service

 

How to solve mysql ERROR 1118 (42000) Row size too large

  I had this issue with MYSQL 5.7 . The following worked althoug...