-
Notifications
You must be signed in to change notification settings - Fork 0
/
notas_vagrant.html
180 lines (173 loc) · 12.5 KB
/
notas_vagrant.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<link rel="stylesheet" href="/estaticos/mini.css">
</head>
<body>
<div id="wrapper" class="col-sm-12 col-md-8 col-lg-6 col-md-offset-2 col-lg-offset-3">
<header class="sticky">
<a href="https://celticman.github.io/"><h1 class="title">Celticman - notas personales</h1></a>
</header>
<h1 id="uso-de-vagrant">Uso de Vagrant</h1>
<h2 id="configuración">Configuración</h2>
<h3 id="descargar-imágen-máquina-virtual-base">1 - Descargar imágen
máquina virtual base</h3>
<p>Este comando descarga la máquina del registro de vagrant:</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">vagrant</span> box add ubuntu/focal64</span></code></pre></div>
<h3 id="crear-vagrantfile-con-la-base-anterior">2 - Crear Vagrantfile
con la base anterior</h3>
<div class="sourceCode" id="cb2"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> init ubuntu/focal64</span></code></pre></div>
<h3 id="arrancar-máquina-vagrant">3 - Arrancar máquina vagrant</h3>
<div class="sourceCode" id="cb3"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> up</span></code></pre></div>
<p>La máquina virtual se crea en el directorio or defecto de
VirtualBox.</p>
<h3 id="parar-máquina-vagrant">4 - Parar máquina vagrant</h3>
<div class="sourceCode" id="cb4"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> halt</span></code></pre></div>
<h3 id="suspender-máquina-vagrant">5 - Suspender máquina vagrant</h3>
<div class="sourceCode" id="cb5"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> suspend</span></code></pre></div>
<h3 id="destruir-máquina-vagrant">6 - Destruir máquina vagrant</h3>
<p>Destruye la máquina virtual de vagrant, que la guarda Virtual Box en
el directorio ~/VirtualBox VMs.</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> destroy</span></code></pre></div>
<h3 id="actualizacion">7 - Actualizacion</h3>
<p>Actualizar imagen</p>
<div class="sourceCode" id="cb7"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> box update</span></code></pre></div>
<h2 id="conexión-a-máquina-vagrant">Conexión a máquina vagrant</h2>
<h3 id="conexión-ssh">Conexión SSH</h3>
<div class="sourceCode" id="cb8"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> ssh</span></code></pre></div>
<h3 id="mostar-parámetros-conexión-ssh">Mostar parámetros conexión
SSH</h3>
<div class="sourceCode" id="cb9"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">vagrant</span> ssh-config</span></code></pre></div>
<h3 id="configurar-máquina-con-ansible">Configurar máquina con
Ansible</h3>
<p>Añadir al fichero Vagrantfile:</p>
<pre><code> config.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "kubuntu_2004_servidor.yml"
end</code></pre>
<h1 id="setup-vagrant-box-ubuntu-14.04">Setup Vagrant box (Ubuntu
14.04)</h1>
<h2 id="introduction">Introduction</h2>
<p>This file discribe all the steps in order to setup a Vagrant box
(using the <a
href="https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony">Ansible
Ubuntu simple Symfony App</a> config - please refer to this repository
for more info).</p>
<h2 id="requirements">Requirements</h2>
<ul>
<li><a href="http://git-scm.com">Git</a></li>
<li><a href="https://www.virtualbox.org">Virtual box</a></li>
<li><a href="http://www.vagrantup.com">Vagrant</a></li>
<li><a href="http://www.ansible.com">Ansible</a></li>
</ul>
<h2 id="install-the-vagrant-box">Install the Vagrant box</h2>
<h3 id="create-the-box">Create the box</h3>
<div class="sourceCode" id="cb11"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd ~/vagrant/vm1</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant box add {title} {url}</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant init {title}</span></code></pre></div>
<p>Sample box: <a
href="https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box">Ubuntu
Server Precise 12.04.4 amd64 (source) Kernel is ready for Docker (Docker
not included) Contains Chef, Puppet</a></p>
<p>For example:</p>
<div class="sourceCode" id="cb12"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd ~/vagrant/vm1</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant box add ubuntu_14_04_basebox https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant init ubuntu_14_04_basebox</span></code></pre></div>
<h3 id="config-the-vm">Config the VM</h3>
<p>Add the following lines in your VagrantFile</p>
<div class="sourceCode" id="cb13"><pre
class="sourceCode ruby"><code class="sourceCode ruby"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="st">"forwarded_port"</span>, <span class="wa">guest: </span><span class="dv">20</span>, <span class="wa">host: </span><span class="dv">20020</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="st">"forwarded_port"</span>, <span class="wa">guest: </span><span class="dv">21</span>, <span class="wa">host: </span><span class="dv">20021</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="st">"forwarded_port"</span>, <span class="wa">guest: </span><span class="dv">22</span>, <span class="wa">host: </span><span class="dv">20022</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="st">"forwarded_port"</span>, <span class="wa">guest: </span><span class="dv">80</span>, <span class="wa">host: </span><span class="dv">20080</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i <span class="cf">in</span> <span class="dv">1024</span><span class="kw">..</span><span class="dv">1048</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="wa">:forwarded_port</span>, <span class="wa">guest: </span>i, <span class="wa">host: </span>i</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> config<span class="at">.vm.network</span> <span class="st">"forwarded_port"</span>, <span class="wa">guest: </span><span class="dv">3306</span>, <span class="wa">host: </span><span class="dv">23306</span></span></code></pre></div>
<h3 id="run-the-vm">Run the VM</h3>
<div class="sourceCode" id="cb14"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant up</span></code></pre></div>
<h2 id="ansible-config">Ansible config</h2>
<h3 id="clone-the-ansible-config">Clone the Ansible config</h3>
<p>Clone the <a
href="https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony">Ansible
Ubuntu simple Symfony App</a>.</p>
<div class="sourceCode" id="cb15"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd ~/git</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> git clone https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony.git</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd remiii-ansible-ubuntu-app-simple-symfony</span></code></pre></div>
<h3 id="config-the-ansible-config">Config the Ansible config</h3>
<p>*** WARNING: is just a sample, please ie. <a
href="https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony/blob/master/README.md#setup">remiii-ansible-ubuntu-app-simple-symfony</a>
***</p>
<p>Setup the vars in <code>vars/myConfig.yml</code> and add
<code>ansible_inventory_machinename</code> file: <a
href="https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony/blob/master/README.md#setup">More
info here</a>.</p>
<pre><code># ansible_inventory_machinename
machine ansible_ssh_host='127.0.0.1' ansible_ssh_port=20022</code></pre>
<p>Copy the config dist file <code>vars/myConfig.yml.dist</code></p>
<div class="sourceCode" id="cb17"><pre
class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cp vars/myConfig.yml.dist vars/myConfig.yml</span></code></pre></div>
<pre><code># pathToTheProject/vars/myConfig.yml
...
rootPath: '~/git/remiii-ansible-ubuntu-app-simple-symfony'
hostname: 'vm1.local'
publicIpAddress: '127.0.0.1'
...</code></pre>
<p>Add some files in the <code>vars</code> directory: <a
href="https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony/blob/master/README.md#setup">More
info here</a>.</p>
<ul>
<li>myGitUserMachineUserKey</li>
<li>myGitUserMachineUserKey.pub</li>
<li>mySSHPublicKey.pub</li>
<li>…</li>
</ul>
<h3 id="run-the-ansible-config">Run the Ansible config</h3>
<p>Exec the config:</p>
<div class="sourceCode" id="cb19"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ansible-playbook <span class="at">-i</span> ansible_inventory_machinename <span class="at">--private-key</span><span class="op">=</span>pathToYourVagrantPrivateKey <span class="at">-u</span> vagrant ./myConfig.yml</span></code></pre></div>
<h3 id="update-etchosts-config-on-your-host">Update etc/hosts config on
your Host</h3>
<div class="sourceCode" id="cb20"><pre
class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> sudo vi /etc/hosts</span></code></pre></div>
<p>Add the following lines in your hosts <code>/etc/hosts</code>
file:</p>
<pre><code>###
# VM1
###
127.0.0.1 vm1.local sql.vm1.local apc.vm1.local website-sample.vm1.local website-sample1.vm1.local website-sample2.vm1.local foo.vm1.local</code></pre>
<h3 id="thats-it">That’s it!</h3>
<h3 id="restart-and-login-to-the-vm">Restart and login to the VM</h3>
<div class="sourceCode" id="cb22"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd ~/vagrant/vm1</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vagrant reload</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> vargant ssh</span></code></pre></div>
<h2 id="license">License</h2>
<p>MIT</p>
<h2 id="author">Author</h2>
<ul>
<li>Rémi Barbe (aka Remiii)</li>
</ul>
<footer>
Estilo: <a href="https://minicss.us">Mini.css</a>
Generador: <a href="https://pandoc.org/">pandoc 2.17.1.1</a>
Fecha: 2023-10-25
Alojamiento: <a href="https://github.com/celticman/celticman.github.io"><img src="/estaticos/gitHubmark32px.png"></a>
</footer>
</div>
</body>
</html>