mongodump -d dbname -u username -p password --authenticationDatabase=admin -o /backuplocation/ --gzip
Secure file download in PHP, Security question PHP, PHP MYSQL Interview Question -Books download - PHP solutions guidelines queries update, phpmysqlquestion
Wednesday, September 14, 2022
mongodump command for backup
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);Monday, August 2, 2021
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.
- tar xf jdk-8u144-linux-x64.tar.gz -C /usr/local
- mv /usr/local/jdk1.8.0_144 /usr/local/java
- cd ~
Configure the java environment variable.
Add the following at the end of the ~/.bashrc file:
- export JAVA_HOME=/usr/local/java
- export JRE_HOME=$JAVA_HOME/jre
- export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/bin/tools.jar:$JRE_HOME/lib
- 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
- touch /etc/default/logstash
- ln -s /usr/local/java/bin/java /usr/bin/java
- rpm -ivh logstash-6.2.4.rpm
- 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.
- [root@l ~]# cat /etc/systemd/system/logstash.service
- [Unit]
- Description=logstash
-
- [Service]
- Type=simple
- ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
- ExecStop=/bin/kill -s QUIT $MAINPID
- ExecReload=/bin/kill -s HUP $MAINPID
- WorkingDirectory=/usr/share/logstash/bin
-
- [Install]
- WantedBy=multi-user.target
-
- [root@l ~]# systemctl daemon-reload #####Update
- [root@l ~]#
- [root@l ~]# systemctl list-unit-files |grep logstash
- logstash.service disabled
- [root@l ~]#
- [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
- ln -s /usr/local/java/bin/java /usr/bin/java
- /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd
3, configuration
- cd /etc/logstash/conf.d/
- chown -R logstash /etc/logstash/conf.d
- mkdir /opt/logstash
- touch /opt/logstash/messages
- chown -R logstash /opt/logstash
- chown -R logstash /opt/logstash/messages
- chown -R logstash /var/log/messages
Shipper configuration file (logstash_shipper.conf)
- vim logstash_shipper.conf
- ###########################################3
- input{
- file{
- type => "messages"
- path => "/var/log/messages"
- start_position => "beginning"
- sincedb_path => "/dev/null"
- }
- }
-
-
- output{
- if [type] == "messages"{
- redis{
- host => "10.0.0.132"
- data_type => "list"
- key => "messages"
- port => 6379
- db => 2
- password => "123456"
- }
- }
- }
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.
- vim logstash_indexer.conf
- ######################################
- input{
- redis{
- host => "10.0.0.132"
- data_type => "list"
- key => "messages"
- password => "123456"
- db => 2
- }
- }
-
- output{
- if [type] == "messages" {
- elasticsearch{
- hosts => ["10.0.0.130"]
- index => "messages-%{+YYYY-MM-dd}"
- }
- }
- }
4, test
- cd /usr/share/logstash/bin/
- ./logstash --path.settings /etc/logstash/ -r /etc/logstash/conf.d/ --config.test_and_exit
- [root@l bin]# ./logstash --path.settings /etc/logstash/ -r /etc/logstash/conf.d/ --config.test_and_exit
- Sending Logstash's logs to /var/log/logstash which is now configured via log4j2.properties
- Configuration OK
5, start
- systemctl start logstash.service
- 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...
-
Introduction to PHP PDO (PHP Data Objects) 1. What is PDO 2. What Databases does PDO support 3. Where do I begin? 4. Connect to ...
-
SQLSTATE[HY000]: General error MySQL: 1364 Field 'coloum' doesn't have a default value, how to solveWith the root access of the mysql, do the following changes select @@ GLOBAL . sql_mode In my case, I get the following: ONLY_FULL_...
-
I had this issue with MYSQL 5.7 . The following worked althoug...