Advertisement
42n4

UBUNTU4VAGRANT

Apr 11th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.16 KB | None | 0 0
  1. ##############################################################################################
  2. #Uruchamiam Cepha na 3 maszynach vagrant Ubuntu
  3. #TUTAJ JEST GŁÓWNY SKRYPT
  4. #GŁÓWNY SKRYPT
  5. #curl https://pastebin.com/raw/2y9B4KhW | sed 's/\r//g' > VAskryptglownyUbuntu.txt
  6. #DALEJ PASTUJ LINIE z PLIKU GŁÓWNEGO skryptglowny.txt
  7. #lub z podanego powyżej adresu pastebin oraz uruchamiaj FUNKCJE
  8. #vim VAskryptglownyUbuntu.txt #paste sth
  9.  
  10. ##############################################################################################
  11. #FUNKCJE DO TEGO SKRYPTU W OSOBNYM SKRYPCIE
  12. curl https://pastebin.com/raw/anHdueta | sed 's/\r//g' > VAskryptfunkcje.sh
  13. sh VAskryptfunkcje.sh
  14.  
  15. ##############################################################################################
  16. #TWORZENIE MASZYNY VM Z LINII KOMENDY
  17. export VM="Ubuntu1610"
  18. export VBOS="Ubuntu_64"
  19. export VBFOLDER="/mnt/dc/VBox/"
  20. export ISO4VM="/mnt/dc/IMAGES/ubuntu-16.10-server-amd64.iso"
  21. VACreateVM $VM $VBOS $VBFOLDER $ISO4VM
  22.  
  23. ##############################################################################################
  24. #INSTALACJA SYSTEMU Z ISO NA VM z openssh-server zaznaczonym
  25. VBoxManage startvm $VM # --type headless
  26. #VBoxHeadless --startvm $VM &
  27. #WPISAĆ DO MASZYNY VM
  28. #zaloguj się na vagrant konto, jakie załozyłeś podczas instalacji, zmień hasło roota
  29. #passwd
  30. #sed -i 's/prohibit-password/yes/g' /etc/ssh/sshd_config
  31. #systemctl restart sshd
  32.  
  33. ##############################################################################################
  34. #BEZPIECZNE WYŁĄCZENIE MASZYNY
  35. VBoxManage controlvm $VM acpipowerbutton
  36. sleep 20
  37. VAChangeVMStorage $VM
  38. VBoxManage startvm $VM --type headless
  39. #ssh -p 2222 root@127.0.0.1
  40. sleep 30
  41. curl https://pastebin.com/raw/anHdueta | sed 's/\r//g' > VAskryptfunkcje.sh
  42. sh VAskryptfunkcje.sh
  43. sed -i '/:2222/d'  ~/.ssh/known_hosts
  44. scp -rp -P 2222 /usr/local/bin/va_* root@127.0.0.1:/usr/local/bin &&\
  45. ssh -p 2222 root@127.0.0.1 /usr/local/bin/va_update_vmubuntu
  46.  
  47. #DODAWANIE I USUWANIE dzielonych katalogów (vagrant ma swoje własne katalogi):
  48. #VBoxManage sharedfolder add $VM --name SHARED --hostpath /mnt/dc/SHARED --automount
  49. #VBoxManage sharedfolder remove $VM --name SHARED
  50. #To mount it on the guest:
  51. #sudo mount -t vboxsf -o uid=$UID SHARED /mnt/dc/SHARED
  52. #SNAPSHOTY BACKUPY
  53. #VBoxManage snapshot $VM take shot`date +%y%m%d`
  54. #VBoxManage snapshot $VM restore shot`date +%y%m%d`
  55. #KLONOWANIE MASZYNY
  56. #VBoxManage export $VM --output vmClone`date +%y%m%d`.ovf --options manifest,nomacs
  57. #macaddr=$(echo `uname -a`|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/08:00:27:\3:\4:\5/')
  58. #VBoxManage modifyvm $VM --macaddressX $macaddr
  59. #domyślnie zmienia mac i nazwy
  60. #VBoxManage import vmClone`date +%y%m%d`.ovf
  61.  
  62. ##############################################################################################
  63. #TWORZYMY VAGRANT MASZYNĘ Z VIRTUALBOX MASZYNY
  64. VBoxManage controlvm $VM  acpipowerbutton
  65. sleep 20
  66. VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --medium none
  67. [ -e ${VBFOLDER}/v${VM}.box ] && rm ${VBFOLDER}/v${VM}.box
  68. vagrant box remove v${VM} --force
  69. vagrant package --output ${VBFOLDER}/v${VM}.box --base $VM
  70. vagrant box add v${VM} ${VBFOLDER}/v${VM}.box --force
  71. #DODAJ ${VBFOLDER}/v${VM}.box do zbioru obrazów atlas
  72. #https://atlas.hashicorp.com/vagrant
  73.  
  74. ##############################################################################################
  75. cd
  76. vagrant box list
  77. rm -rf v${VM}
  78. [ ! -d v${VM} ] && mkdir v${VM}
  79. cd v${VM}
  80. #vagrant init v${VM}
  81. #dla trzech maszyn, a nie dla jednej
  82. #https://www.vagrantup.com/docs/provisioning/shell.html
  83. #sed -i 's/^end/\ \ config.vm.provision "shell", inline: "echo server1 > \/etc\/hostname"\n end/g' Vagrantfile
  84. cp /usr/local/bin/Vagrantfile.3Ubuntu Vagrantfile
  85. vagrant up --provision
  86. vagrant ssh server1
  87.  
  88. #w przypadku gdy na koncie vagrant zmienił się publiczny klucz vagranta w .ssh/authorized_keys
  89. #należy logować się po haśle, zmienić Vagrantfile od razu po vagrant init nazwa_boxa
  90. #https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html
  91. #sed -i 's/^end/\ \ config.ssh.password="vagrant"\n end/g' Vagrantfile
  92. #jeśli nie wstawimy config.ssh.password jak wyżej, to pastujemy klucz insecure vagranta do maszyny na konto vagrant:
  93. #wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O ~/.ssh/authorized_keys
  94. #chmod 700 ~/.ssh
  95. #chmod 600 ~/.ssh/authorized_keys
  96. #chown -R vagrant:vagrant ~/.ssh
  97. #po tym: vagrant halt && vagrant up && vagrant ssh
  98. #http://www.thisprogrammingthing.com/2016/fixing-vagrant-connection-error/
  99.  
  100. #usuwanie maszyn vagranta z nazwami na v* z VirtualBoxa
  101. cd $VBFOLDER && for i in v${VM}*; do VBoxManage controlvm $i poweroff; VBoxManage unregistervm --delete $i; done && cd
  102.  
  103. #https://atlas.hashicorp.com/boxes/search
  104. #https://github.com/Zuehlke/linux-developer-vm
  105.  
  106.  
  107. #arp-scan 192.168.2.0/24 --interface=enp0s31f6
  108. #vagrantfile for public ip http://ix.io/q2t, dla dwóch serwerów http://ix.io/q2y, dla trzech serwerów http://ix.io/qdE
  109.  
  110. #https://groups.google.com/forum/#!topic/vagrant-up/thrR2PRodQE
  111. #https://programmaticponderings.com/2014/12/14/installing-puppet-master-and-agents-on-multiple-vm-using-vagrant-and-virtualbox/
  112.  
  113.  
  114. ##################################################################################
  115. ##################################################################################
  116. ### CEPH #########################################################################
  117. ##################################################################################
  118. ##################################################################################
  119.  
  120. #http://www.virtualtothecore.com/en/adventures-ceph-storage-part-1-introduction/
  121. #https://blog.zhaw.ch/icclab/tag/ceph/
  122. #https://wiki.centos.org/SpecialInterestGroup/Storage/ceph-Quickstart
  123. #http://linoxide.com/storage/setup-red-hat-ceph-storage-centos-7-0/
  124. #http://karan-mj.blogspot.com/2013/12/what-is-ceph-ceph-is-open-source.html
  125. #https://www.reddit.com/r/DataHoarder/comments/4gzpxi/why_is_ceph_so_rare_for_home_use_even_among
  126. #http://palmerville.github.io/2016/04/30/single-node-ceph-install.html
  127. [ ! -d ceph-deploy ] && mkdir ceph-deploy
  128. cd ceph-deploy/
  129. #INICJALIZACJA CEPHA
  130. va_ceph_init
  131. #TESTOWANIE CEPHA
  132. #object storage gateway
  133. ceph-deploy rgw create server1 server2 server3
  134. #cephfs
  135. ceph-deploy mds create server1 server2 server3
  136. ceph -s #ceph status
  137. ceph osd tree
  138. ceph mon_status
  139. ceph osd pool create mypool 1
  140. ceph osd lspools
  141. ceph df
  142. echo "test data" > testfile
  143. rados put -p mypool testfile testfile
  144. rados -p mypool ls
  145. rados -p mypool setomapval testfile mykey myvalue
  146. rados -p mypool getomapval testfile mykey
  147. rados get -p mypool testfile testfile2
  148. md5sum testfile testfile2
  149. ceph osd pool create cephfs_data 128
  150. ceph osd pool create cephfs_metadata 128
  151. ceph fs new cephfs cephfs_metadata cephfs_data
  152. [ ! -d /mnt/mycephfs ] && mkdir /mnt/mycephfs
  153. mount -t ceph server1:6789:/ /mnt/mycephfs -o name=admin,secret=`cat /etc/ceph/ceph.client.admin.keyring | grep key | cut -f 2 | sed 's/key = //g'`
  154.  
  155. #test wydajności dysku ceph, gdzie -s rozmiar pliku MB, -r ilość ram MB (domyślne wartości: 8192 i dostępna pamięć)
  156. free && sync && echo 3 > /proc/sys/vm/drop_caches && free
  157. bonnie++ -s 2048 -r 1024 -u root -d /mnt/mycephfs -m BenchClient
  158.  
  159. #https://wiki.mikejung.biz/Sysbench#Install_Sysbench_on_CentOS_7
  160. #http://www.servernoobs.com/avoiding-cpu-speed-scaling-in-modern-linux-distributions-running-cpu-at-full-speed-tips/
  161. #for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
  162. #do [ -f $CPUFREQ ] || continue;
  163. #  echo -n performance > $CPUFREQ;
  164. #done          
  165. grep -E '^model name|^cpu MHz' /proc/cpuinfo  
  166. sysbench --test=cpu --cpu-max-prime=10000 --num-threads=4 run
  167. #sysbench --test=fileio --file-test-mode=rndwr run
  168. #sysbench --test=fileio help
  169. #sysbench --test=fileio --file-test-mode=seqwr --num-threads=1 --file-block-size=4096 run
  170. #sysbench --test=fileio --file-test-mode=rndwr --num-threads=1 --file-block-size=4096 run  
  171. #http://cromwell-intl.com/linux/performance-tuning/disks.html
  172. echo 3 | sudo tee /proc/sys/vm/drop_caches && sudo sync
  173. iperf -s #pomiar przepustowości sieci, uruchamiamy na jednym serwerze np. server1
  174. iperf -c server1 -i1 -t 10  #na drugim serwerze mierzymy
  175.  
  176. ##################################################################################
  177. ##################################################################################
  178. ## DOCKER ########################################################################
  179. ##################################################################################
  180. ##################################################################################
  181. #https://docs.docker.com/machine/drivers/virtualbox/
  182. systemctl enable docker
  183. systemctl start docker
  184. usermod -aG docker guest
  185. cat << 'EOF' >  test.S
  186. #include <sys/syscall.h>
  187. .text
  188. .globl _start
  189. .type _start, @function
  190. _start:
  191.         movq $SYS_exit, %rax
  192.         movq $0, %rdi
  193.         syscall
  194. EOF
  195. gcc -nostdlib test.S && { ./a.out; echo $?; }
  196.  
  197. wget https://raw.githubusercontent.com/docker-library/hello-world/master/hello.c
  198. gcc -static hello.c -o hello
  199.  
  200.  
  201. #http://blog.bjdean.id.au/2015/08/docker-from-scratch/
  202. curl http://ix.io/pOz | sed 's/\r//g' > witaj.c
  203. echo -e "witaj: witaj.c" > makefile
  204. echo -e "\t gcc -static -o witaj witaj.c" >> makefile
  205. echo -e "docker: witaj" >> makefile
  206. echo -e "\t docker build --rm -t dockwitaj ." >> makefile
  207. cat << 'EOF' > Dockerfile
  208. FROM scratch
  209. COPY witaj /
  210. CMD ["/witaj"]
  211. EOF
  212. #gcc -static witaj.c -o witaj
  213. #docker build --rm -t dockwitaj .
  214. make docker
  215. #docker run --rm=true dockwitaj
  216. #/etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet systemd.legacy_systemd_cgroup_controller=yes"
  217. docker run --rm=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro dockwitaj
  218. docker run --rm=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro --env="BJDTEST=i żegna!"  dockwitaj
  219.  
  220.  
  221. #https://www.iron.io/microcontainers-tiny-portable-containers/
  222.  
  223. #https://github.com/rocker-org/rocker
  224. docker run --rm=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro -ti rocker/r-base
  225.  
  226. #https://github.com/niallo/docker-freeciv
  227. #http://blog.xebia.com/create-the-smallest-possible-docker-container/
  228.  
  229. #https://www.linux.com/learn/how-use-docker-machine-create-swarm-cluster
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement