Imscaradh tapa vm ESXi ag baint úsáide as Terraform

Dia duit gach duine, Ivan is ainm dom agus is riarthóir córais alcóil (OPS) mé.

Ba mhaith liom a insint duit conas a imscaraim meaisíní fíorúla ar ESXi gan vCenter ag baint úsáide as Terraform.

Go minic bíonn ort meaisíní fíorúla a imscaradh/athchruthú chun é seo nó an feidhmchlár sin a thástáil. Mar gheall ar a leisce, smaoinigh mé ar an bpróiseas a uathoibriú. Thug mo chuardach táirge iontach ón gcuideachta dom hashicorp, terraform.

Sílim go bhfuil a fhios ag go leor daoine cad is Terraform ann, ach iad siúd nach bhfuil a fhios acu, is feidhmchlár é chun aon scamall, bonneagar nó seirbhís a bhainistiú ag baint úsáide as an gcoincheap IasC (Bonneagar mar chód).

Úsáidim ESXi mar mo thimpeallacht fhíorúilithe. Simplí go leor, áisiúil agus iontaofa.
Feicim ceist.

Cén fáth terraform más féidir leat úsáid a bhaint as vCenter Server?

Ar ndóigh is féidir leat, ach ... Ar an gcéad dul síos, is ceadúnas breise é seo, ar an dara dul síos, tá an táirge seo an-dian ar acmhainní agus ní bheidh sé oiriúnach ar mo fhreastalaí baile, agus sa tríú háit, is deis é do scileanna a uasghrádú.

Feidhmíonn ardán Intel NUC mar fhreastalaí:

CPU: 2 CPUs x Intel(R) Core(TM) i3-4010U CPU @ 1.70GHz
RAM: 8Gb
HDD: 500Gb
ESXi version: ESXi-6.5.0-4564106-standard (VMware, Inc.)

Agus mar sin, na chéad rudaí ar dtús.

Faoi láthair, déanaimis esxi a chumrú, eadhon, an calafort VNC a oscailt sna socruithe balla dóiteáin.

De réir réamhshocraithe, tá an comhad cosanta ar scríobh. Déanaimid na hionramhálacha seo a leanas:

chmod 644 /etc/vmware/firewall/service.xml
chmod +t /etc/vmware/firewall/service.xml
vi /etc/vmware/firewall/service.xml

cuir an bloc seo a leanas le deireadh an chomhaid:

<service id="1000">
  <id>packer-vnc</id>
  <rule id="0000">
    <direction>inbound</direction>
    <protocol>tcp</protocol>
    <porttype>dst</porttype>
    <port>
      <begin>5900</begin>
      <end>6000</end>
    </port>
  </rule>
  <enabled>true</enabled>
  <required>true</required>
</service>

Scoir muid agus sábhálaimid. Athraigh na cearta ar ais agus atosaigh an tseirbhís:

chmod 444 /etc/vmware/firewall/service.xml
esxcli network firewall refresh

Bailí go dtí go mbeidh an t-óstach atosaithe. Ina dhiaidh sin, ní mór an t-ionramháil seo a dhéanamh arís.

As seo amach déanfaidh mé an obair ar fad i meaisín fíorúil ar an bhfreastalaí céanna.

Gnéithe:

OS: Centos 7 x86_64 minimal
RAM: 1GB
HDD: 20GB
Selinux: disable
firewalld: disable

Next ní mór dúinn pacálaí, táirge de chuid HashiCorp freisin.

Is gá an íomhá “órga” a chur le chéile go huathoibríoch. A úsáidfimid sa todhchaí.

yum install unzip git -y
curl -O https://releases.hashicorp.com/packer/1.5.5/packer_1.5.5_linux_amd64.zip
unzip packer_1.5.5_linux_amd64.zip -d /usr/bin && rm -rf packer_1.5.5_linux_amd64.zip
packer version
Packer v1.5.5

Ar an t-aistriú leagan pacálaí D’fhéadfadh earráid tarlú toisc go bhféadfadh pacáiste a bhfuil an t-ainm céanna air a bheith i RedHat-bhunaithe.

which -a packer
/usr/sbin/packer

Chun é seo a réiteach, is féidir leat nasc simplí a chruthú nó cosán iomlán a úsáid /usr/bin/pacálaí.

Anois ní mór dúinn ovftool nasc íoslódáil. Íoslódáil, cuir ar an bhfreastalaí agus suiteáil:

chmod +x VMware-ovftool-4.4.0-15722219-lin.x86_64.bundle
./VMware-ovftool-4.4.0-15722219-lin.x86_64.bundle
Extracting VMware Installer...done.
You must accept the VMware OVF Tool component for Linux End User
License Agreement to continue.  Press Enter to proceed.
VMWARE END USER LICENSE AGREEMENT
Do you agree? [yes/no]:yes
The product is ready to be installed.  Press Enter to begin
installation or Ctrl-C to cancel. 
Installing VMware OVF Tool component for Linux 4.4.0
    Configuring...
[######################################################################] 100%
Installation was successful.

Bogaimis ar aghaidh.

D’ullmhaigh mé gach rud a theastaigh uaim don gig.

git clone https://github.com/letnab/create-and-deploy-esxi.git && cd create-and-deploy-esxi

Go fillteán iso ní mór duit dáileadh an chórais oibriúcháin a shuiteáil. I mo chás is centos 7 é.

Ní mór duit freisin a chur in eagar ar an gcomhad centos-7-bonn.json:

variables: указать свои данные для подключения
iso_urls: указать актуальный
iso_checksum: чексумма вашего образа 

Tar éis na hathruithe go léir, reáchtáil an tógáil:

/usr/bin/packer build centos-7-base.json

Má tá gach rud cumraithe agus sonraithe i gceart, ansin feicfidh tú pictiúr de shuiteáil uathoibríoch an chórais oibriúcháin. Tógann an próiseas seo 7-8 nóiméad dom.

Tar éis críochnú rathúil san fhillteán aschur-pacálaí-centos7-x86_64 beidh comhad ubhagán ann.

Suiteáil Terraform:

curl -O https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
unzip terraform_0.12.24_linux_amd64.zip -d /usr/bin/ && rm -rf terraform_0.12.24_linux_amd64.zip
terraform version
Terraform v0.12.24

Ós rud é nach bhfuil soláthraí ag Terraform le haghaidh ESXi, ní mór duit ceann a thógáil.

Socraigh dul:

cd /tmp
curl -O https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz && rm -rf go1.14.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
go version go1.14.2 linux/amd64

Ansin, bailímid an soláthraí:

go get -u -v golang.org/x/crypto/ssh
go get -u -v github.com/hashicorp/terraform
go get -u -v github.com/josenk/terraform-provider-esxi
export GOPATH="$HOME/go"
cd $GOPATH/src/github.com/josenk/terraform-provider-esxi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -extldflags "-static"' -o terraform-provider-esxi_`cat version`
cp terraform-provider-esxi_`cat version` /usr/bin

Táimid ag an líne deiridh. Déanaimis ár n-íomhá a rolladh amach.

Téigh go dtí an fillteán:

cd /root/create-and-deploy-esxi/centos7

Gcéad dul síos, in eagar an comhad athróga.tf. Ní mór duit nasc leis an bhfreastalaí ESXi a shonrú.

I gcomhad líonra_config.cfg ina bhfuil socruithe líonra an mheaisín fíorúil amach anseo. Déanaimid é a athrú chun freastal ar ár riachtanais agus reáchtáilimid an líneáil aon-líne:

sed -i -e '2d' -e '3i "network": "'$(gzip < network_config.cfg| base64 | tr -d 'n')'",' metadata.json

Bhuel, sa chomhad príomh.tf athraigh an cosán go dtí an comhad ubhagán le do chuid féin, más difriúil é.

Nóiméad na fírinne.

terraform init
Initializing the backend...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.esxi: version = "~> 1.6"
* provider.template: version = "~> 2.1"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.template_file.Default: Refreshing state...
data.template_file.network_config: Refreshing state...

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # esxi_guest.Default will be created
  + resource "esxi_guest" "Default" {
      + boot_disk_size         = (known after apply)
      + disk_store             = "datastore1"
      + guest_name             = "centos7-test"
      + guest_shutdown_timeout = (known after apply)
      + guest_startup_timeout  = (known after apply)
      + guestinfo              = {
          + "metadata"          = "base64text"
          + "metadata.encoding" = "gzip+base64"
          + "userdata"          = "base64text"
          + "userdata.encoding" = "gzip+base64"
        }
      + guestos                = (known after apply)
      + id                     = (known after apply)
      + ip_address             = (known after apply)
      + memsize                = "1024"
      + notes                  = (known after apply)
      + numvcpus               = (known after apply)
      + ovf_properties_timer   = (known after apply)
      + ovf_source             = "/root/create-and-deploy-esxi/output-packer-centos7-x86_64/packer-centos7-x86_64.ova"
      + power                  = "on"
      + resource_pool_name     = (known after apply)
      + virthwver              = (known after apply)

      + network_interfaces {
          + mac_address     = (known after apply)
          + nic_type        = (known after apply)
          + virtual_network = "VM Network"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Críochnaigh:

terraform apply

Má dhéantar gach rud i gceart, ansin i 2-3 nóiméad déanfar meaisín fíorúil nua a imscaradh ón íomhá a cruthaíodh roimhe seo.

Níl na roghanna seo go léir teoranta ach amháin ag do shamhlaíocht.

Ní raibh mé ach ag iarraidh mo thaithí a roinnt agus na príomhphointí a thaispeáint agus mé ag obair leis na táirgí seo.

Go raibh maith agat as aire!

PS: Beidh áthas orm cáineadh cuiditheach a fháil.

Foinse: will.com

Add a comment