Delete common rows between tables


tableA                                                        
apple@gmail.com
ram@gmail.com
user@hotmail.com
jai@qqmail.com
bai@example.com

tableB
ram@gmail.com
jai@qqmail.com

Query

delete
    from tableA
where exists
  ( select 1 
         from tableB
          where email = tableA.email )

Resulting table tableA  where common item from tableB is deleted: 

TableA
apple@gmail.com
user@hotmail.com
bai@example.com

part 5 dockerizing simple flask application and docker exec

### vim Dockerfile

FROM python:3.5
RUN pip install  Flask==0.11.1
RUN useradd -ms /bin/bash admin
USER admin
WORKDIR /app
COPY app /app
CMD ["python", "app.py"]

###

docker build -t urgen/dockerapp:1.01

docker images   <copy imageid>

docker run -d -p 5000:8080

    -d = run container in background
    -p = expose port
    5000 = port of container
    8080 = port of real host


user1@localhost ~ $ docker run -d -i -t busybox
8ba73738bf52630e31106be2f3a1cb4d4e0ab8f79d311f38c6ec8ff5ce7eba24

# to docker exec the container must be running in background (-d option)
docker exec -it 8ba73738bf52630e31106be2f3a1cb4d4e0ab8f79d311f38c6ec8ff5ce7eba24  sh

part 4 push docker image to docker hub public

1) docker images  ## list images

docker tag  <image id>  <docker hub repositoryname>:<tag>

2) docker tag  c75bebcdd211 urgensherpa2/box1:1.01

docker login --username=urgensherpa2
password:
Login succeed

3) docker push urgensherpa2/box1:1.01

part 4 docker automate building images

Build docker images

   docker file - is text doc that contains all the instructions to assemble the image

By default the filename is "Dockerfile" where we put all the instructions

cd /home/user1/

# vim Dockerfile
FROM debian:jessie
RUN apt-get update
RUN apt-get install -y git vim rsync
COPY localfile.txt  /src/localfile.txt   ##copy local file to containers /src/ directory ..look ADD command too!

docker build -t repositoryname:tag .


docker build -t vieux/apache:2.0 .

docker build -t urgen/dockerfiledemo -f Dockerfile /home/user1/

docker build -t urgen/dockerfiledemo -f customdockerfilemame /home/user1/

OR

docker build -t ubuntu:latest .

    --tag, -t  = Name and optionally a tag in the ‘name:tag’ format
    --file, -f = Name of the Dockerfile (Default is ‘PATH/Dockerfile’)


in screenshot "Dockerfile" is saved at /home/user1/docker directory

part 3 docker build images and commit , delete and stop running containers

Docker image is made up of list of readonly layes that represent filesystem differences. image layers are stacked on top of each other to form up a base for container's filesystem

Install GIT in a base image called ubuntu:latest

# docker run -it ubuntu:latest
apt-get update && apt-get install -y git

exit

# docker ps -a     ...grab container id


Docker commit - Create a new image from a container's changes
## commit changes and save to a new container named ubuntu:1.00
docker commit 4188d246e83c urg3n/ubuntu:1.00

docker commit d823hjhd8fj2    repositoryname:tag

# list new images created
--> docker images

docker run -it urg3n/ubuntu:1.00

## Delete container !!! ##

docker ps -a   and grab container id

docker rm 247e45581fed    ### removes container with ID 247e45581fed

part 2 docker port mapping and run in background

## remove docker container after running the command called "sleep 100"
docker run --rm busybox:1.24  sleep 100

## specify name for docker container we want to run
docker run  --name  mycontainer100 busybox:1.24
docker run  --name  mycontainer200 busybox:latest
docker ps -a

docker inspect containerid
##outpus image id , logpath,mac id

user1@localhost$ docker run -d busybox:latest sleep 10
a7393fc5cc8e1db7e87b9eb24151147

user1@localhost$ docker inspect a7393fc5cc8e1db7e87b9eb24151147


### docker tomcat
expose container port 8080 to host port 8888

docker run -it -p 8888:8080 tomcat:8.0

-->open browser--goto--> localhost:8888  it willopen tomcat server


# run container in detached mode

docker run -it -d -p 8888:8080 tomcat:8.0 

docker exec <name> /bin/cat /etc/profile
docker logs <name>

#docker run -d -p <hostport>:<containerPort>  nginx:latest

a7393fc5cc8e1db7e87b9eb24151147sf
docker logs a7393fc5cc8e1db7e87b9eb24151147sf

# Docker attach or login into the running container :-

docker exec -it containeridORname /bin/bash

# Docker management
# delete all containers
docker ps -aq | xargs docker rm -f

docker logs <cont id>   # view the output logs of container






mysql database size

To determine the sizes of all of your databases, at the mysql> prompt type the following command:

SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;


To determine the sizes of all of the tables in a specific database, at the mysql> prompt, type the following command. Replace database_name with the name of the database that you want to check:

SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;

git dealing with remotes

Add a remote

git remote add origin https://github.com/user/repo.git
# Set a new remote

git remote -v
# Verify new remote
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Remove remote

git remote -v
# View current remotes
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)
destination  https://github.com/FORKER/REPOSITORY.git (fetch)
destination  https://github.com/FORKER/REPOSITORY.git (push)

git remote rm destination
# Remove remote
git remote -v
# Verify it's gone
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)



Rename the remote

git remote -v
# View existing remotes
origin  https://github.com/OWNER/REPOSITORY.git (fetch)
origin  https://github.com/OWNER/REPOSITORY.git (push)

git remote rename origin destination
# Change remote name from 'origin' to 'destination'

git remote -v
# Verify remote's new name
destination  https://github.com/OWNER/REPOSITORY.git (fetch)
destination  https://github.com/OWNER/REPOSITORY.git (push)


remote add origin git@gitlab.com:urg3n/mailservice935dovecot.git

git push origin master

postfix firewall daemon postfwd

https://www.vooservers.com/technical-blog/rate-limit-outbound-mail-in-postfix/

DKIM on postfix and bind

Open dkim on postfix


yum install opendkim

## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes
AutoRestartRate         10/1h
LogWhy                  Yes
Syslog                  Yes
SyslogSuccess           Yes
Mode                    sv
Canonicalization        relaxed/simple
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

Generate set of keys for your mydomain.com domain name:

## mkdir /etc/opendkim/keys/mydomain.com
## opendkim-genkey -D /etc/opendkim/keys/mydomain.com/ -d mydomain.com -s default
## chown -R opendkim: /etc/opendkim/keys/mydomain.com
## mv /etc/opendkim/keys/mydomain.com/default.private /etc/opendkim/keys/mydomain.com/default


add mydomain.com to OpenDKIM’s key table by adding the following record in /etc/opendkim/KeyTable

default._domainkey.mydomain.com mydomain.com:default:/etc/opendkim/keys/mydomain.com/default
next, edit /etc/opendkim/SigningTable and add the following record to OpenDKIM’s signing table:

*@mydomain.com default._domainkey.mydomain.com


And add your domain and your hostname as trusted hosts in /etc/opendkim/TrustedHosts  

127.0.0.1
mydomain.com
host.mydomain.com
assuming the domain in question is ‘mydomain.com’ and server’s hostname is set to ‘host.mydomain.com’

finally, edit your mydomain.com DNS zone and add the TXT record from

/etc/opendkim/keys/mydomain.com/default.txt

default._domainkey      IN      TXT     ( "v=DKIM1; k=rsa; "
          "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDApHRr7ZmXRaAB+RQRbP4VdMwIrIHIP18KFtXRsv/xpWc0Gix6ZXN13fcG03KNGKZo2PY+csPkGC5quDnH5V0JEhDZ78KcDWFsU6u4fr9ktVAdt6P7jWXjcyqdHOZ8+YN4cAeU4lRFNgQvdupIcByYwzPYMgBFHfJm9014HvRqhwIDAQAB" )  ; ----- DKIM key default for mydomain.com


Verify by 
## dig +short default._domainkey.mydomain.com TXT

CONFIGURE POSTFIX

In order to integrate OpenDKIM with Postfix we need to add the following few lines in /etc/postfix/main.cf:

smtpd_milters           = inet:127.0.0.1:8891
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 2

## service opendkim start
## chkconfig opendkim on
## service postfix restart





 ## cp /etc/opendkim.conf{,.orig}
## vim /etc/opendkim.conf

AutoRestart             Yes  #Automatically re-start on failures.  Use with caution; if the filter fails instantly after it starts, this can cause a tight fork(2) loop

AutoRestartRate         10/1h  # This is a string of the form n/t[u] where n is an integer limiting the count of restarts in the given interval and t[u] defines the time  inter‐
              val  through which the rate is calculated;

LogWhy                  Yes # If  logging is enabled (see Syslog below), issues very detailed logging about the logic behind the filter's decision to either sign a message or verify it
Syslog                  Yes

SyslogSuccess           Yes #Log via calls to syslog(3) additional entries indicating successful signing or verification of messages.

Mode                    sv   # Valid modes  are  s
              (signer)  and  v (verifier).  The default is sv except in test mode (see the opendkim(8) man page) in which case the default is v.  When signing
              mode is enabled, one of the following combinations must also be set: (a) Domain, KeyFile, Selector, no KeyTable, no SigningTable; (b)  KeyTable,
              SigningTable, no Domain, no KeyFile, no Selector; (c) KeyTable, SetupPolicyScript, no Domain, no KeyFile, no Selector.


Canonicalization        relaxed/simple   #  Selects the canonicalization method(s) to be used when signing messages.  When verifying, the message's DKIM-Signature: header  field  specifies
              the  canonicalization  method.   The recognized values are relaxed and simple as defined by the DKIM specification.  The default is simple.  The
              value may include two different canonicalizations separated by a slash ("/") character, in which case the first will be applied  to  the  header
              and the second to the body.


ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp