Docker: CentOS 7 Fun. 
[aesteban@localhost ~]$ 
[aesteban@localhost ~]$
[aesteban@localhost ~]$ cat /etc/redhat-release
Fedora release 24 (Twenty Four)
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[aesteban@localhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker pull centos:7
Trying to pull repository docker.io/library/centos ...
7: Pulling from docker.io/library/centos

a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:7
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos 7 1e1148e4cc2c 6 days ago 201.8 MB
[aesteban@localhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[aesteban@localhost ~]$ sudo docker run -d --privileged -p 80:80 docker.io/centos:7 /sbin/init
f0faf6197fbc696796333bfc81f25d537a1aba170b81f2076010222e84284b36
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker exec -it f0faf6197fbc696796333bfc81f25d537a1aba170b81f2076010222e84284b36 bash
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# yum install epel-release
...
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# yum install nginx
...
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# systemctl start nginx
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-12-12 02:55:32 UTC; 4s ago
Process: 2643 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 2642 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 2641 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 2644 (nginx)
CGroup: /system.slice/docker-f0faf6197fbc696796333bfc81f25d537a1aba170b81f2076010222e84284b36.scope/system.slice/nginx.service
├─2644 nginx: master process /usr/sbin/nginx
├─2645 nginx: worker process
├─2646 nginx: worker process
├─2647 nginx: worker process
└─2648 nginx: worker process

Dec 12 02:55:31 f0faf6197fbc systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 12 02:55:31 f0faf6197fbc nginx[2642]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 12 02:55:31 f0faf6197fbc nginx[2642]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 12 02:55:32 f0faf6197fbc systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# exit
exit
[aesteban@localhost ~]$
[aesteban@localhost ~]$ # localhost should now be accessible in browser
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker exec -it f0faf6197fbc systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-12-12 02:55:32 UTC; 1min 57s ago
Process: 2643 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 2642 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 2641 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 2644 (nginx)
CGroup: /system.slice/docker-f0faf6197fbc696796333bfc81f25d537a1aba170b81f2076010222e84284b36.scope/system.slice/nginx.service
├─2644 nginx: master process /usr/sbin/nginx
├─2645 nginx: worker process
├─2646 nginx: worker process
├─2647 nginx: worker process
└─2648 nginx: worker process

Dec 12 02:55:31 f0faf6197fbc systemd[1]: Starting The nginx HTTP and reverse proxy server...
Dec 12 02:55:31 f0faf6197fbc nginx[2642]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Dec 12 02:55:31 f0faf6197fbc nginx[2642]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Dec 12 02:55:32 f0faf6197fbc systemd[1]: Started The nginx HTTP and reverse proxy server.
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker exec -it f0faf6197fbc bash
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# systemctl status postfix
Unit postfix.service could not be found.
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# systemctl status memcached
Unit memcached.service could not be found.
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# # We can install postfix and memcached with yum using the same procedure!
[root@f0faf6197fbc /]#
[root@f0faf6197fbc /]# # Exercise Done :) !!


[ view entry ] ( 1008 views )   |  print article
PostgreSQL Fun 

#Fedora 23
[acool@localhost ~]$ sudo dnf install postgresql-server.x86_64
[acool@localhost ~]$ sudo postgresql-setup --initdb
[acool@localhost ~]$ sudo systemctl start postgresql
[acool@localhost ~]$ sudo su - postgres
-bash-4.3$
-bash-4.3$
-bash-4.3$ createuser --pwprompt acool
Enter password for new role:
Enter it again:
-bash-4.3$
-bash-4.3$
-bash-4.3$ psql
psql (9.4.9)
Type "help" for help.
postgres=#
postgres=#
postgres=#
postgres-# # list databases
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)

postgres-#
postgres-# #list users (roles)
postgres-# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
acool | | {}
postgres | Superuser, Create role, Create DB, Replication | {}

postgres-#
postgres=#
postgres=# ALTER USER acool SUPERUSER;
ALTER ROLE
postgres=# ALTER USER acool CREATEROLE;
ALTER ROLE
postgres=# ALTER USER acool CREATEDB;
ALTER ROLE
postgres=# ALTER USER acool REPLICATION;
ALTER ROLE
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
acool | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}

postgres=#


[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$ cat postgresql-test.sql
CREATE TABLE soccer_teams
(
name varchar(250),
city varchar(250)
);
[acool@localhost ~]$
[acool@localhost ~]$ createdb my-db-test
[acool@localhost ~]$
[acool@localhost ~]$ psql -d my-db-test
psql (9.4.9)
Type "help" for help.

my-db-test=#
my-db-test=#
my-db-test=# \i postgresql-test.sql
CREATE TABLE
my-db-test=#
my-db-test=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+-------
public | soccer_teams | table | acool
(1 row)

my-db-test=#
my-db-test-#
my-db-test-# \d+ soccer_teams
Table "public.soccer_teams"
Column | Type | Modifiers | Storage | Stats target | Description
--------+------------------------+-----------+----------+--------------+-------------
name | character varying(250) | | extended | |
city | character varying(250) | | extended | |

my-db-test=#
my-db-test=# INSERT INTO soccer_teams(name,city) VALUES('LA Galaxy','Los Angeles');
INSERT 0 1
my-db-test=#
my-db-test=# SELECT * FROM soccer_teams;
name | city
-----------+-------------
LA Galaxy | Los Angeles
(1 row)

my-db-test-#
my-db-test-# \q
[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$ psql -V
psql (PostgreSQL) 9.4.9
[acool@localhost ~]$
[acool@localhost ~]$
[acool@localhost ~]$

// other crap
postgres=# #delete user (without roles?, DROP ROLE acool works too?, objects depend on it?)
postgres=# DROP USER acool;
DROP ROLE


[ view entry ] ( 1255 views )   |  print article
AWS Notes 
S3 crap

#list s3 buckets
[acool@acool2 www]$ aws s3 ls

#list files in bucket
[acool@acool2 www]$ aws s3 ls s3://logs-fastly/www/
...
[aesteban@localhost ~]$ aws s3 ls s3://my-db-backup/all_dbs-2019-10-08/ --human-readable --summarize
...


#downloading a list of files from bucket
[acool@acool2 www]$ for i in x.log y.log z.log; do aws s3 cp "s3://logs-fastly/www/$i" .; done


[ view entry ] ( 962 views )   |  print article
Docker: Tasks 101 
So in my opinion containers are more like chroot-in-steroids isolation than fully virtualized environments. That's how it feels to me so far as of 4/11/2018. - Angel


# installing docker (1.10.3)
[aesteban@localhost ~]$ sudo dnf install docker

# start and enable it
[aesteban@localhost ~]$ sudo systemctl start docker
[aesteban@localhost ~]$ sudo systemctl enable docker

# download and run hello-world image
[aesteban@localhost ~]$ sudo docker run hello-world

# download ubuntu image and run it
[aesteban@localhost ~]$ sudo docker run -it ubuntu bash

# listing images
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest e38bc07ac18e 3 hours ago 1.848 kB
docker.io/ubuntu latest f975c5035748 5 weeks ago 112.4 MB
[aesteban@localhost ~]$

# listing all containers
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61d35d591f53 ubuntu "bash" 3 minutes ago Exited (0) 3 minutes ago clever_brahmagupta
1c61c7a6f4d7 hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago tiny_boyd
[aesteban@localhost ~]$

# removing a container (container id)
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker rm 61d35d591f53
61d35d591f53
[aesteban@localhost ~]$

# removing an image (image id)
[aesteban@localhost ~]$ sudo docker rmi f975c5035748
Untagged: docker.io/ubuntu:latest
Untagged: docker.io/ubuntu@sha256:e348fbbea0e0a0e73ab0370de151e7800684445c509d46195aef73e090a49bd6
Deleted: sha256:f975c50357489439eb9145dbfa16bb7cd06c02c31aa4df45c77de4d2baa4e232
Deleted: sha256:0bd983fc698ee9453dd7d21f8572ea1016ec9255346ceabb0f9e173b4348644f
Deleted: sha256:08fe90e1a1644431accc00cc80f519f4628dbf06a653c76800b116d3333d2b6d
Deleted: sha256:5dc5eef2b94edd185b4d39586e7beb385a54b6bac05d165c9d47494492448235
Deleted: sha256:14a40a140881d18382e13b37588b3aa70097bb4f3fb44085bc95663bdc68fe20
Deleted: sha256:a94e0d5a7c404d0e6fa15d8cd4010e69663bd8813b5117fbad71365a73656df9
[aesteban@localhost ~]$

# deleting all containers
[aesteban@localhost ~]$ sudo docker rm $(sudo docker ps -a -q)
1c61c7a6f4d7
[aesteban@localhost ~]$

# deleting all images
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker rmi $(sudo docker images -q)
Untagged: docker.io/hello-world:latest
Untagged: docker.io/hello-world@sha256:6c88d0eedd6a5e71f0affaf150f8b7b286c7bdc679f23d726d12781803e727d3
Deleted: sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96
Deleted: sha256:2b8cbd0846c5aeaa7265323e7cf085779eaf244ccbdd982c4931aef9be0d2faf
[aesteban@localhost ~]$

# installing docker-compose
[aesteban@localhost ~]$ sudo dnf install docker-compose

# saving a modified container (eg. after installing RPMs)
[aesteban@localhost ~]$ sudo docker commit "container-id" "image_name" # repo name

#
[aesteban@localhost ~]$ sudo docker start "container-id"

#
[aesteban@localhost ~]$ sudo docker attach "container-id"

# exporting an image to a file
[aesteban@localhost ~]$ sudo docker save "image-id" | gzip -c image_name.tgz

# importing an image from a file
[aesteban@localhost ~]$ sudo docker load < image_name.tgz

# sample docker-compose.yml
[aesteban@localhost docker-practice]$ cat docker-compose.yml
web:
image: nginx:latest
ports:
- "8888:80"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: cytopia/php-fpm-7.1 # could also be and id (imageid? or containerid? I think the first.)
volumes:
- ./code/:/code/
[aesteban@localhost docker-practice]$

# executing docker-compose.yml
[aesteban@localhost docker-practice]$ sudo docker-compose up
...

# sample docker file
[aesteban@localhost docker-practice]$ cat Dockerfile
FROM miveo/centos-php-fpm:7.1
RUN yum -y install php71u-pecl-memcached.x86_64
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$

# building a docker file
[aesteban@localhost docker-practice]$ sudo docker build -t ent:ent .
...

# verifying build
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ent ent 3d83d51abac9 About a minute ago 429.3 MB
docker.io/nginx latest b175e7467d66 27 hours ago 108.9 MB
docker.io/cytopia/php-fpm-7.1 latest 927ad858fb6a 7 months ago 1.098 GB
docker.io/miveo/centos-php-fpm 7.1 95cae7821f24 15 months ago 287.6 MB
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$ sudo docker run -it 3d83d51abac9 bash
[root@43bb9a049b54 /]#
[root@43bb9a049b54 /]# rpm -qa | grep php | grep memcached
php71u-pecl-memcached-3.0.4-2.ius.centos7.x86_64
[root@43bb9a049b54 /]#
[root@43bb9a049b54 /]#


12/11/2018

#stop container id
[aesteban@localhost docker-practice-2]$ sudo docker stop 2d900ed18675
2d900ed18675
[aesteban@localhost docker-practice-2]$


[ view entry ] ( 1105 views )   |  print article
Virsh: Moving a VM image to a new machine. 
1.- rsync .img image file to new machine.
2.- Output the xml definition file in the source machine:
[acool@oldmachine ~]$sudo virsh dumpxml VMNAME > VMNAME.xml

3.- Adjust path of .img file image in xml file as needed.
4.- On the destination machine define the new VM:
[acool@newmachine ~]$sudo virsh define VMNAME.xml

5.- Start VM.

Big shout-out to dyasny.

[ view entry ] ( 1116 views )   |  print article
Websocket example with PHP 

[acool@localhost websocket-fun]$
[acool@localhost websocket-fun]$ # start web server
[acool@localhost websocket-fun]$ php -S localhost:8080
PHP 5.6.29 Development Server started at Fri Jul 28 22:21:15 2017
Listening on http://localhost:8080
Document root is /home/acool/websocket-fun
Press Ctrl-C to quit.


[acool@localhost websocket-fun]$ 
[acool@localhost websocket-fun]$ # start websocket application
[acool@localhost websocket-fun]$ php -q server.php


Open two browser windows go to localhost:8080 and start chatting with yourself hehe

Window 1



Window 2



server.php
<?php
$host = 'localhost'; //host
$port = '9000'; //port
$null = NULL; //null var

//Create TCP/IP sream socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
//reuseable port
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);

//bind socket to specified host
socket_bind($socket, 0, $port);

//listen to port
socket_listen($socket);

//create & add listning socket to the list
$clients = array($socket);

//start endless loop, so that our script doesn't stop
while (true)
{
//manage multipal connections
$changed = $clients;
//returns the socket resources in $changed array
socket_select($changed, $null, $null, 0, 10);

//check for new socket
if (in_array($socket, $changed))
{
$socket_new = socket_accept($socket); //accpet new socket
$clients[] = $socket_new; //add socket to client array

$header = socket_read($socket_new, 1024); //read data sent by the socket
perform_handshaking($header, $socket_new, $host, $port); //perform websocket handshake

socket_getpeername($socket_new, $ip); //get ip address of connected socket
$response = mask(json_encode(array('type'=>'system', 'message'=>$ip.' connected'))); //prepare json data
send_message($response); //notify all users about new connection

//make room for new socket
$found_socket = array_search($socket, $changed);
unset($changed[$found_socket]);
}

//loop through all connected sockets
foreach ($changed as $changed_socket)
{

//check for any incomming data
while(socket_recv($changed_socket, $buf, 1024, 0) >= 1)
{
$received_text = unmask($buf); //unmask data
$tst_msg = json_decode($received_text); //json decode
$user_name = $tst_msg->name; //sender name
$user_message = $tst_msg->message; //message text
$user_color = $tst_msg->color; //color

//prepare data to be sent to client
$response_text = mask(json_encode(array('type'=>'usermsg', 'name'=>$user_name, 'message'=>$user_message, 'color'=>$user_color)));
send_message($response_text); //send data
break 2; //exist this loop
}

$buf = @socket_read($changed_socket, 1024, PHP_NORMAL_READ);
if ($buf === false)
{ // check disconnected client
// remove client for $clients array
$found_socket = array_search($changed_socket, $clients);
socket_getpeername($changed_socket, $ip);
unset($clients[$found_socket]);

//notify all users about disconnected connection
$response = mask(json_encode(array('type'=>'system', 'message'=>$ip.' disconnected')));
send_message($response);
}
}
}
// close the listening socket
socket_close($socket);

function send_message($msg)
{
global $clients;
foreach($clients as $changed_socket)
{
@socket_write($changed_socket,$msg,strlen($msg));
}
return true;
}


//Unmask incoming framed message
function unmask($text)
{
$length = ord($text[1]) & 127;
if($length == 126) {
$masks = substr($text, 4, 4);
$data = substr($text, 8);
}
elseif($length == 127) {
$masks = substr($text, 10, 4);
$data = substr($text, 14);
}
else {
$masks = substr($text, 2, 4);
$data = substr($text, 6);
}
$text = "";
for ($i = 0; $i < strlen($data); ++$i) {
$text .= $data[$i] ^ $masks[$i%4];
}
return $text;
}

//Encode message for transfer to client.
function mask($text)
{
$b1 = 0x80 | (0x1 & 0x0f);
$length = strlen($text);

if($length <= 125)
$header = pack('CC', $b1, $length);
elseif($length > 125 && $length < 65536)
$header = pack('CCn', $b1, 126, $length);
elseif($length >= 65536)
$header = pack('CCNN', $b1, 127, $length);
return $header.$text;
}

//handshake new client.
function perform_handshaking($receved_header,$client_conn, $host, $port)
{
$headers = array();
$lines = preg_split("/\r\n/", $receved_header);
foreach($lines as $line)
{
$line = chop($line);
if(preg_match('/\A(\S+): (.*)\z/', $line, $matches))
{
$headers[$matches[1]] = $matches[2];
}
}

$secKey = $headers['Sec-WebSocket-Key'];
$secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
//hand shaking header
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"WebSocket-Origin: $host\r\n" .
// "WebSocket-Location: ws://$host:$port/demo/shout.php\r\n".
"Sec-WebSocket-Accept:$secAccept\r\n\r\n";
socket_write($client_conn,$upgrade,strlen($upgrade));
}


index.php
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">

.panel{


margin-right: 3px;
}

.button {
background-color: #4CAF50;
border: none;
color: white;
margin-right: 30%;
margin-left: 30%;
text-decoration: none;
display: block;
font-size: 16px;
cursor: pointer;
width:30%;
height:40px;
margin-top: 5px;

}
input[type=text]{
width:100%;
margin-top:5px;

}


.chat_wrapper {
width: 70%;
height:472px;
margin-right: auto;
margin-left: auto;
background: #3B5998;
border: 1px solid #999999;
padding: 10px;
font: 14px 'lucida grande',tahoma,verdana,arial,sans-serif;
}
.chat_wrapper .message_box {
background: #F7F7F7;
height:350px;
overflow: auto;
padding: 10px 10px 20px 10px;
border: 1px solid #999999;
}
.chat_wrapper input{
//padding: 2px 2px 2px 5px;
}
.system_msg{color: #BDBDBD;font-style: italic;}
.user_name{font-weight:bold;}
.user_message{color: #88B6E0;}

@media only screen and (max-width: 720px) {
/* For mobile phones: */
.chat_wrapper {
width: 95%;
height: 40%;
}


.button{ width:100%;
margin-right:auto;
margin-left:auto;
height:40px;}






}

</style>
</head>
<body>
<?php
$colours = array('007AFF','FF7000','FF7000','15E25F','CFC700','CFC700','CF1100','CF00BE','F00');
$user_colour = array_rand($colours);
?>


<script src="jquery-3.1.1.js"></script>


<script language="javascript" type="text/javascript">
$(document).ready(function(){
//create a new WebSocket object.
var wsUri = "ws://localhost:9000/demo/server.php";
websocket = new WebSocket(wsUri);

websocket.onopen = function(ev) { // connection is open
$('#message_box').append("<div class=\"system_msg\">Connected!</div>"); //notify user
}

$('#send-btn').click(function(){ //use clicks message send button
var mymessage = $('#message').val(); //get message text
var myname = $('#name').val(); //get user name

if(myname == ""){ //empty name?
alert("Enter your Name please!");
return;
}
if(mymessage == ""){ //emtpy message?
alert("Enter Some message Please!");
return;
}
document.getElementById("name").style.visibility = "hidden";

var objDiv = document.getElementById("message_box");
objDiv.scrollTop = objDiv.scrollHeight;
//prepare json data
var msg = {
message: mymessage,
name: myname,
color : '<?php echo $colours[$user_colour]; ?>'
};
//convert and send data to server
websocket.send(JSON.stringify(msg));
});

//#### Message received from server?
websocket.onmessage = function(ev) {
var msg = JSON.parse(ev.data); //PHP sends Json data
var type = msg.type; //message type
var umsg = msg.message; //message text
var uname = msg.name; //user name
var ucolor = msg.color; //color

if(type == 'usermsg')
{
$('#message_box').append("<div><span class=\"user_name\" style=\"color:#"+ucolor+"\">"+uname+"</span> : <span class=\"user_message\">"+umsg+"</span></div>");
}
if(type == 'system')
{
$('#message_box').append("<div class=\"system_msg\">"+umsg+"</div>");
}

$('#message').val(''); //reset text

var objDiv = document.getElementById("message_box");
objDiv.scrollTop = objDiv.scrollHeight;
};

websocket.onerror = function(ev){$('#message_box').append("<div class=\"system_error\">Error Occurred - "+ev.data+"</div>");};
websocket.onclose = function(ev){$('#message_box').append("<div class=\"system_msg\">Connection Closed</div>");};
});




</script>
<div class="chat_wrapper">
<div class="message_box" id="message_box"></div>
<div class="panel">
<input type="text" name="name" id="name" placeholder="Your Name" maxlength="15" />

<input type="text" name="message" id="message" placeholder="Message" maxlength="80"
onkeydown = "if (event.keyCode == 13)document.getElementById('send-btn').click()" />





</div>

<button id="send-btn" class=button>Send</button>

</div>

</body>
</html>


Thanks to sanwebe.com

[ view entry ] ( 1305 views )   |  print article
Ansible: Tasks 101 
More crap will be added to this post sometime in the future, stay tuned if you want...

-Angel

[acool@hydra2 ansible]$ # running a playbook
[acool@hydra2 ansible]$ ansible-playbook dev-hosts-playbook.yml -i dev-hosts.txt
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$# content of dev-hosts.txt
[acool@hydra2 ansible]$ cat dev-hosts.txt
acool2.10-network.net ansible_user=root
userA_2.10-network.net ansible_user=root
userB_2.10-network.net ansible_user=root
userC_2.10-network.net ansible_user=root


[acool@hydra2 ansible]$
[acool@hydra2 ansible]$ # playbook content
[acool@hydra2 ansible]$ cat dev-hosts-playbook.yml
---
- hosts: all
tasks:
- name: Installing EPEL repo.
yum: pkg=epel-release.noarch state=installed
- name : Installing RPMs
yum: pkg={{item}} state=installed
with_items:
- centos-release-scl
- centos-release-scl-rh
- rh-php70
- rh-php70-php-mysqlnd
- rh-php70-php-bcmath
- rh-php70-php-gd
- rh-php70-php-soap
- rh-php70-php-mbstring
- rh-php70-php-fpm
- sclo-php70-php-pecl-memcached
- git
#- rabbitmq-server
- openvpn
- nginx
- composer
- memcached
- npm
- http-parser
- name: Open firewall ports
firewalld:
port: "{{item.port}}/tcp"
zone: public
permanent: true
state: enabled
immediate: yes
with_items:
- { port: '80' }
- { port: '443' }
- name: Starting services.
action: service name={{item}} state=started enabled=yes
with_items:
- nginx
- memcached
- rh-php70-php-fpm
- name: Enabling php 7
copy:
src: /home/acool/ansible/files/dev-vms/rh-php70.sh
dest: /etc/profile.d/rh-php70.sh
- name: Setting SELINUX to permissive.
selinux:
policy: targeted
state: permissive
- name: Copying nginx config files
template:
src: /home/acool/ansible/templates/dev-vms/10-network-net.conf
dest: /etc/nginx/conf.d/10-network-net.conf
- name: Installing gulp globally.
command: npm install gulp -g
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$
[acool@hydra2 ansible]$ # Ad-Hoc commands, -i stands for inventory and -l for limit
[acool@hydra2 ansible]$ ansible all -i dev-hosts.txt -a 'free -h' -l acool2.10-network.net
acool2.10-network.net | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 1.8G 142M 1.5G 8.6M 165M 1.5G
Swap: 2.0G 0B 2.0G

[acool@hydra2 ansible]$
[acool@hydra2 ansible]$



9/1/2018 - more stuff :)
[aesteban@localhost ansible]$ ## adding a new role
[aesteban@localhost ansible]$ ansible-galaxy init roles/dev --offline
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ll roles/
total 16
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 13:04 app
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 11:17 cms
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 11:10 common
drwxrwxr-x 8 aesteban aesteban 4096 Sep 1 13:04 dev
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ls -l
total 32
-rw-rw-r-- 1 aesteban aesteban 62 Sep 1 12:43 app-machines.yml
-rw-rw-r-- 1 aesteban aesteban 62 Sep 1 12:43 cms-machines.yml
-rw-rw-r-- 1 aesteban aesteban 70 Sep 1 16:24 dev-machines.yml
drwxrwxr-x 2 aesteban aesteban 4096 Sep 1 12:48 files
-rw-rw-r-- 1 aesteban aesteban 65 Sep 1 16:19 hosts.txt
drwxrwxr-x 6 aesteban aesteban 4096 Sep 1 13:04 roles
drwxrwxr-x 2 aesteban aesteban 4096 Sep 1 11:10 templates
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible-playbook -i hosts.txt dev-machines.yml --check --limit "dev3.example.com"
...
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ cat hosts.txt
[devmachines]
dev3.example.com

[cmsmachines]

[appmachies]
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible --version
ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.13 (default, May 10 2017, 20:04:36) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$
[aesteban@localhost ansible]$ ansible-playbook -i hosts.txt dev-machines.yml --syntax-check

playbook: dev-machines.yml
[aesteban@localhost ansible]$


[ view entry ] ( 1348 views )   |  print article
LVM - Logical Volume Manager Commands 101 
[aesteban@localhost ~]$  # PVS, VGS and LVS commands
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 fedora lvm2 a-- 237.98g 4.00m
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
fedora 1 3 0 wz--n- 237.98g 4.00m
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home fedora -wi-ao---- 180.17g
root fedora -wi-ao---- 50.00g
swap fedora -wi-ao---- 7.81g
[aesteban@localhost ~]$
[aesteban@localhost ~]$

[aesteban@localhost ~]$ # LVSCAN and LVDISPLAY commands
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo lvscan
ACTIVE '/dev/fedora/swap' [7.81 GiB] inherit
ACTIVE '/dev/fedora/home' [180.17 GiB] inherit
ACTIVE '/dev/fedora/root' [50.00 GiB] inherit
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo lvdisplay /dev/fedora/home
--- Logical volume ---
LV Path /dev/fedora/home
LV Name home
VG Name fedora
LV UUID V6WFgj-PA3l-TYA7-fZ2J-IC0z-3yL4-4Rttov
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-10-19 10:59:08 -0700
LV Status available
# open 1
LV Size 180.17 GiB
Current LE 46123
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

[aesteban@localhost ~]$
[aesteban@localhost ~]$

[aesteban@localhost ~]$ 
[aesteban@localhost ~]$ sudo lvm
lvm>
lvm>
lvm>
lvm> lvscan
ACTIVE '/dev/fedora/swap' [7.81 GiB] inherit
ACTIVE '/dev/fedora/home' [180.17 GiB] inherit
ACTIVE '/dev/fedora/root' [50.00 GiB] inherit
lvm>
lvm>


Physical volumes commands:
pvcreate
pvmove
pvresize
...etc.

Volume groups commands:
vgcreate
vgextend
vgconvert
vgreduce
...etc.

Logical volumes commands:
lvmcache
lvmthin
lvconvert
lvchange
lvextend
lvreduce
lvremove
lvrename
...etc.

See new kid on the block (as of 2017) : SSM, system storage manager.


[ view entry ] ( 1261 views )   |  print article
CentOS 7: Recovering data from RAID 1 member. 
Scenario: We have a RAID 1 member, the other members are missing. We will re-assemble the MD array and mount it to recover the data.


[acool@localhost sdX]$ #connect surviving hd in any available sata port,
[acool@localhost sdX]$ #copy partition from surviving HD (sdd)
[acool@localhost sdX]$ sudo dd if=/dev/sdd1 of=./sdX1.img status=progress
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ #set image as loop device
[acool@localhost sdX]$ sudo losetup /dev/loop200 sdX1.img
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ #examine raid1 member
[acool@localhost sdX]$ sudo mdadm --examine /dev/loop200
/dev/loop200:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x1
Array UUID : 626c8ef2:f11c73eb:d3fb3366:bbf7a200
Name : localhost.localdomain:root (local to host localhost.localdomain)
Creation Time : Thu Jan 19 10:05:17 2017
Raid Level : raid1
Raid Devices : 3

Avail Dev Size : 25165824 (12.00 GiB 12.88 GB)
Array Size : 12582912 (12.00 GiB 12.88 GB)
Data Offset : 16384 sectors
Super Offset : 8 sectors
Unused Space : before=16296 sectors, after=0 sectors
State : clean
Device UUID : 626c8ef2:f11c73eb:d3fb3366:bbf7ae4b

Internal Bitmap : 8 sectors from superblock
Update Time : Sat Jan 28 23:33:56 2017
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : b33f59c9 - correct
Events : 1540


Device Role : Active device 0
Array State : AAA ('A' == active, '.' == missing, 'R' == replacing)
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ # reassemble array (I had to change UUID)
[acool@localhost sdX]$ sudo mdadm --assemble --run --force /dev/md200 --update=uuid --uuid=626c8ef2:f11c73eb:d3fb3366:bbf7a200 /dev/loop200
mdadm: /dev/md200 has been started with 1 drive (out of 3).
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ sudo mdadm --detail /dev/md200
/dev/md200:
Version : 1.2
Creation Time : Thu Jan 19 10:05:17 2017
Raid Level : raid1
Array Size : 12582912 (12.00 GiB 12.88 GB)
Used Dev Size : 12582912 (12.00 GiB 12.88 GB)
Raid Devices : 3
Total Devices : 1
Persistence : Superblock is persistent

Intent Bitmap : Internal

Update Time : Sat Jan 28 23:33:56 2017
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0

Name : localhost.localdomain:root (local to host localhost.localdomain)
UUID : 626c8ef2:f11c73eb:d3fb3366:bbf7a200
Events : 1540

Number Major Minor RaidDevice State
0 7 200 0 active sync /dev/loop200
- 0 0 1 removed
- 0 0 2 removed
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ # mount md device in order to access content
[acool@localhost sdX]$ sudo mount /dev/md200 sdX1_mount/
[acool@localhost sdX]$
[acool@localhost sdX]$
[acool@localhost sdX]$ # you can now ls sdX1_mount directory to see contents
[acool@localhost sdX]$
[acool@localhost sdX]$ #also, see partscan option in losetup


[ view entry ] ( 1202 views )   |  print article
FDISK - GDISK: List of known partition types 
FDISK
[aesteban@localhost ~]$ 
[aesteban@localhost ~]$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.28.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT

Command (m for help): quit

[aesteban@localhost ~]$
[aesteban@localhost ~]$


GDISK
[aesteban@localhost ~]$ 
[aesteban@localhost ~]$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): l
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
3000 ONIE boot 3001 ONIE config 3900 Plan 9
4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata
4202 Windows Storage Spac 7501 IBM GPFS 7f00 ChromeOS kernel
7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap
8300 Linux filesystem 8301 Linux reserved 8302 Linux /home
8303 Linux x86 root (/) 8304 Linux x86-64 root (/ 8305 Linux ARM64 root (/)
8306 Linux /srv 8307 Linux ARM32 root (/) 8400 Intel Rapid Start
8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
a585 Midnight BSD Vinum a600 OpenBSD disklabel a800 Apple UFS
a901 NetBSD swap a902 NetBSD FFS a903 NetBSD LFS
a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID
ab00 Recovery HD af00 Apple HFS/HFS+ af01 Apple RAID
af02 Apple RAID offline af03 Apple label af04 AppleTV recovery
af05 Apple Core Storage bc00 Acronis Secure Zone be00 Solaris boot
bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
Press the <Enter> key to see more codes:
bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition
f800 Ceph OSD f801 Ceph dm-crypt OSD f802 Ceph journal
f803 Ceph dm-crypt journa f804 Ceph disk in creatio f805 Ceph dm-crypt disk i
fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p
fd00 Linux RAID

Command (? for help): quit
[aesteban@localhost ~]$
[aesteban@localhost ~]$


[ view entry ] ( 1603 views )   |  print article

<<First <Back | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Next> Last>>


2024 By Angel Cool