42n4

CENTOS4VAGRANT

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