Advertisement
42n4

FUNKCJE4VAGRANTDOCKER

Apr 10th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 34.83 KB | None | 0 0
  1. ###############################################################################################
  2. #Uruchamiam Cepha na 3 maszynach vagrant
  3. #https://github.com/pwasiewi/packer-proxmoxbeta
  4. #https://github.com/pwasiewi/packer-ubuntu
  5. ###############################################################################################
  6. #TUTAJ JEST SKRYPT Z FUNKCJAMI DO GŁÓWNEGO SKRYPTU
  7. #curl https://pastebin.com/raw/FMxYTYhF | sed 's/\r//g' > VAskryptglownyCentos.txt
  8. #curl https://pastebin.com/raw/2y9B4KhW | sed 's/\r//g' > VAskryptglownyUbuntu.txt
  9. #curl https://pastebin.com/raw/GQF1MwtB | sed 's/\r//g' > VAskryptglownyMiniUbuntu.txt
  10. #curl https://pastebin.com/raw/Ey6qHu37 | sed 's/\r//g' > VAskryptglownyProxmox.txt
  11. #curl https://pastebin.com/raw/xYGzrccq | sed 's/\r//g' > VAdocker4all.txt
  12. ###############################################################################################
  13. #FUNKCJE DO TEGO SKRYPTU W OSOBNYM SKRYPCIE
  14. #curl https://pastebin.com/raw/anHdueta | sed 's/\r//g' > VAskryptfunkcje.sh
  15. #sh VAskryptfunkcje.sh
  16.  
  17. ###############################################################################################
  18. #ssh nie pyta o klucze
  19. [ ! -d ~/.ssh ] && mkdir ~/.ssh
  20. echo StrictHostKeyChecking no >> ~/.ssh/config
  21. ###############################################################################################
  22. #SKRYPT TWORZY MASZYNĘ WIRTUALNĄ
  23. #CreateVM <OS_NAME> <VBOX_OS> <VB_DIR> <VM_ISO_IMAGE>
  24. #CreateVM "Centos73" "RedHat_64" "/mnt/dc/VBox/" "/mnt/dc/IMAGES/CentOS-7-x86_64-Minimal-1611.iso"
  25. cat << 'EOF' > /usr/local/bin/VACreateVM
  26. VM=$1
  27. VBOS=$2
  28. VBFOLDER=$3
  29. ISO4VM=$4
  30. DISK_SIZE=$5
  31. [ -z $DISK_SIZE ] && DISK_SIZE=8192
  32. [ ! -d $VBFOLDER ] && mkdir -p $VBFOLDER
  33. cd $VBFOLDER
  34. VMFOLDER="${VBFOLDER}/${VM}"
  35. echo VBoxManage controlvm $VM poweroff
  36. VBoxManage controlvm $VM poweroff
  37. sleep 5
  38. echo VBoxManage unregistervm --delete $VM
  39. VBoxManage unregistervm --delete $VM
  40. echo VBoxManage createvm --name $VM --register
  41. VBoxManage createvm --name $VM --register
  42. echo VBoxManage createhd --filename ${VMFOLDER}/${VM}_1.vdi --size $DISK_SIZE
  43. VBoxManage createhd --filename ${VMFOLDER}/${VM}_1.vdi --size $DISK_SIZE
  44. echo VBoxManage createhd --filename ${VMFOLDER}/${VM}_2.vdi --size 8192
  45. VBoxManage createhd --filename ${VMFOLDER}/${VM}_2.vdi --size 8192
  46. #VBoxManage list ostypes
  47. echo VBoxManage modifyvm $VM --ostype $VBOS
  48. VBoxManage modifyvm $VM --ostype $VBOS
  49. echo VBoxManage modifyvm $VM --cpus 2 --memory 2048 --acpi on --x2apic on --vram 128 --accelerate3d on --graphicscontroller vboxvga
  50. VBoxManage modifyvm $VM --cpus 2 --memory 2048 --acpi on --x2apic on --vram 128 --accelerate3d on --graphicscontroller vboxvga
  51. #VBoxManage modifyvm $VM --audio alsa --audiocontroller ac97
  52. echo VBoxManage storagectl $VM --name IDE --add ide --controller PIIX4 --bootable on
  53. VBoxManage storagectl $VM --name IDE --add ide --controller PIIX4 --bootable on
  54. echo VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --tempeject on --medium $ISO4VM
  55. VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --tempeject on --medium $ISO4VM
  56. echo VBoxManage storagectl $VM --name SATA --add sata --controller IntelAhci --bootable on
  57. VBoxManage storagectl $VM --name SATA --add sata --controller IntelAhci --bootable on
  58. echo VBoxManage storageattach $VM --storagectl SATA --port 1 --device 0 --type hdd --medium ${VMFOLDER}/${VM}_1.vdi --discard on --nonrotational on
  59. VBoxManage storageattach $VM --storagectl SATA --port 1 --device 0 --type hdd --medium ${VMFOLDER}/${VM}_1.vdi --discard on --nonrotational on
  60. echo VBoxManage storageattach $VM --storagectl SATA --port 2 --device 0 --type hdd --medium ${VMFOLDER}/${VM}_2.vdi --discard on --nonrotational on
  61. VBoxManage storageattach $VM --storagectl SATA --port 2 --device 0 --type hdd --medium ${VMFOLDER}/${VM}_2.vdi --discard on --nonrotational on
  62. echo VBoxManage modifyvm $VM --ioapic on
  63. VBoxManage modifyvm $VM --ioapic on
  64. echo VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
  65. VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
  66. echo VBoxManage modifyvm $VM --nic1 nat --nictype1 82540EM --cableconnected1 on
  67. VBoxManage modifyvm $VM --nic1 nat --nictype1 82540EM --cableconnected1 on
  68. #echo VBoxManage modifyvm $VM --nic2 bridged  --nictype2 82540EM --bridgeadapter2 enp0s31f6 --cableconnected2 on
  69. #VBoxManage modifyvm $VM --nic2 bridged  --nictype2 82540EM --bridgeadapter2 enp0s31f6 --cableconnected2 on
  70. EOF
  71. chmod 755 /usr/local/bin/VACreateVM
  72.  
  73. ###############################################################################################
  74. #ZMIEŃ ISO i przekierowanie portów na eth0
  75. cat << 'EOF' > /usr/local/bin/VAChangeVMStorage  
  76. VM=$1
  77. echo VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --medium none
  78. VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --medium none
  79. #sprawdź wersję Virtualbox i pobierz właściwą płytę VBoxGuestAdditions.iso
  80. [ ! -f /mnt/dc/IMAGES/VBoxGuestAdditions.iso ] && wget http://download.virtualbox.org/virtualbox/5.1.18/VBoxGuestAdditions_5.1.18.iso -O /mnt/dc/IMAGES/VBoxGuestAdditions.iso
  81. echo VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --medium /mnt/dc/IMAGES/VBoxGuestAdditions.iso
  82. VBoxManage storageattach $VM --storagectl IDE --port 0 --device 0 --type dvddrive --medium /mnt/dc/IMAGES/VBoxGuestAdditions.iso
  83. #przekierowanie portów
  84. echo VBoxManage modifyvm $VM --natpf1 delete guestssh
  85. VBoxManage modifyvm $VM --natpf1 delete guestssh
  86. echo VBoxManage modifyvm $VM --natpf1 "guestssh,tcp,,2222,,22"
  87. VBoxManage modifyvm $VM --natpf1 "guestssh,tcp,,2222,,22"
  88. EOF
  89. chmod 755 /usr/local/bin/VAChangeVMStorage
  90.  
  91. #PODAJ POSORTOWANE ROZMIARY ZAINSTALOWANYCH PAKIETÓW
  92. cat << 'EOF' > /usr/local/bin/va_prpmsize  
  93. rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n
  94. EOF
  95. chmod 755 /usr/local/bin/va_prpmsize  
  96.  
  97. ###############################################################################################
  98. #WYGENERUJ MAC DLA VIRTUALBOXA
  99. cat << 'EOF' > /usr/local/bin/va_genmac
  100. echo /etc/hostname `date` |md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/020027\3\4\5/'
  101. EOF
  102. chmod 755 /usr/local/bin/va_genmac
  103.  
  104. ###############################################################################################
  105. #NA KONCIE VAGRANT ZRÓB SSHD
  106. cat << 'EOF' > /usr/local/bin/va_ssh4vagrant
  107. #ssh-keygen -t rsa -b 2048 -N '' -f ~/.ssh/id_rsa
  108. [ ! -d ~/.ssh ] && mkdir ~/.ssh
  109. echo StrictHostKeyChecking no >> ~/.ssh/config
  110. wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O ~/.ssh/authorized_keys
  111. chmod 700 ~/.ssh
  112. chmod 600 ~/.ssh/authorized_keys
  113. chown -R vagrant:vagrant ~/.ssh
  114. EOF
  115. chmod 755 /usr/local/bin/va_ssh4vagrant
  116.  
  117. ###############################################################################################
  118. #ZAKTUALIZUJ VM CENTOSA
  119. cat << 'EOF' > /usr/local/bin/va_update_vmcentos
  120. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  121. echo StrictHostKeyChecking no >> ~/.ssh/config
  122. yum install -y epel-release
  123. rpm -Uvh http://download.ceph.com/rpm-jewel/el7/noarch/ceph-release-1-1.el7.noarch.rpm
  124. #https://apt.puppetlabs.com/
  125. #https://www.digitalocean.com/community/tutorials/how-to-install-puppet-4-in-a-master-agent-setup-on-centos-7
  126. rpm -Uvh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm
  127. #http://www.itzgeek.com/how-tos/linux/centos-how-tos/setup-chef-12-centos-7-rhel-7.html
  128. #http://linoxide.com/linux-how-to/chef-workstation-server-node-centos-7/
  129. yum install -y deltarpm
  130. yum update -y && yum upgrade -y
  131. yum install -y vim ansible nmap sg3_utils wget nano bash-completion ceph-deploy puppetserver puppet ansible sysbench iperf bonnie++ gcc bzip2 make kernel-devel-`uname -r`  net-tools ntp ntpdate ntp-doc traceroute pssh
  132. [ -f /etc/ansible/hosts ] && mv /etc/ansible/hosts /etc/ansible/hosts.orig -f
  133. echo "[web]" > /etc/ansible/hosts
  134. #echo server1 >> /etc/ansible/hosts
  135. #echo server2 >> /etc/ansible/hosts
  136. #echo server3 >> /etc/ansible/hosts
  137. echo 'ansible all -s -m shell -a "$1"' > /usr/local/bin/ae
  138. chmod 700 /usr/local/bin/ae
  139. ntpdate 0.us.pool.ntp.org
  140. hwclock --systohc
  141. systemctl enable ntpd && systemctl start ntpd
  142. curl ix.io/client > /usr/local/bin/ix
  143. chmod +x /usr/local/bin/ix
  144. groupadd admin
  145. usermod -G admin vagrant
  146. echo 'Defaults    env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
  147. echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
  148. sed -i 's/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-enp0s3
  149. echo NM_CONTROLLED=yes >> /etc/sysconfig/network-scripts/ifcfg-enp0s3
  150. #Instaluje sterowniki Virtualbox
  151. [ ! -d /mnt/dvd ] && mkdir /mnt/dvd
  152. mount -t iso9660 -o ro /dev/sr0 /mnt/dvd
  153. cd /mnt/dvd
  154. ./VBoxLinuxAdditions.run
  155. su - vagrant /usr/local/bin/va_ssh4vagrant
  156. yum erase -y kernel kernel-devel
  157. yum clean all
  158. cd
  159. curl https://pastebin.com/raw/FMxYTYhF | sed 's/\r//g' > VAskryptglownyCentos.txt
  160. curl https://pastebin.com/raw/anHdueta | sed 's/\r//g' > VAskryptfunkcje.sh
  161. sh VAskryptfunkcje.sh
  162. EOF
  163. chmod 755 /usr/local/bin/va_update_vmcentos
  164.  
  165. ###############################################################################################
  166. cat << 'EOF' > /usr/local/bin/Vagrantfile.3Centos
  167. servers=[
  168.   {
  169.     :hostname => "server1",
  170.     :ip => "192.168.2.11",
  171.     :bridge => "enp0s31f6",
  172.     #:box => "42n4/centos73_1611",
  173.     :box => "vCentos73",
  174.     :ram => 2048,
  175.     :cpu => 2,
  176.     :mac => "02002751a1bc"
  177.   },
  178.   {
  179.     :hostname => "server2",
  180.     :ip => "192.168.2.12",
  181.     :bridge => "enp0s31f6",
  182.     #:box => "42n4/centos73_1611",
  183.     :box => "vCentos73",
  184.     :ram => 2048,
  185.     :cpu => 2,
  186.     :mac => "0200272864d1"
  187.   },
  188.   {
  189.     :hostname => "server3",
  190.     :ip => "192.168.2.13",
  191.     :bridge => "enp0s31f6",
  192.     #:box => "42n4/centos73_1611",
  193.     :box => "vCentos73",
  194.     :ram => 2048,
  195.     :cpu => 2,
  196.     :mac => "020027092383"
  197.   }
  198. ]
  199. Vagrant.configure(2) do |config|
  200.     servers.each do |machine|
  201.         config.vm.define machine[:hostname] do |node|
  202.             node.vm.box = machine[:box]
  203.             node.vm.hostname = machine[:hostname]
  204.             node.vm.network "public_network", bridge: machine[:bridge] ,ip: machine[:ip], mac: machine[:mac]
  205.             node.vm.provider "virtualbox" do |vb|
  206.                 vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
  207.                 vb.customize ["modifyvm", :id, "--nic2", "bridged",  "--nictype2", "82540EM", "--bridgeadapter2", machine[:bridge], "--cableconnected2", "on" ]
  208.             end
  209.         end
  210.     end
  211.   # default router
  212.   config.vm.provision "shell",
  213.     run: "always",
  214.     inline: "route add default gw 192.168.2.1"
  215.   # delete default gw on enp0s3 (eth0)
  216.   config.vm.provision "shell",
  217.     run: "always",
  218.     inline: "eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
  219. end
  220. EOF
  221.  
  222. ###############################################################################################
  223. cat << 'EOF' > /usr/local/bin/Vagrantfile.3Ubuntu
  224. $ip01="71"
  225. $ip02="72"
  226. $ip03="73"
  227. #in MSWin it gives you names: VBoxManage.exe list bridgedifs
  228. #$bridge = "Intel(R) Ethernet Connection (2) I219-V"
  229. $bridge = "enp0s31f6"
  230. #$bridge="wlp3s0"
  231. #$box = "42n4/UbuntuServerYakkety"
  232. $box="42n4/ubuntu"
  233. $net="192.168.0."
  234. servers=[
  235.   {
  236.     :hostname => "server1",
  237.     :ip => $net+$ip01,
  238.     :bridge => $bridge,
  239.     :box => $box,
  240.     :ram => 2048,
  241.     :cpu => 2,
  242.     :mac => "02002751a1bc"
  243.   },
  244.   {
  245.     :hostname => "server2",
  246.     :ip => $net+$ip02,
  247.     :bridge => $bridge,
  248.     :box => $box,
  249.     :ram => 2048,
  250.     :cpu => 2,
  251.     :mac => "0200272864d1"
  252.   },
  253.   {
  254.     :hostname => "server3",
  255.     :ip => $net+$ip03,
  256.     :bridge => $bridge,
  257.     :box => $box,
  258.     :ram => 2048,
  259.     :cpu => 2,
  260.     :mac => "020027092383"
  261.   }
  262. ]
  263. Vagrant.configure(2) do |config|
  264.     servers.each do |machine|
  265.         config.vm.define machine[:hostname] do |node|
  266.             node.vm.box = machine[:box]
  267.             node.vm.hostname = machine[:hostname]
  268.             node.vm.network "public_network", bridge: machine[:bridge] ,ip: machine[:ip], mac: machine[:mac]
  269.         #node.vm.network "forwarded_port", guest: 8006, host: 8006 if machine[:hostname] == "server1"
  270.             node.vm.provider "virtualbox" do |vb|
  271.                 vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
  272.                 vb.customize ["modifyvm", :id, "--nic2", "bridged",  "--nictype2", "82540EM", "--bridgeadapter2", machine[:bridge], "--cableconnected2", "on", "--nicpromisc2", "allow-all" ]
  273.             end
  274.         end
  275.     end
  276.   config.vm.provision "shell",
  277.     run: "once",
  278.     inline: "sed -i 's/192.168.2./"+$net+"/g' /usr/local/bin/va_hosts4ssh && \
  279.    sed -i 's/192.168.2./"+$net+"/g' /usr/local/bin/va_ceph.conf && \
  280.    sed -i 's/ip01=11/ip01="+$ip01+"/g' /usr/local/bin/va_hosts4ssh && \
  281.    sed -i 's/ip02=12/ip02="+$ip02+"/g' /usr/local/bin/va_hosts4ssh && \
  282.    sed -i 's/ip03=13/ip03="+$ip03+"/g' /usr/local/bin/va_hosts4ssh"
  283.   # default router
  284.   config.vm.provision "shell",
  285.     run: "always",
  286.     inline: "route add default gw "+$net+"1 && \
  287.    eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
  288. end
  289. EOF
  290.  
  291. ###############################################################################################
  292. #va_hosts4ssh "server"
  293. cat << 'EOF' > /usr/local/bin/va_hosts4ssh
  294. server=$1
  295. [ -e /usr/bin/parallel-ssh ] && ln -sfn /usr/bin/parallel-ssh /usr/bin/pssh
  296. if [ -n "$server" ]; then    
  297.     #tu wpisuje uzyskane z dhcp ip
  298.     ip01=11
  299.     ip02=12
  300.     ip03=13
  301.     echo "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4" > /etc/hosts
  302.     echo "192.168.2.${ip01} ${server}1" >> /etc/hosts
  303.     echo "192.168.2.${ip02} ${server}2" >> /etc/hosts
  304.     echo "192.168.2.${ip03} ${server}3" >> /etc/hosts
  305.     echo "${server}1" >> /etc/ansible/hosts
  306.     echo "${server}2" >> /etc/ansible/hosts
  307.     echo "${server}3" >> /etc/ansible/hosts
  308.  
  309.     ssh-keygen -t rsa -b 2048 -N '' -f ~/.ssh/id_rsa
  310.     echo StrictHostKeyChecking no >> ~/.ssh/config
  311.  
  312.     #for node in ${server}1 ${server}2 ${server}3; do ssh-copy-id -i $node ; done
  313.     #http://unix.stackexchange.com/a/204986/23303
  314.     echo "root@192.168.2.${ip01}" > ./ips.txt
  315.     echo "root@192.168.2.${ip02}" >> ./ips.txt
  316.     echo "root@192.168.2.${ip03}" >> ./ips.txt
  317.     cat ~/.ssh/id_rsa.pub | pssh -h ./ips.txt -l remoteuser -A -I -i  \
  318.     '                                                                 \
  319.     umask 077;                                                       \
  320.     [ ! -d ~/.ssh ] && mkdir -p ~/.ssh;                              \
  321.      echo StrictHostKeyChecking no >> ~/.ssh/config;                  \
  322.     afile=~/.ssh/authorized_keys;                                    \
  323.     cat - >> $afile;                                                 \
  324.     sort -u $afile -o $afile                                         \
  325.    '
  326.  
  327.     scp /etc/hosts root@${server}2:/etc
  328.     scp /etc/hosts root@${server}3:/etc
  329.     scp /etc/ansible/hosts root@${server}2:/etc/ansible
  330.     scp /etc/ansible/hosts root@${server}3:/etc/ansible
  331.     ssh ${server}1 "echo ${server}1 > /etc/hostname"
  332.     ssh ${server}2 "echo ${server}2 > /etc/hostname"
  333.     ssh ${server}3 "echo ${server}3 > /etc/hostname"
  334. else
  335.     echo Server name argument required e.g: va_hosts4centos server
  336. fi
  337. EOF
  338. chmod 755 /usr/local/bin/va_hosts4ssh
  339.  
  340. #DODATKOWE DANE DO CEPH.CONF
  341. cat << 'EOF' > /usr/local/bin/va_ceph.conf
  342. mon_pg_warn_max_per_osd = 0
  343. public network = 192.168.2.0/24
  344. #cluster network = 192.168.2.0/24
  345. #Choose reasonable numbers for number of replicas and placement groups.
  346. osd pool default size = 2 # Write an object 2 times
  347. osd pool default min size = 1 # Allow writing 1 copy in a degraded state
  348. osd pool default pg num = 64
  349. osd pool default pgp num = 64
  350. #Choose a reasonable crush leaf type
  351. #0 for a 1-node cluster.
  352. #1 for a multi node cluster in a single rack
  353. #2 for a multi node, multi chassis cluster with multiple hosts in a chassis
  354. #3 for a multi node cluster with hosts across racks, etc.
  355. osd crush chooseleaf type = 1
  356. osd journal size = 200
  357. EOF
  358.  
  359. #INICJALIZACJA CEPHA
  360. cat << 'EOF' > /usr/local/bin/va_ceph_init
  361. #su - cephuser
  362. ceph-deploy purge server1 server2 server3
  363. ceph-deploy purgedata server1 server2 server3
  364. ceph-deploy forgetkeys
  365. ceph-deploy new server1 server2 server3
  366. #ceph-deploy install --release jewel --no-adjust-repos server1 server2 server3
  367. #ceph-deploy install --release jewel server1 server2 server3
  368. ceph-deploy install --repo-url http://download.ceph.com/rpm-jewel/el7/ server1 server2 server3
  369. ceph-deploy --overwrite-conf mon create server1
  370. ceph-deploy --overwrite-conf mon create server2
  371. ceph-deploy --overwrite-conf mon create server3
  372. ceph --admin-daemon /var/run/ceph/ceph-mon.server1.asok mon_status
  373. #poczekaj kilka sekund
  374. sleep 5
  375. cat /usr/local/bin/va_ceph.conf >> ./ceph.conf
  376. scp ./ceph.conf root@server1:/etc/ceph/ceph.conf
  377. scp ./ceph.conf root@server2:/etc/ceph/ceph.conf
  378. scp ./ceph.conf root@server3:/etc/ceph/ceph.conf
  379.  
  380. for i in server1 server2 server3; do ceph-deploy disk zap $i:sdb; done
  381. ae "parted -s /dev/sdb mklabel gpt mkpart primary xfs 0% 100%"
  382. #sprawdź, czy na wszystkich serwerach się wykonało
  383. ceph-deploy gatherkeys server1
  384. ssh server2 ceph-deploy gatherkeys server2
  385. ssh server3 ceph-deploy gatherkeys server3
  386.  
  387. #http://tracker.ceph.com/issues/13833
  388. #ae "chown ceph:ceph /dev/sda2"
  389. for i in server1 server2 server3; do
  390. ceph-deploy --overwrite-conf osd prepare $i:/dev/sdb1; done
  391.  
  392. #poczekać chwilę
  393. for i in server1 server2 server3; do
  394. ceph-deploy --overwrite-conf osd activate $i:/dev/sdb1; done
  395. #sprawdzić "ceph -s", czy osd się dodały
  396.  
  397. #ceph-deploy  --username ceph osd create osd3:/dev/sdb1
  398. ceph-deploy admin server1 server2 server3
  399. ae "chmod +r /etc/ceph/ceph.client.admin.keyring"
  400. ae "systemctl enable ceph-mon.target"
  401. ae "systemctl enable ceph-mds.target"
  402. ae "systemctl enable ceph-osd.target"
  403. ceph -s
  404. EOF
  405. chmod 755 /usr/local/bin/va_ceph_init
  406.  
  407. #TWORZENIE CEPHA DYSKU
  408. cat << 'EOF' > /usr/local/bin/va_ceph_create
  409. #object storage gateway
  410. ceph-deploy rgw create server1 server2 server3
  411. #cephfs requirements
  412. ceph-deploy mds create server1 server2 server3
  413. ceph osd pool create mypool 1
  414. echo "test data" > testfile
  415. rados put -p mypool testfile testfile
  416. rados -p mypool setomapval testfile mykey myvalue
  417. rados -p mypool getomapval testfile mykey
  418. rados get -p mypool testfile testfile2
  419. md5sum testfile testfile2
  420. ceph osd pool create cephfs_data 32
  421. ceph osd pool create cephfs_metadata 32
  422. ceph fs new cephfs cephfs_metadata cephfs_data
  423. echo [ ! -d /mnt/mycephfs ] && mkdir /mnt/mycephfs
  424. echo mount -t ceph `ifconfig enp0s8 | grep inet\ | awk '{print $2}'`:6789:/ /mnt/mycephfs -o name=admin,secret=`cat /etc/ceph/ceph.client.admin.keyring | grep key | cut -f 2 | sed 's/key = //g'`
  425. echo "free && sync && echo 3 > /proc/sys/vm/drop_caches && free"
  426. echo bonnie++ -s 2048 -r 1024 -u root -d /mnt/mycephfs -m BenchClient
  427. EOF
  428. chmod 755 /usr/local/bin/va_ceph_create
  429.  
  430.  
  431. ###############################################################################################
  432. #updatuje Ubuntu, dodając pakiety np. ceph-deploy
  433. cat << 'EOF' > /usr/local/bin/va_update_vmubuntu
  434. wget https://apt.puppetlabs.com/puppetlabs-release-pc1-yakkety.deb
  435. dpkg -i puppetlabs-release-pc1-yakkety.deb
  436. apt-get update
  437. apt-get dist-upgrade -y
  438. apt-get install -y ceph-deploy curl iotop vim nano git bash-completion sg3-utils mc ethtool wpagui wireless-tools bonnie++ iperf sysbench ansible ntp ntpdate ntpstat rdate nmap aptitude openssh-server arp-scan gdebi-core puppet-master pssh traceroute debian-goodies wajig
  439. #puppet resource package puppet-master ensure=latest
  440. #apt install -y quota lm-sensors glusterfs-server
  441. #wget http://prdownloads.sourceforge.net/webadmin/webmin_1.831_all.deb
  442. #gdebi webmin_1.831_all.deb -n
  443. #rm webmin_1.831_all.deb
  444. #curl http://ix.io/pnr > /etc/ntp.conf
  445. ntpdate 0.us.pool.ntp.org
  446. hwclock --systohc
  447. systemctl restart ntp
  448. systemctl enable ntp
  449. ufw status verbose
  450. ufw disable
  451. [ -f /etc/ansible/hosts ] && mv /etc/ansible/hosts /etc/ansible/hosts.orig -f
  452. echo "[web]" > /etc/ansible/hosts
  453. #echo server1  > /etc/ansible/hosts
  454. #echo server2 >> /etc/ansible/hosts
  455. #echo server3 >> /etc/ansible/hosts
  456. echo 'ansible all -s -m shell -a "$1"' > /usr/local/bin/ae
  457. chmod 700 /usr/local/bin/ae
  458. curl ix.io/client > /usr/local/bin/ix
  459. chmod +x /usr/local/bin/ix
  460. sed -i 's/prohibit-password/yes/g' /etc/ssh/sshd_config
  461. #VAGRANT STUFF
  462. useradd -ms /bin/bash vagrant
  463. adduser vagrant users
  464. echo "vagrant:vagrant" | chpasswd
  465. groupadd admin
  466. usermod -G admin vagrant
  467. echo 'Defaults    env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
  468. echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
  469. apt-get install -y build-essential
  470. #Instaluje sterowniki Virtualbox
  471. [ ! -d /mnt/dvd ] && mkdir /mnt/dvd
  472. mount -t iso9660 -o ro /dev/sr0 /mnt/dvd
  473. cd /mnt/dvd
  474. ./VBoxLinuxAdditions.run
  475. su - vagrant /usr/local/bin/va_ssh4vagrant
  476. #wajig large
  477. #dpigs
  478. #apt remove -y linux-headers-4.8.0-22 linux-image-4.8.0-22-generic linux-image-extra-4.8.0-22-generic
  479. apt-get -y remove build-essential
  480. apt-get -y autoremove
  481. #dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
  482. EOF
  483. chmod 755 /usr/local/bin/va_update_vmubuntu
  484.  
  485. ###############################################################################################
  486. #python docker_netinfo dockername
  487. cat << 'EOF' > /usr/local/bin/docker_netinfo
  488. #!/usr/bin/python2.7
  489. import json
  490. import subprocess
  491. import sys
  492. try:
  493.     CONTAINER = sys.argv[1]
  494. except Exception as e:
  495.     print "\n\tSpecify the container name, please."
  496.     print "\t\tEx.:  script.py my_container\n"
  497.     sys.exit(1)
  498. # Inspecting container via Subprocess
  499. proc = subprocess.Popen(["docker","inspect",CONTAINER],
  500.                       stdout=subprocess.PIPE,
  501.                       stderr=subprocess.STDOUT)
  502. out = proc.stdout.read()
  503. json_data = json.loads(out)[0]
  504. net_dict = {}
  505. for network in json_data["NetworkSettings"]["Networks"].keys():
  506.     net_dict['mac_addr']  = json_data["NetworkSettings"]["Networks"][network]["MacAddress"]
  507.     net_dict['ipv4_addr'] = json_data["NetworkSettings"]["Networks"][network]["IPAddress"]
  508.     net_dict['ipv4_net']  = json_data["NetworkSettings"]["Networks"][network]["IPPrefixLen"]
  509.     net_dict['ipv4_gtw']  = json_data["NetworkSettings"]["Networks"][network]["Gateway"]
  510.     net_dict['ipv6_addr'] = json_data["NetworkSettings"]["Networks"][network]["GlobalIPv6Address"]
  511.     net_dict['ipv6_net']  = json_data["NetworkSettings"]["Networks"][network]["GlobalIPv6PrefixLen"]
  512.     net_dict['ipv6_gtw']  = json_data["NetworkSettings"]["Networks"][network]["IPv6Gateway"]
  513.     for item in net_dict:
  514.         if net_dict[item] == "" or net_dict[item] == 0:
  515.             net_dict[item] = "null"
  516.     print "\n[%s]" % network
  517.     print "\n{}{:>13} {:>14}".format(net_dict['mac_addr'],"IP/NETWORK","GATEWAY")
  518.     print "--------------------------------------------"
  519.     print "IPv4 settings:{:>16}/{:<5}  {}".format(net_dict['ipv4_addr'],net_dict['ipv4_net'],net_dict['ipv4_gtw'])
  520.     print "IPv6 settings:{:>16}/{:<5}  {}".format(net_dict['ipv6_addr'],net_dict['ipv6_net'],net_dict['ipv6_gtw'])
  521. EOF
  522. chmod 755 /usr/local/bin/docker_netinfo
  523.  
  524.  
  525. ###############################################################################################
  526. #clean docker space
  527. cat << 'EOF' > /usr/local/bin/docker_clean
  528. #!/bin/bash
  529. # remove exited containers:
  530. out=$(docker ps -aq -f status=dead -f status=exited)
  531. #echo $out
  532. if [[ $out ]]; then
  533.    echo docker rm -v $out
  534.    docker rm -v $out
  535. else
  536.    echo Docker dead or exited not found
  537. fi
  538. # remove unused images:
  539. out=$(docker images --no-trunc | grep '<none>' | awk '{ print $3 }')
  540. #echo $out
  541. if [[ $out ]]; then
  542.    echo docker rmi $out
  543.    docker rmi $out
  544. else
  545.    echo Docker unused images not found
  546. fi
  547. # remove unused volumes:
  548. out=$(docker volume ls -qf dangling=true)
  549. #echo $out
  550. if [[ $out ]]; then
  551.    echo docker volume rm $out
  552.    docker volume rm $out
  553.    #docker volume ls -qf dangling=true | xargs -r docker volume rm
  554. else
  555.    echo Docker unused volumes not found
  556. fi
  557. EOF
  558. chmod 755 /usr/local/bin/docker_clean
  559.  
  560. ###############################################################################################
  561. #remove all dockers
  562. cat << 'EOF' > /usr/local/bin/docker_remove
  563. #!/bin/bash
  564. out=$(docker ps -aq)
  565. #echo $out
  566. if [[ $out ]]; then
  567.    echo docker rm -f $out
  568.    docker rm -f $out
  569. else
  570.    echo Docker not found
  571. fi
  572. EOF
  573. chmod 755 /usr/local/bin/docker_remove
  574.  
  575. ###############################################################################################
  576. #network config /etc/network/interfaces
  577. cat << 'EOF' > /usr/local/bin/va_interfaces
  578. auto lo
  579. iface lo inet loopback
  580.  
  581. auto enp0s3
  582. iface enp0s3 inet static
  583.         address  10.0.2.15
  584.         netmask  255.255.255.0
  585.         gateway  10.0.2.2
  586.  
  587. iface enp0s8 inet manual
  588.  
  589. auto vmbr0
  590. iface vmbr0 inet static
  591.         address  192.168.2.71
  592.         netmask  255.255.255.0
  593.         gateway  192.168.2.1
  594.         bridge_ports enp0s8
  595.         bridge_stp off
  596.         bridge_fd 0
  597. EOF
  598.  
  599. ###############################################################################################
  600. #updatuje proxmox
  601. #va_update_proxmox jessie jewel
  602. cat << 'EOF' > /usr/local/bin/va_update_proxmox
  603. DEBIAN=$1
  604. [ -z $1 ] && DEBIAN=stretch
  605. CEPH=$2
  606. [ -z $2 ] && CEPH=luminous
  607. #export HOME=/root
  608. #echo "export HOME=/root" >> $HOME/.bashrc
  609. #echo "export SHELL=/bin/bash" >> $HOME/.bashrc
  610. sed -i 's/#\ You/export SHELL=\/bin\/bash #/g' $HOME/.bashrc
  611. sed -i 's/# alias/alias/g' $HOME/.bashrc
  612. sed -i 's/# export/export/g' $HOME/.bashrc
  613. sed -i 's/# eval/eval/g' $HOME/.bashrc
  614. sed -i 's/# PS1/PS1/g' $HOME/.bashrc
  615. sed -i 's/# unmask/unmask/g' $HOME/.bashrc
  616. . $HOME/.bashrc
  617. echo 'gpg --keyserver pgpkeys.mit.edu --recv-key  "$1"' > /usr/local/bin/pgpkeyadd
  618. echo 'gpg -a --export "$1" | apt-key add -' >> /usr/local/bin/pgpkeyadd
  619. chmod 755 /usr/local/bin/pgpkeyadd
  620. #pgpkey glusterfs
  621. #pgpkeyadd "DAD761554A72C1DF"
  622. echo "deb http://ftp.pl.debian.org/debian $DEBIAN main contrib" > /etc/apt/sources.list
  623. echo "deb http://security.debian.org $DEBIAN/updates main contrib" >> /etc/apt/sources.list
  624. echo "deb http://download.proxmox.com/debian $DEBIAN pve-no-subscription" >> /etc/apt/sources.list
  625. echo "deb http://download.proxmox.com/debian $DEBIAN pvetest" >> /etc/apt/sources.list
  626. sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/pve-enterprise.list
  627. wget -O - http://download.gluster.org/pub/gluster/glusterfs/3.10/rsa.pub | apt-key add -
  628. echo deb http://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/$DEBIAN/apt $DEBIAN main > /etc/apt/sources.list.d/gluster.list
  629. apt-get update
  630. apt-get install -y locales dirmngr
  631. sed -i 's/^# pl_PL.UTF/pl_PL.UTF/g' /etc/locale.gen && locale-gen
  632. update-locale LANG=pl_PL.UTF-8
  633. apt-get dist-upgrade -y
  634. apt-get install -y sudo openssh-server curl iotop vim git lm-sensors sg3-utils mc ethtool wpagui wireless-tools bonnie++ iperf glusterfs-server ansible ntp ntpdate ntpstat rdate aptitude nano git bash-completion sysbench nmap arp-scan gdebi-core pssh traceroute debian-goodies wajig
  635. #curl http://ix.io/nS5 > /etc/ntp.conf
  636. #systemctl stop system-timesync.service;systemctl disable system-timesync.service;systemctl mask #system-timesync.service
  637. #systemctl restart ntp
  638. #systemctl enable ntp
  639. apt-get install quota gdebi-core -y
  640. wget http://prdownloads.sourceforge.net/webadmin/webmin_1.831_all.deb
  641. apt-get install libnet-ssleay-perl libauthen-pam-perl libpam-runtime libio-pty-perl  apt-show-versions -y  
  642. gdebi webmin_1.831_all.deb -n
  643. rm -f webmin_1.831_all.deb
  644. sed -i 's/DEFAULT="quiet"/DEFAULT="quiet intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1 pci=realloc"/g' /etc/default/grub
  645. update-grub
  646. echo "#etc/modules: kernel modules to load at boot time" > /etc/modules
  647. echo vfio              >> /etc/modules
  648. echo vfio_iommu_type1  >> /etc/modules
  649. echo vfio_pci          >> /etc/modules
  650. echo vfio_virqfd       >> /etc/modules
  651. echo "deb http://www.deb-multimedia.org $DEBIAN main non-free" > /etc/apt/sources.list.d/mint.list
  652. apt-get update
  653. apt-get install -y --force-yes deb-multimedia-keyring
  654. apt-get update
  655. apt-get dist-upgrade -y
  656. apt-get autoremove -y
  657. #apt-get install -y mate-desktop-environment xorg lightdm X11vnc
  658. #apt-get install -y firefox-esr-l10n-pl
  659. apt-get install -y openvswitch-switch
  660. #https://serversforhackers.com/an-ansible-tutorial
  661. #http://www.cyberciti.biz/faq/
  662. [ ! -d /etc/ansible ] && mkdir /etc/ansible
  663. [ -f /etc/ansible/hosts ] && mv /etc/ansible/hosts /etc/ansible/hosts.orig -f
  664. echo "[web]" > /etc/ansible/hosts
  665. #echo "192.168.11.5${host01}" >> /etc/ansible/hosts
  666. echo 'ansible all -s -m shell -a "$1"' > /usr/local/bin/ae
  667. chmod 700 /usr/local/bin/ae
  668. [ ! -d /mnt/SambaShare ] && mkdir /mnt/SambaShare
  669. echo "#!/bin/sh -e" > /etc/rc.local
  670. echo "mount /mnt/SambaShare" >> /etc/rc.local
  671. echo "mount -a" >> /etc/rc.local
  672. echo "gluster volume start vol0" >> /etc/rc.local
  673. sed -i 's/exit/\#exit/g' /etc/rc.local
  674. echo "exit 0" >> /etc/rc.local
  675. chmod 755 /etc/rc.local
  676. update-rc.d rc.local defaults
  677. update-rc.d rc.local enable
  678. cat << __EOF__ >  /etc/systemd/system/rc-local.service
  679. [Unit]
  680.  Description=/etc/rc.local Compatibility
  681.  ConditionPathExists=/etc/rc.local
  682.  After=network.target
  683. [Service]
  684.  Type=forking
  685.  ExecStart=/etc/rc.local start
  686.  TimeoutSec=0
  687.  StandardOutput=tty
  688.  RemainAfterExit=yes
  689.  SysVStartPriority=99
  690. [Install]
  691.  WantedBy=multi-user.target
  692. __EOF__
  693. systemctl enable rc-local
  694. /etc/init.d/kmod start  
  695. update-rc.d kmod enable
  696. curl ix.io/client > /usr/local/bin/ix
  697. chmod +x /usr/local/bin/ix
  698. echo "T" | pveceph install -version $CEPH
  699. [ ! -d /etc/ceph ] && mkdir /etc/ceph
  700. ln -sfn /etc/pve/ceph.conf  /etc/ceph/ceph.conf  
  701. #VAGRANT STUFF
  702. useradd -ms /bin/bash vagrant
  703. adduser vagrant users
  704. echo "vagrant:vagrant" | chpasswd
  705. groupadd admin
  706. usermod -G admin vagrant
  707. echo 'Defaults    env_keep += "SSH_AUTH_SOCK"' >> /etc/sudoers
  708. echo '%admin ALL=NOPASSWD: ALL' >> /etc/sudoers
  709. apt install -y pve-headers-`uname -r` build-essential
  710. #Instaluje sterowniki Virtualbox
  711. [ ! -d /mnt/dvd ] && mkdir /mnt/dvd
  712. mount -t iso9660 -o ro /dev/sr0 /mnt/dvd
  713. cd /mnt/dvd
  714. ./VBoxLinuxAdditions.run
  715. su - vagrant /usr/local/bin/va_ssh4vagrant
  716. #wajig large
  717. #dpigs
  718. apt-get remove -y pve-headers-`uname -r` build-essential
  719. apt-get -y autoremove
  720. #dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
  721. cd
  722. curl https://pastebin.com/raw/anHdueta | sed 's/\r//g' > VAskryptfunkcje.sh
  723. sh VAskryptfunkcje.sh
  724. curl https://pastebin.com/raw/Ey6qHu37 | sed 's/\r//g' > VAskryptglownyProxmox.txt
  725. EOF
  726. chmod 755 /usr/local/bin/va_update_proxmox
  727.  
  728. ###############################################################################################
  729. cat << 'EOF' > /usr/local/bin/Vagrantfile.3Proxmox
  730. $ip01="71"
  731. $ip02="72"
  732. $ip03="73"
  733. #in MSWin it gives you names: VBoxManage.exe list bridgedifs
  734. #$bridge = "Intel(R) Ethernet Connection (2) I219-V"
  735. $bridge = "enp0s31f6"
  736. #$bridge="wlp3s0"
  737. #$box = "42n4/UbuntuServerYakkety"
  738. $box="42n4/proxmoxbeta"
  739. $net="192.168.0."
  740. servers=[
  741.   {
  742.     :hostname => "server1",
  743.     :ip => $net+$ip01,
  744.     :bridge => $bridge,
  745.     :box => $box,
  746.     :ram => 2048,
  747.     :cpu => 2,
  748.     :mac => "02002751a1bc"
  749.   },
  750.   {
  751.     :hostname => "server2",
  752.     :ip => $net+$ip02,
  753.     :bridge => $bridge,
  754.     :box => $box,
  755.     :ram => 2048,
  756.     :cpu => 2,
  757.     :mac => "0200272864d1"
  758.   },
  759.   {
  760.     :hostname => "server3",
  761.     :ip => $net+$ip03,
  762.     :bridge => $bridge,
  763.     :box => $box,
  764.     :ram => 2048,
  765.     :cpu => 2,
  766.     :mac => "020027092383"
  767.   }
  768. ]
  769. Vagrant.configure(2) do |config|
  770.     servers.each do |machine|
  771.         config.vm.define machine[:hostname] do |node|
  772.             node.vm.box = machine[:box]
  773.             node.vm.hostname = machine[:hostname]
  774.             node.vm.network "public_network", bridge: machine[:bridge] ,ip: machine[:ip], mac: machine[:mac]
  775.         node.vm.network "forwarded_port", guest: 8006, host: 8006 if machine[:hostname] == "server1"
  776.         node.vm.network "forwarded_port", guest: 8006, host: 8016 if machine[:hostname] == "server2"
  777.         node.vm.network "forwarded_port", guest: 8006, host: 8026 if machine[:hostname] == "server3"
  778.             node.vm.provider "virtualbox" do |vb|
  779.                 vb.customize ["modifyvm", :id, "--memory", machine[:ram]]
  780.                 vb.customize ["modifyvm", :id, "--nic2", "bridged",  "--nictype2", "82540EM", "--bridgeadapter2", machine[:bridge], "--cableconnected2", "on", "--nicpromisc2", "allow-all" ]
  781.             end
  782.         end
  783.     end
  784.   config.vm.provision "shell",
  785.     run: "once",
  786.     inline: "mkdir -p /etc/pve/priv && touch /etc/pve/priv/authorized_keys && \
  787.    sed -i 's/192.168.2./"+$net+"/g' /usr/local/bin/va_hosts4ssh && \
  788.    sed -i 's/192.168.2./"+$net+"/g' /usr/local/bin/va_ceph.conf && \
  789.    sed -i 's/ip01=11/ip01="+$ip01+"/g' /usr/local/bin/va_hosts4ssh && \
  790.    sed -i 's/ip02=12/ip02="+$ip02+"/g' /usr/local/bin/va_hosts4ssh && \
  791.    sed -i 's/ip03=13/ip03="+$ip03+"/g' /usr/local/bin/va_hosts4ssh"
  792.   # default router
  793.   config.vm.provision "shell",
  794.     run: "always",
  795.     inline: "route add default gw "+$net+"1 && \
  796.    eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
  797. end
  798. EOF
  799.  
  800.  
  801. ###############################################################################################
  802. # exchange nics
  803. cat << 'EOF' > /usr/local/bin/va_exchangenics
  804. ae "rm -f ~/interfaces && cp /usr/local/bin/va_interfaces ~/interfaces"
  805. for i in server1 server2 server3; do ssh $i "sed -i 's/192.168.2.71/'`grep $i /etc/hosts | awk  '{ print $1}'`'/g' ~/interfaces && cat ~/interfaces"; done && \
  806. ae "rm -f /etc/network/interfaces && cp ~/interfaces /etc/network/interfaces" && \
  807. ae "cat /etc/network/interfaces"
  808. for i in server3 server2; do ssh $i "reboot"; done && reboot
  809. EOF
  810. chmod 755 /usr/local/bin/va_exchangenics
  811.  
  812. ###############################################################################################
  813. # proxmox pve ceph create after: pveceph init --network 192.168.<YOUR_NET>.0/24
  814. cat << 'EOF' > /usr/local/bin/va_pvecephcreate
  815. for i in server1 server2 server3; do ssh $i "pveceph createmon"; done
  816. for i in server1 server2 server3; do ssh $i "ceph-disk zap /dev/sdb" && ssh $i "pveceph createosd /dev/sdb" && ssh $i "partprobe /dev/sdb1"; done
  817. cd /etc/pve/priv/
  818. mkdir ceph
  819. cp /etc/ceph/ceph.client.admin.keyring ceph/rbd.keyring
  820. ceph -s                          #ceph should be online
  821. ceph osd lspools                 #look at the pools!
  822. ceph osd pool create rbd 128     #create pool if not present
  823. ceph osd pool set rbd size 2     #replica number
  824. ceph osd pool set rbd min_size 1 #min replica number after e.g. server failure
  825. ceph osd pool application enable rbd rbd
  826. rbd pool init rbd
  827. EOF
  828. chmod 755 /usr/local/bin/va_pvecephcreate
  829.  
  830. ###############################################################################################
  831. # proxmox pve cluster create after ssh with no password: va_hosts4ssh server  #password: packer
  832. cat << 'EOF' > /usr/local/bin/va_pveclustercreate
  833. pvecm create kluster
  834. sleep 5
  835. for i in server2 server3; do ssh $i "pvecm add server1"; done
  836. for i in server3 server2; do ssh $i "reboot"; done
  837. reboot
  838. EOF
  839. chmod 755 /usr/local/bin/va_pveclustercreate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement