Posts

Showing posts from August, 2019

Stop and Start NFS and Related Services

Using restart option (i.e. service nfs restart) may crash / freeze your Linux computer if executed.

Stop NFS server:  

# service nfslock stop
# service nfs stop
# service portmap stop
# umount /proc/fs/nfsd

Start service in following order:
# service portmap start
# service nfs start
# service nfslock start
# mount -t nfsd nfsd /proc/fs/nfsd

How to bind / configure NIC teaming/bonding in CentOS / Oracle Linux / RedHat Linux

Following is an example of how to configure NIC teaming/bonding

1) create channel bonding interface
$ sudo vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0 BOOTPROTO=none IPADDR=192.168.1.199 NETMASK=255.255.254.0 GATEWAY=192.168.1.1 ONBOOT=yes USERCTL=no TYPE=Ethernet DNS1=8.8.8.8 DNS1=8.8.4.4 IPV6INIT=no
$ sudo vim /etc/sysconfig/network-scripts/ifcfg-em1 (em2, em3 ...) and add/change the values:

TYPE=Ethernet BOOTPROTO=none IPV4_FAILURE_FATAL=no NAME=em1 ONBOOT=yes MASTER=bond0 SLAVE=yes USERCTL=no NM_CONTROLLED=no
2)edit /etc/modprobe.d/

$ sudo vim /etc/modprobe.d/bond0.conf
alias bond0 bonding

3)config mode=4
#echo "802.3ad 4" > /sys/class/net/bond0/bonding/mode
( If you failed to modify the file content by vim, this echo command can help you)
( When your bonding is running, you may not be able to modify it, you may need to stop it by
systemctl stop network before you can modify it)
(optional, defaults to 'balance-rr 0')
If you configure an LACP bond to t…

Setting JDK in Eclipse

The list of available compilers are in the Window -> Preferences -> Java -> Installed JRE's tab.

Lambda is a fully managed compute service

Lambda is a fully managed compute service that runs your code in response to events generated by custom code or from various AWS services such as Amazon S3, DynamoDB, Kinesis, Amazon SNS, and Amazon Cognito.

The AWS SAM CLI is a separate command line tool that you can use to manage and test AWS SAM applications.

In addition to commands for uploading artifacts and launching AWS CloudFormation stacks that are also available in the AWS CLI, the SAM CLI provides additional commands for validating templates and running applications locally in a Docker container.

How to suspend and resume Linux processes

You can use kill to stop the process.

For a 'polite' stop to the process (prefer this for normal use), send SIGTSTP:

kill -TSTP [pid]
For a 'hard' stop, send SIGSTOP:

kill -STOP [pid]
Note that if the process you are trying to stop by PID is in your shell's job table, it may remain visible there, but terminated, until the process is fg'd again.

To resume execution of the process, sent SIGCONT:

kill -CONT [pid]

You can use AWS CLI to add multiple FQDN in a single command while creating a new ACM certificate.

Following is the command you can use to achieve this,

aws acm request-certificate --domain-name example.com  --validation-method DNS --subject-alternative-names b.example.comc.example.comd.example.com

A Gradle plugin that provides Maven-like dependency management functionality

A Gradle plugin that provides Maven-like dependency management functionality
https://github.com/spring-gradle-plugins/dependency-management-plugin

Build Your Java Project with Apache Maven

Once you set up your project, you can build it using Maven's package command.
mvn package
This creates your .jar file in the target directory.

SQL server Express vs developer

Developer Edition supports more features and larger databases. For example, if you want to restore a 88gb database from your production server onto your workstation to do testing, you'll need Developer Edition.

If you're working with Enterprise-only features like partitioning, compression or the Resource Governor. Those features aren't available in Express, but they are available in Developer Edition.

And SQL Express is quite capable of handling fair loads.

SQL Server Express does not require licensing but has a smaller set of features.

Developing against full SQL Server (and Developer Edition matches Enterprise Edition) always leaves the chance that you rely on some feature that is not in the production edition.

By default, Postfix configuration files are in /etc/postfix.

The two most important Postfix configuration files are main.cf and master.cf; these files must be owned by root.
Giving someone else write permission to main.cf or master.cf (or to their parent directories) means giving root privileges to that person.

Open source client for AnyConnect

"network-manager-openconnect-gnome" package in the Ubuntu Repository. It uses OpenConnect which is an open source client for AnyConnect.
You can find the package in the Ubuntu Software Center or Synaptic by searching for "OpenConnect."

If you wish to install it via the command-line, you can do so with:

sudo apt install network-manager-openconnect-gnome

Run Unix commands from within Vim

:shell :sh[ell] start a shell :! :!{command} execute {command} with a shell

Create a basic Maven package

mvn -B archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DgroupId=org.example.basicapp \
  -DartifactId=myapp

Resources for preparing technical interviews

LeetCode is a social platform for preparing IT technical interviews. It strives to provide you with the best learning experience in preparing interviews for companies in the IT industry.

ProgrammerInterview.com is to help programmers successfully prepare for technical interviews. It does this by presenting a variety of questions, grouped by subject matter. This site is a great resource for any level of programmer – whether you are an entry level “fresher” just starting out your career, or an experienced senior level programmer who is looking for more advanced questions, it presents a wide variety of real interview questions.


AWS SDK Eclipse Toolkit provides an Eclipse plugin for you to both create a deployment package and also upload it to create a Lambda function.

AWS SDK Eclipse Toolkit plugin enables you to author Java code, create and upload a deployment package, and create your Lambda function.

Install docker on AWS EC2

sudo amazon-linux-extras install docker

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.

Example:
$ sdk install gradle 5.6.1

Build Anything by Gradle Build Tool

Write in Java, C++, Python or your language of choice. Package for deployment on any platform. Go monorepo or multi-repo. And rely on Gradle's unparalleled versatility to build it all.
https://gradle.org/

Shell script to identify duplicate Java classes.

mkdir -p expanded unzip path/to/my/i88ca.jar -d expanded find ./expanded/lib -name '*.jar'| xargs -n1 zipinfo -1 | grep '.*.class'| sort | uniq -c | sort

Executable JAR by maven

You can simply use

java -cp path-to-your-jar:path-to-your-lib your-full-main-class-name

to run the jar.

For example:
java -cp /i88/ca/example.jar:/i88/ca/lib/* it.i88.ca.example.App
If you encounter "Failed to load Main-Class manifest attribute" problem, this is probably because you have no Main-Class attribute specified in the manifest file.

To create an executable JAR, one simply needs to set the main class that serves as the application entry point.

<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <ma…

Solution: Unable to locate package on Ubuntu

Updating the package index:

sudo apt update

Next, install Maven by typing the following command:

sudo apt install maven

What version of Java is being used by Maven

mvn -version will output which java it's using.
$ mvn -version Apache Maven 3.0.5 (Red Hat 3.0.5-17) Maven home: /usr/share/maven Java version: 1.8.0_222-ea, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b03-1.amzn2.0.1.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.14.114-105.126.amzn2.x86_64", arch: "amd64", family: "unix"



How to solve: "ERROR: Maven JVM terminated unexpectedly with exit code 137"

In case your Jenkins CI fails to complete building your project but only logging the following:

ERROR: Maven JVM terminated unexpectedly with exit code 137

It means maven does NOT have enough memory available. To solve this, simply increase your MAVEN_OPTS memory. Or you may need to increase your system's memory. This is very likely if you run your Jenkins on a virtual machine and you are stingy of memory.

shade is bound to the package phase and is used to create a shaded jar.

Apache Maven Shade Plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.
https://maven.apache.org/plugins/maven-shade-plugin/

The federal telecom regulator significantly lowered the wholesale rates

The federal telecom regulator significantly lowered the wholesale rates that smaller internet resellers pay to access broadband network infrastructure built by major providers like Bell Canada, Rogers.
The CRTC said it did so to increase choice, affordability and ensure a competitive marketplace across Canada.

Intel Project Athena machines

Intel unveiled the new Comet Lake 10th-gen chips that will power all sorts of notebooks later this year. 
Comet Lake chips will bring support for more cores, more RAM of the faster and more efficient variety, as well as faster Wi-Fi 6 support. 
These chips will power a special set of laptops that Intel certifies under the “Project Athena” program.
Project Athena machines are supposed to be ultraslim, light devices that feature all-day battery life, always-on internet, and AI support. 
Project Athena machines also have to deliver increased performance and responsiveness, and that includes the ability to turn on instantly.

Get the list of event source mappings while using AWS Lambda with Amazon Simple Queue Service

You can get the list of event source mappings by running the following command.

$ aws lambda list-event-source-mappings --function-name ProcessSQSRecord \
--event-source SQS-queue-arn
The list returns all of the event source mappings you created, and for each mapping it shows the LastProcessingResult, among other things. This field is used to provide an informative message if there are any problems. Values such as No records processed (indicates that AWS Lambda has not started polling or that there are no records in the queue) and OK (indicates AWS Lambda successfully read records from the queue and invoked your Lambda function) indicate that there no issues. If there are issues, you receive an error message.

Get Dell Service Tag from the command line

Get your Dell Service Tag from the command line


Windows: From a command prompt, type: wmic bios get serialnumber
Linux: From a terminal, type:
sudo -i dmidecode -s system-serial-number

MySQL uses DATEDIFF to compare two date type values.

DATEDIFF() returns expr1 − expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

mysql> SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
        -> 1
mysql> SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');
        -> -31

Integrate API Gateway with SQS

Image
1. Create SQS queue

Open AWS console in services, navigate to Simple Queue Service. Click on “Create New Queue” Give queue a name, in our case it is “beaches” and hit “Create Queue”



2. Create IAM Policy for AWS API Gateway to push Request Message to Queue.

Select IAM, Navigate to “policies” and click on “Create Policy”.

Open JSON editor and add the following policy, click on “Review Policy”, name policy as beaches-policy and hit “Create Policy”.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": "sqs:SendMessage", "Resource": "arn:aws:sqs:your-sqs-arn:123456789:beaches" } ] }
Both send and receive permissions:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0"…

How to find all watching JIRA issues

watcher = currentUser()

How to temporarily disable an account on Windows 10

How to disable a Windows 10 account using Computer Management On Windows 10 Pro or Enterprise, you can use Computer Management to manage various aspects of an account, including the ability to restrict access to an account.

Open Start.
Search for Computer Management and click the top result to open the console.
Quick tip: You can also use the Windows key + X keyboard shortcut and selecting Computer Management.
Browse the following path:
System Tools > Local Users and Groups > Users
Double-click the account you want to disable. (If the user account is using a Microsoft account, note that the name will only use the first five letters of the email address. If you want the account to use a custom name, you can refer to this guide.)
Under the "General" tab, check the Account is disabled option.
Click Apply.
How to disable a Windows 10 account using Command Prompt If your device is running Windows 10 Home, you can use Command Prompt to disable or enable a Windows 10 account…

VMware bought Pivotal Software Inc in a $2.7 billion deal.

VMware to pay $5 billion for firms offering cloud security, developers platform

Get HttpServletRequest object in restful web service

@POSTpublicResponse post(@ContextHttpServletRequest request, @ContextHttpServletResponse response){ returnResponse .ok("pong2") .build(); }

Testing Rest APIs using Spring 5 WebTestClient

WebTestClient contains request methods that are similar to WebClient. 
In addition, it contains methods to check the response status, header and body.  You can also use assertion libraries like AssertJ with WebTestClient.

WebClient is part of Spring 5’s reactive web framework called Spring WebFlux.

To use WebClient, you need to include the spring-webflux module in your project.

Add Dependency in an existing Spring Boot project

If you have an existing Spring Boot project, you can add the spring-webflux module by adding the following dependency in the pom.xml file -

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

Spring Boot version 2.x.x is needed for using the Spring WebFlux module.

WebClient vs RestTemplate in Spring

Starting with Spring 5, the non-blocking and reactive WebClient offers a modern alternative to RestTemplate. WebClient offers support for both synchronous and asynchronous HTTP requests and streaming scenarios. Therefore, RestTemplate will be marked as deprecated in a future version of the Spring Framework and will not contain any new functionalities.

strace is a diagnostic, debugging and instructional userspace utility for Linux.

strace is a powerful command line tool for debugging and trouble shooting programs in Unix-like operating systems such as Linux. It captures and records all system calls made by a process and the signals received by the process.
strace is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state. The operation of strace is made possible by the kernel feature known as ptrace. Some Unix-like systems provide other diagnostic tools similar to strace, such as truss.

MySQL Warning | 1681 | 'INFORMATION_SCHEMA.INNODB_LOCK_WAITS' is deprecated and will be removed in a future release

For MySQL 8, use performance_schema

SELECTr.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query FROMperformance_schema.data_lock_waits w INNER JOINinformation_schema.innodb_trx b ONb.trx_id=w.blocking_engine_transaction_idINNER JOINinformation_schema.innodb_trx r ONr.trx_id=w.requesting_engine_transaction_id;

How do I hide my IP address?

The most common method to hide your IP address is to use a proxy or a VPN

What is an IP Address?

The Internet Protocol Address (or IP Address) is a unique address that
computing devices such as personal computers, tablets, and smartphones
use to identify itself and communicate with other devices in the IP
network. Any device connected to the IP network must have a unique IP
address within the network. An IP address is analogous to a street
address or telephone number in that it is used to uniquely identify an
entity.

Azure Automation

Azure Automation delivers a cloud-based automation and configuration
service that provides consistent management across your Azure and
non-Azure environments. It consists of process automation, update
management, and configuration features. Azure Automation provides
complete control during deployment, operations, and decommissioning of
workloads and resources.

Curl command without using cache

curl -H 'Cache-Control: no-cache' http://i88.ca

Follow Redirects with cURL

curl -L i88.ca

The -L flag instructs cURL to follow any redirect so that you reach
the eventual endpoint.

Alter MySQL table without locking

In case you are not sure if an ALTER TABLE will copy and/or block the table, and you want to make sure your DDL statement won’t cause such problems, you can add new alter specifications to the statement: ALGORITHM and LOCK.

ALTERTABLE i88ca ENGINE=InnoDB, LOCK=NONE; ALGORITHM [=] {DEFAULT|INPLACE|COPY}LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE}

Debug MySQL performance Script.sql

-- run as rootTEE mysql_output.txt; SELECT VERSION(); SELECT NOW(); SHOW GLOBAL VARIABLES; SHOW MASTER STATUS; SHOW SLAVE STATUS\G SHOW GLOBAL STATUS; SHOW FULL PROCESSLIST; SHOW ENGINE INNODB STATUS\G SHOW FULL PROCESSLIST; -- Info on transactions and locks SELECTr.trx_wait_startedAS wait_started, TIMEDIFF(NOW(), r.trx_wait_started) AS wait_age, rl.lock_tableAS locked_table, rl.lock_indexAS locked_index, rl.lock_typeAS locked_type, r.trx_idAS waiting_trx_id, r.trx_mysql_thread_idAS waiting_pid, r.trx_queryAS waiting_query, rl.lock_idAS waiting_lock_id, rl.lock_modeAS waiting_lock_mode, b.trx_idAS blocking_trx_id, b.trx_mysql_thread_idAS blocking_pid, b.trx_queryAS blocking_query, bl.lock_idAS blocking_lock_id, bl.lock_modeAS blocking_lock_mode FROMinformation_schema.INNODB_LOCK_WAITS w INNER JOINinformation_schema.INNODB_TRX b ONb.trx_id=w.blocking_trx_idINNER JOINinformation_schema.INNODB_TRX r ONr.trx_id=w.requesting_trx_idINNER JOINinformation_schema.INNODB_LOCKS …

How to deal with Lock wait timeout exceeded in MySQL

Run SHOW ENGINE INNODB STATUS\G after your failed statement, you can find what caused the lock.

pt-deadlock-logger - Log MySQL deadlocks

can do this job for you.

You should consider increasing the lock wait timeout value for InnoDB by setting the innodb_lock_wait_timeout

show variables like 'innodb_lock_wait_timeout';

SET innodb_lock_wait_timeout = 120; (only for current session)

Or

SET GLOBAL innodb_lock_wait_timeout = 120;

or put to configuration file:

[mysqld]
innodb_lock_wait_timeout=120

MySQL how to get non sleep processlist

$ mysqladmin --login-path=root processlist | grep -v 'Sleep' | less

Get only process ids:
$ mysqladmin --login-path=root processlist | grep -v 'Sleep'  | awk -F '|' '{print $2}'
Others:
SELECT*FROMINFORMATION_SCHEMA.PROCESSLIST; SELECT*FROMINFORMATION_SCHEMA.PROCESSLISTwhere command !='Sleep'; SELECT*FROMINFORMATION_SCHEMA.PROCESSLISTwhere command !='Sleep'and STATE !='Waiting for table metadata lock'; SELECTcount(*) FROMINFORMATION_SCHEMA.PROCESSLISTwhere STATE ='Waiting for table metadata lock';

Change the background color and design of all your Office programs

To change the background color and design of all your Office programs, go to  File > Options > General > Office Theme.

Email delivery testing tool

If you are a G Suite admin, consider the following best practices to generally improve security:

if you are a G Suite admin, consider the following best practices to generally improve security:
Review and verify current OAuth API access by third-parties.Run OAuth Token audit log reports to catch future inadvertent scope grants and set up automated email alerts in the Admin console using the custom alerts feature, or script it with the Reports API.Turn on 2-step verification for your organization and use security keys.Follow the security checklist if you feel that an account may be compromised.Help prevent abuse of your brand in phishing attacks by publishing a DMARCpolicy for your organization.Use and enforce rules for S/MIME encryption

Do SPF Records apply to subdomains?

You need to have separate SPF records for each subdomain you wish to send mail from. http://www.openspf.org/FAQ/The_demon_question

This makes sense - a subdomain may very well be in a different geographical location which will have a very different SPF definition.

The 'include:' directive for SPF may be used to provide all subdomains with the same entries. For example, on the SPF record for subdomain mailfrom.example.com enter 'include:example.com'. In this fashion whenever you update the definition for example.com your subdomains will automatically pick up the updated values.

If a subdomain is created as a CNAME record, the SPF record is the one for the domain it points to, e.g. sub.domain.com is a CNAME of otherdomain.com, the SPF a mail server will get when it looks up mail@sub.domain.com is in the DNS record for otherdomain.com. This is the same if the CNAME record says sub.domain.com => othersub.domain.com, so your TXT record would need to be othersub, not sub…

PowerMTA pmta command

Usage: pmta [options] command

where 'options' are:
    --help                display this message
    --xml                 display result in XML
    --dom                 display result as DOM-like "variables"

and where 'command' is one of:
    clear dnscache domainname
    check mfrom [--tcp] [--dumppackets] mfrom ip
    check spf [--tcp] [--dumppackets] ip heloDomain [mailFrom]
    delete [--dsn] [--queue=domain[/vmta]] [--orig=addr] [--rcpt=addr] [--jobId=id] [--envId=id] [--older-than=time-interval] [--no-accounting]
    deregister [--user=name] [--local-only] [--retain-unloaded]
    disable source [--reenable-after=interval] ip domain[/vmta]
    enable source ip domain[/vmta]
    list [--queue=domain[/vmta]] [--orig=addr] [--rcpt=addr] [--jobId=id] [--envId=id] [--maxitems=n] [--older-than=time-interval] [--pause] [--priority] [--schedule]
    pause queue domain[/vmta]
    pause job jobid
    register [--user=name] [--label=name] [--webmon-ip=ip] [--we…

From address for DKIM and SPF

SPF is checking on the envelop's from address such as "Mail From" or smtp.from.

DKIM is checking on the inside letter's from address, not the envelop's from address.

MySQL: How to check foreign keys related to a table

SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROMINFORMATION_SCHEMA.KEY_COLUMN_USAGEWHERE REFERENCED_TABLE_NAME ='Your_Table';