Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Docker centos7

Introduction

In previous posts we have seen the installation and working of Docker. This post will explain the installation of the Docker Community Edition (CE) on CentOS. If you are looking for the Ubuntu installation you should check our this post.

 

Step 1 | Remove Old Versions

$ sudo yum remove docker docker-common docker-selinux docker-engine

Step 2 | Install Required Packages

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Step 3 | Setup the Docker CE Repository

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 4 | Update the Packages

$ sudo yum update

Step 5 |Install specific version (Production recommended)

$ sudo yum list docker-ce.x86_64  --showduplicates | sort -r

Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

$ sudo yum install docker-ce-<VERSION>

Step 6 | Install through respository

$ sudo yum install docker-ce

Step 7 | Start Docker

$ sudo systemctl start docker

Step 8 | Verify the Installation

$ sudo docker run hello-world

This will install the Docker on CentOS.

Redis

what is Redis

Redis is a key-value storage system. Similar to Memcached, it supports storing relatively many value types, including string, list, set, and zset.
These data types support push / pop, add / remove, and intersection and union and difference sets and richer operations, all of which are atomic.
On this basis, Redis supports a variety of different sorts. Like memcached, data is cached in memory for efficiency.
The difference is that Redis periodically writes updated data to disk or writes modifications to additional log files and implements master-slave synchronization based on this. Redis is a high-performance key-value database.
The emergence of Redis, a large extent, to compensate for such lack of keyvalue memcached storage, in some cases can play a good complement to the relational database.

 

1, Redis installation

1.1 Pre-installation environment description

Using a CentOS 7 version of Linux system with
master ip of 192.168.1.110
slave ip of 192.168.1.111 The

1.2 Download Redis

Redis can go to the official website to download: https://redis.io/download , now the latest stable version has reached 4.0.
Used here is redis-4.0.1.tar.gz .

1.3 installation steps

$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar xzf redis-4.0.1.tar.gz -C /usr/local/
$ cd /usr/local/redis-4.0.1
$ make & make test
make Possible exceptions

make[1]: Leaving directory `/usr/local/redis-4.0.1/src’ make[1]: Entering directory `/usr/local/redis-4.0.1/src’
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/redis-4.0.1/src’
make: *** [test] Error 2
solution

yum install -y tcl

2, Redis simple configuration

All configuration changes are in this configuration file

/usr/local/redis-4.0.1/redis.conf

 

2.2 bound host address

Bind after the host to add ip,from behind Redis need to connect through the IP.

bind 127.0.0.1 192.168.1.110

2.3 Set Redis password

The password is set herejaven

# requirepass foobared
requirepass mohan

2.4 Set the Redis port number

The default port is6379

port 6379

3, test Redis

start up
/usr/local/redis-4.0.1/redis.conf
src/redis-server

src/redis-server redis.conf
Client connection

src/redis-cli
src/redis-cli -a mohan

/usr/local/redis-4.0.1/redis.conf
src/redis-cli shutdown
src/redis-cli -p 6666 shutdown

 

4, Redis master-slave replication configuration

Redis master-slave replication is very powerful, a master can have multiple slaves, and a slave can have multiple slaves, so go on, forming a powerful multi-level server cluster architecture. The following simple configuration.

Modify the slave’s redis configuration file

Master’s redis configuration file bindcan be set as long as

Slave redis modify the slave configuration file slaveof 10.211.55.3 6379 (mapped to the main server, 6379the port number)
can also be dynamically set:
Redis-cli connected to the slave node server, execute the following command.
slaveof 10.211.55.3 6379

If master sets the authentication password, you also need to configure masterauth. Here I set the master authentication password javen, so configure masterauth javen.

After configuring the slave start the Redis service, OK, master-slave configuration is completed (is not very simple).
The following test:
In the master and slave, respectively, the info command to view the results are as follows:

slave:

[root@centos-linux-2 redis-4.0.1]# src/redis-cli
127.0.0.1:6379> info

 

 

5, Redis remote connection

Usage: redis-cli [OPTIONS] [cmd [arg [arg …]]]

-h <host ip>, the default is 127.0.0.1

-p <port>, the default is 6379

-a <password>, redis lock, you need to pass the password

-help, Show help information

redis-cli -h 10.211.55.4 -p 6379 -a javen

 

Master and slave MySQL versions are MySQL5.6.31

Master and slave MySQL versions are MySQL5.6.31

Primary server IP: 192.168.1.178

From the server IP: 192.168.1.145

Master and slave are able to ping each other.

A?192.168.1.178?Master?
B?192.168.1.145?Slave?

 

service mysqld stop
service mysqld start
service mysqld restart

 

mysql> grant replication slave on *.* to ‘mohan’@’192.168.1.145’ identified by ‘123456’;
mysql> flush privileges;

vi /etc/my.cnf

port=3306

binlog-ignore-db=mysql
server-id=1
expire-logs-days=7
binlog-ignore-db=information_schema
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
binlog-ignore-db=gogs

service mysqld restart

mysql -u root -proot -P3306
mysql> flush tables with read lock;

show master status;

mysql> show master status;
+——————+———-+————–+——————————————————-+——————-+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+——————+———-+————–+——————————————————-+——————-+
| mysql-bin.000001 | 154 | | mysql,information_schema,performation_schema,sys,gogs | |
+——————+———-+————–+——————————————————-+——————-+
1 row in set (0.00 sec)

5 Slave

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-bin=mysql-bin
server-id=3
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
binlog-ignore-db = performation_schema
binlog-ignore-db = sys
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

 

service mysqld restart

 

mysql> stop slave;
mysql> change master to master_host=’192.168.1.178′,master_user=’mohan’,master_password=’123456′,master_log_file=’mysql-bin.000001′, master_log_pos= 154;
mysql> show slave status \G;

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql>

Setting up MySQL server on aws EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

Install the mysqld server
sudo yum install -y mysql55-server

start the mysqld instance
sudo service mysqld start

the following command ensure launches mysqld on server restart
sudo chkconfig mysqld on

run the following command to set password for root user and delete test databases.
sudo mysql_secure_installation

make a note of the root password ????

Let’s try to create a user and database. This way we can control the database access levels.
mysql -uroot -pmy_root_password

I’m going to create a db_demo with demo_user having password demo123.
CREATE DATABASE db_demo;
USE db_demo;
CREATE USER 'demo_user'@'localhost' IDENTIFIED BY 'demo123';
GRANT ALL PRIVILEGES ON *.* TO 'demo_user'@'localhost' WITH GRANT OPTION;
CREATE USER 'demo_user'@'%' IDENTIFIED BY 'demo123';
GRANT ALL PRIVILEGES ON *.* TO 'demo_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

That’s it. You are all set.

Note:

    • details on mysql privileges can be found here
    • Don’t forget to open the default port 3306 if you want to access the database outside the ec2 instance boundary
    • useful mysqld commands

  • sudo service mysqld start
  • sudo service mysqld stop
  • sudo service mysqld restart
  • sudo service mysqld status

 

Setting git on aws EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

install developer tools
sudo yum groupinstall -y "Development Tools"

install git
sudo yum install git

checkout the source code
git clone https://my.git.repo.git
cd my_local_git_folder
git checkout -f branch_to_checkout

Installing node.js on amazon EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

#install developer tools
sudo yum groupinstall -y "Development Tools"

Install the node using nvm as it allows you to switch between any version of the node ????
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 4.4.5
node -e "console.log('Running Node.js ' + process.version)"

Install pm2
npm install pm2 -g --save

pull the source code in ec2 instance. run your node app using pm2
pm2 start app.js --name="api"

Monitoring Memory Utilisation of aws EC2 instance in CloudWatch

Connect to your EC2 instance using ssh.
ssh -i ec2-user@my_ec2_ip_address

Install following perl packages
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https

Download the monitoring scripts
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O

Install the monitoring scripts
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
cd aws-scripts-mon

run the following command to check the memory utilisation.
./mon-get-instance-stats.pl --recent-hours=12

In order to push this data periodically to cloud watch, we need to create an IAM user with relevant permissions, then schedule a cron job to periodically push the data to aws cloud watch.

Create a new IAM user and provide him access to the ec2 instance and cloud watch. Make a note of the aws credentials i.e. access key and secret key. You need this later. Make sure the IAM user has following access.

cloudwatch:PutMetricData
cloudwatch:GetMetricStatistics
cloudwatch:ListMetrics
ec2:DescribeTags

For the purpose of the demo, you can provide full access to EC2 and CloudWatch (This is not recommended for production.)

run the following command
cp awscreds.template awscreds.con

open the file  awscreds.conf and enter the key & secret.
The content of the file should look something like this

AWSAccessKeyId=AKAWSACESSKEYSA
AWSSecretKey=z/NOAWSSECRETkeyzt

Run the following command to push the data to cloud watch
./mon-put-instance-data.pl --mem-util --mem-used --mem-avail

Now, configure the cron tab to automate this process at eveny 5 minutes interval.
crontab -e
*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --from-cron

In your aws console, go to cloud watch section, and select Metrics => custom namespaces => Linux System. Select the required metrics.

 

AWS S3 permissions

A quick tip on aws S3 permissions to a specific folder in a bucket.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"s3:Put*",
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::nameofmybucket/profile/*"
]
}]
}

Try to avoid bucket root level permission as much as possible. Also, try to use cognito if the client wants to directly access aws resources.

Setting up redis on aws EC2 instance

Setting up redis on aws EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip

Update the instance
sudo yum update -y

Install the developer tools to compile the redis source
sudo yum groupinstall -y "Development Tools"

Install tcl
sudo yum install -y tcl

Download the latest redis source
wget http://download.redis.io/redis-stable.tar.gz

unzip the source
tar xvzf redis-stable.tar.gz

go to the redis folder and run the make command to compile the source
cd redis-stable
make
make test
sudo make install

to run the server, go to the src folder and run the daemonize command.
cd src
./redis-server --daemonize yes

Run the redis-cli command to check if server resonds.
redis-cli
ping

If the response is PONG then you are good to go ????

554 5.7.1 : Relay access denied centos postfix

554 5.7.1 : Relay access denied centos postfix

 

Based on the Postfix documentation, setting mynetworks = all doesn’t appear to be valid, and if you specifically set mynetworks to something, then mynetworks_style is ignored.

Reset mynetworks back to its default value if you want to use mynetworks_style=host, or explicitly set mynetworks to reflect where mail is being sent from (usually localhost and your local subnet). For example:

mynetworks = 127.0.0.0/8 192.168.1.0/24
mynetworks_style = subnet

Based on the Postfix documentation, setting mynetworks = all doesn’t appear to be valid, and if you specifically set mynetworks to something, then mynetworks_style is ignored.

Reset mynetworks back to its default value if you want to use mynetworks_style=host, or explicitly set mynetworks to reflect where mail is being sent from (usually localhost and your local subnet). For example:

mynetworks = 127.0.0.0/8 192.168.1.0/24
mynetworks_style = subnet

How to resolve and prevent 554 5.7.1 : Relay access denied email errors in Linux and Windows mail servers

 

When a mail user tries to send a mail, and gets a bounce.
When mails from a remote domain is rejected by the server, and mail users report it to the server owner.
In either case, we’ve seen the error recorded in mail server logs. It looks something like this:

Jan 23 03:10:57 mysev postfix/smtpd[15921]: NOQUEUE: reject: RCPT from mail-wg0-f53.google.com[74.125.82.53]:
554 5.7.1 <user1@vdomain1.com>: Relay access denied; from=<sender+caf_=sender=sender@gmail.com> to=<user1@domain1.com> proto=ESMTP helo=<mail-wg0-f53.google.com>

1. User authentication system could be broken
All modern mail servers have a way to authenticate a user before it accepts a mail to be sent. So, if we notice ALL of the mail server users getting this error, we immediately check the user authentication settings of mail server.
For example, in Postfix mail server, the below setting enables SMTP authentication. If this is disabled in the configuration file, all the users will receive “554 5.7.1 : Relay access denied“.
smtpd_recipient_restrictions = permit_sasl_authenticated

Page 1 of 16412345...102030...Last »