Skip to content

Commit

Permalink
many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsiryk committed Apr 5, 2017
1 parent a25c3f0 commit afd1494
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 79 deletions.
26 changes: 14 additions & 12 deletions AWS/available_zones.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
Available zones
===============

# Actual information on http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
Actual information on http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html

us-east-1 US East (N. Virginia)
us-west-2 US West (Oregon)
us-west-1 US West (N. California)
eu-west-1 EU (Ireland)
eu-central-1 EU (Frankfurt)
ap-southeast-1 Asia Pacific (Singapore)
ap-northeast-1 Asia Pacific (Tokyo)
ap-southeast-2 Asia Pacific (Sydney)
ap-northeast-2 Asia Pacific (Seoul)
ap-south-1 Asia Pacific (Mumbai)
sa-east-1 South America (São Paulo)
============== ============== ===============
us-east-1 US East (N. Virginia)
us-west-2 US West (Oregon)
us-west-1 US West (N. California)
eu-west-1 EU (Ireland)
eu-central-1 EU (Frankfurt)
ap-southeast-1 Asia Pacific (Singapore)
ap-northeast-1 Asia Pacific (Tokyo)
ap-southeast-2 Asia Pacific (Sydney)
ap-northeast-2 Asia Pacific (Seoul)
ap-south-1 Asia Pacific (Mumbai)
sa-east-1 South America (São Paulo)
============== ============== ===============
38 changes: 22 additions & 16 deletions AWS/cli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CLI
===

~/.aws/config
``~/.aws/config``::

[default]
output = json
Expand All @@ -12,38 +12,44 @@ CLI
output = json
region = eu-west-1 # important!

~/.aws/credentials

``~/.aws/credentials``::

[default]
[default]
aws_access_key_id = <key_id>
aws_secret_access_key = <access_key>

[<username>]
aws_access_key_id = <key_id>
aws_secret_access_key = <access_key>

########################################

# for run as username:
aws --profile <username> <some_aws_command>


# controll output

aws iam get-user --query 'User.Arn' --output text
Run aws command as user::

aws --profile <username> <some_aws_command>

aws iam list-users --query 'Users[0]'

aws iam list-users --query 'Users[*].{name:UserName, arn:Arn}'
Controll output::

aws iam list-users --query 'Users[*].[UserName, Arn]' # output without keys
aws iam get-user --query 'User.Arn' --output text
aws iam list-users --query 'Users[0]'
aws iam list-users --query 'Users[*].{name:UserName, arn:Arn}'
# output without keys
aws iam list-users --query 'Users[*].[UserName, Arn]'
# output where UserName==den
aws iam list-users --query 'Users[?UserName==`den`].[UserName, Arn]'
aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,InstanceId:Attachments[0].InstanceId,AZ:AvailabilityZone,Size:Size}'

aws iam list-users --query 'Users[?UserName==`den`].[UserName, Arn]' # output where UserName==den

aws ec2 describe-volumes --query 'Volumes[*].{ID:VolumeId,InstanceId:Attachments[0].InstanceId,AZ:AvailabilityZone,Size:Size}'

S3
--

::

aws --profile <user> s3 ls s3://<backet> --recursive --human-readable

# S3

aws --profile <user> s3 ls s3://<backet> --recursive --human-readable

69 changes: 69 additions & 0 deletions AWS/deploy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
=======================
Deploy without downtime
=======================

``deploy.sh``::


# Define some global variables
export AUTO_SCALING_GROUP_NAME="asg"
export SCALING_POLICY="LaunchOne"
export ELB_NAME="load-balancer-new-site"

date >> deploy.log

# Returns the number of instances currently in the AutoScaling group
function getNumInstancesInAutoScalingGroup() {
local num=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "$AUTO_SCALING_GROUP_NAME" --query "length(AutoScalingGroups[0].Instances)")
local __resultvar=$1
eval $__resultvar=$num
}

# Returns the number of healthy instances currently in the ELB
function getNumHealthyInstancesInELB() {
local num=$(aws elb describe-instance-health --load-balancer-name "$ELB_NAME" --query "length(InstanceStates[?State=='InService'])")
local __resultvar=$1
eval $__resultvar=$num
}

# Get the current number of desired instances to reset later
export existingNumDesiredInstances=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "$AUTO_SCALING_GROUP_NAME" --query "AutoScalingGroups[0].DesiredCapacity")

# Determine the number of instances we expect to have online
getNumInstancesInAutoScalingGroup numInstances
numInstancesExpected=$(expr $numInstances \* 2)
echo "Expecting to have $numInstancesExpected instance(s) online."

echo "Will launch $numInstances Instance(s)..."
for i in `seq 1 $numInstances`;
do
echo "Launching instance..."
aws autoscaling execute-policy --no-honor-cooldown --auto-scaling-group-name "$AUTO_SCALING_GROUP_NAME" --policy-name "$SCALING_POLICY"
sleep 5s
done

# Wait for the number of instances to increase
getNumInstancesInAutoScalingGroup newNumInstances
until [[ "$newNumInstances" == "$numInstancesExpected" ]];
do
echo "Only $newNumInstances instance(s) online in $AUTO_SCALING_GROUP_NAME, waiting for $numInstancesExpected..."
sleep 10s
getNumInstancesInAutoScalingGroup newNumInstances
done

# Wait for the ELB to determine the instances are healthy
echo "All instances online, waiting for the Load Balancer to put them In Service..."
getNumHealthyInstancesInELB numHealthyInstances
until [[ "$numHealthyInstances" == "$numInstancesExpected" ]];
do
echo "Only $numHealthyInstances instance(s) In Service in $ELB_NAME, waiting for $numInstancesExpected..."
sleep 10s
getNumHealthyInstancesInELB numHealthyInstances
done

# Update the desired capacity back to it's previous value
echo "Resetting Desired Instances to $existingNumDesiredInstances"
aws autoscaling update-auto-scaling-group --auto-scaling-group-name "$AUTO_SCALING_GROUP_NAME" --desired-capacity $existingNumDesiredInstances

# Success!
echo "Deployment complete!"
40 changes: 23 additions & 17 deletions AWS/iam.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
IAM
===

# attach exist managed policy to user
aws iam attach-user-policy --policy-arn arn:aws:iam::aws:policy/<value> --user-name <value>

# create new managed policy
aws iam create-policy --policy-name <value> --policy-document file://<value>

# get user ID
aws iam get-user --query 'User.Arn' --output text
aws iam get-user | awk '/arn:aws:/{print $2}'
aws iam list-users --query 'Users[?UserName==`den`].[Arn]' --output text

aws iam create-group --group-name <value> # create group
list-groups # show groups
attach-group-policy --group-name <value> --policy-arn <policy_arn> # attach policy to group (example arn - arn:aws:iam::aws:policy/AdministratorAccess)
list-attached-group-policies --group-name <value> # show attached policies
remove-user-from-group --user-name <value> --group-name <value> # delete user from group
delete-group --group-name <value> # delete group (first remove the users in the group, delete inline policies and detach any managed policies)
Attach exist managed policy to user::

aws iam attach-user-policy --policy-arn arn:aws:iam::aws:policy/<value> --user-name <value>


Create new managed policy::

aws iam create-policy --policy-name <value> --policy-document file://<value>


Get user ID::

aws iam get-user --query 'User.Arn' --output text
aws iam get-user | awk '/arn:aws:/{print $2}'
aws iam list-users --query 'Users[?UserName==`den`].[Arn]' --output text


aws iam create-group --group-name <value> # create group
list-groups # show groups
attach-group-policy --group-name <value> --policy-arn <policy_arn> # attach policy to group (example arn - arn:aws:iam::aws:policy/AdministratorAccess)
list-attached-group-policies --group-name <value> # show attached policies
remove-user-from-group --user-name <value> --group-name <value> # delete user from group
delete-group --group-name <value> # delete group (first remove the users in the group, delete inline policies and detach any managed policies)
6 changes: 2 additions & 4 deletions AWS/s3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
S3
==

# link to the file:
https://<aws_region>.amazonaws.com/<backet_name>/<file_name>
Example:
https://s3-eu-west-1.amazonaws.com/my-super-bucket/linux-155549_960_720.png
Link to the file looks like: ``https://<aws_region>.amazonaws.com/<backet_name>/<file_name>``.
Example: ``https://s3-eu-west-1.amazonaws.com/my-super-bucket/linux-155549_960_720.png``


7 changes: 5 additions & 2 deletions Elastic/elk_stack_ubuntu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ Generate certificates

**Letsencrypt**::

sudo apt install letsencrypt
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot


# Replace with your webroot and hostname
letsencrypt certonly --webroot -w /var/www/html -d elk.company.com
Expand All @@ -83,7 +86,7 @@ Add CRON tasks to renew automatically Letsencrypt certs::
sudo crontab -e

# Check or renew certs twice per day
0 12,18 * * * letsencrypt renew
0 12,18 * * * certbot renew --post-hook "systemctl reload nginx"



Expand Down
29 changes: 29 additions & 0 deletions MacOS/virtual_mac_machine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Mac OS VM
=========


Important repo https://github.com/kholia/OSX-KVM


Run Sierra on qemu-kvm
----------------------

Expand Down Expand Up @@ -118,8 +122,33 @@ Add next file to Sierra HD ``/Volumes/<Sierra_HD>/Extra/org.chameleon.boot.plist
<string>1024x768x32</string>
</dict>
</plist>


6. Allow usb-tablet device

- download driver from http://philjordan.eu/osx-virt/#usb-tablet and install it on your virtual Mac
- add in virt-manager usb-tablet device and remove usb-mouse


7. Add vmware svga driver

- download and install https://sourceforge.net/projects/vmsvga2 on your Mac
- add the following to ``/Extra/org.chameleon.Boot.plist``::

<key>Kernel Flags</key>
<string>vmw_options_fb=0x06</string>


- add ``-vga vmware`` to QEMU parameters.


Install Mac OS Sierra on VMWare
-------------------------------

1. Download and run script to unlock your VMWare for run Mac OS https://github.com/DrDonk/unlocker . P.S. Read readme in repo.

2.


Run Sierra on VirtualBox
------------------------
Expand Down
9 changes: 9 additions & 0 deletions SWAP.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ SWAP in file
4. Add new SWAP to fstab (auto mount when system start)::

sudo echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab


5. Optional. We will use the command sysctl to change settings dedicated to the Linux virtual memory manager ``vm.swappiness``. This setting tells the Linux kernel/VM handler how likely it should be to use VM. It is a percent value, between 0 & 100. If you set this value to 0, the VM handler will be least likely to use any available swap space, and should use all available system memory first. If you set it to 100, the VM handler will be most likely to use available swap space and will try to leave a greater portion of system memory free for use. A value of 30% should be a happy medium between swapping and system memory::

sudo sysctl -w vm.swappiness=30



Automated swapfile create
Expand All @@ -63,4 +69,7 @@ Run as root::
# Add new SWAP to fstab (auto mount when system start)
sudo echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab

# Tweak system swap usage value
sudo sysctl -w vm.swappiness=30


65 changes: 38 additions & 27 deletions git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,54 @@ Git

https://git-scm.com/book/ru/v2

git push origin serverfix // удаленный сервер/ветка
git push origin serverfix:awesomebranch // локальная ветка serverfix отправится в ветку awesomebranch удалённого проекта.
::

git remote // Чтобы просмотреть, какие удалённые серверы у вас уже настроены, следует выполнить команду
-v // Чтобы посмотреть, какому URL соответствует сокращённое имя в Git
add <name>
git push origin serverfix # remote server/branch
git push origin serverfix:awesomebranch # local branch serverfix will transfer to branch awesomebranch of remote project

###
git remote add origin https://github.com/johnsmith/test.git
###
git remote # Show configured remote servers
-v # Show match URL/name
add <name>

git push origin --delete serverfix // удаляет ветку на сервере

git fetch [имя удал. сервера] // забирает с сервера, но не сливает с локальными изминениями
::

git branch // показывает список веток
-v // покажет еще и последние коммиты на ветках
--merged/--no-merged // покажет слитые/не слитые ветки с текущей
git remote add origin https://github.com/johnsmith/test.git

git branch testing // новая ветка (без переключения на нее)
-d hotfix // удаляет ненужную ветку
-D testing // удаляет ненужную ветку даже если она не слита

git checkout testing // переключение на ветку (HEAD переместится на ветку testing)
-b iss53 // создание и переключение на ветку
::

git merge hotfix // сольет текущуе ветку с hotfix
git push origin --delete serverfix # delete branch on server

git fetch [имя удал. сервера] # pull from server, but not merge with local changes

git branch # show all branches
-v # also show last commits on branches
--merged/--no-merged # show merged/unmerged branches with current

git log --oneline --decorate --graph --all // показывает историю коммитов и указатели веток, и ветвления истории проекта
git branch testing # new branch, without switching
-d hotfix # delete unused branch
-D testing # delete unused branch also if not merged

HEAD указывает на текущую ветку
git checkout testing # switching to branch testing (HEAD transfer to branch testing)
-b iss53 # create and switching branch

git merge hotfix # merge current branch with hotfix


Shows commit history and branch indexes and branch history::

git log --oneline --decorate --graph --all


**HEAD** indicates on current branch


Command aliases::

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'

// алиасы для комманд
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.unstage 'reset HEAD --'

0 comments on commit afd1494

Please sign in to comment.