### Install OS using qemu-iso with Image URL Source: https://docs.servercore.com/dedicated/manage/install-os-from-image Initiates the OS installation by downloading an ISO image from a provided URL. The script uploads the image to server RAM, starts a VNC server, and begins the OS installation. Requires a valid URL to a publicly hosted OS image. ```bash qemu-iso ``` -------------------------------- ### Kafka Consumer Example (Java) Source: https://docs.servercore.com/managed-databases/kafka/connect-to-cluster This Java code snippet outlines the basic structure for a Kafka consumer using the Kafka clients library. It includes necessary imports and the start of a consumer setup, ready to be integrated into a larger application. This code is intended to be placed within the 'src/com/example/App.java' file. ```java package com.example; import java.util.*; import org.apache.kafka.common.*; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.clients.consumer.*; ``` -------------------------------- ### Install mysql2 Node.js Library Source: https://docs.servercore.com/managed-databases/mysql-semi-sync/connect-to-cluster This command installs the `mysql2` library, a popular Node.js driver for connecting to MySQL databases. It is a prerequisite for the provided JavaScript connection example. ```bash npm install mysql2 ``` -------------------------------- ### Example User Data Script for Containers Ready and Portainer Source: https://docs.servercore.com/dedicated/manage-applications/containers-ready An example of a complete user data script for installing Containers Ready with Portainer. This script populates the docker-compose.yaml, .env, and user-values.yaml files with sample configurations for web and db services, environment variables, and Portainer settings including domain and email for Let's Encrypt. ```yaml #cloud-config write_files: - path: "/opt/containers/docker-compose.yaml" permissions: "0644" content: | version: "3.9" services: web: container_name: web image: "busybox" env_file: "/opt/containers/.env" db: container_name: db image: "busybox" env_file: "/opt/containers/.env" - path: "/opt/containers/.env" permissions: "0644" content: | APP_ENV=production LOG_LEVEL=info LOG_FORMAT=json LOG_OUTPUT=/var/log/app.log - path: "/opt/user-values.yaml" permissions: "0644" content: | portainer_use_le: true portainer_domain: "example.com" portainer_le_email: "root@example.com" ``` -------------------------------- ### Connect to Redis Cluster with go-redis (Go) Source: https://docs.servercore.com/managed-databases/redis/connect-to-cluster Provides a Go code example for connecting to a Redis cluster using the go-redis client. It demonstrates setting and getting a key. Requires the 'github.com/go-redis/redis/v8' package. ```go package main import ( "context" "fmt" "github.com/go-redis/redis/v8" ) func main() { var ctx = context.Background() rdb := redis.NewClient(&redis.Options{ Addr: ":", Password: "", DB: 0, }) err := rdb.Set(ctx, "key", "value", 0).Err() if err != nil { panic(err) } val, err := rdb.Get(ctx, "key").Result() if err != nil { panic(err) } fmt.Println("key", val) } ``` -------------------------------- ### Connect to Database without SSL (Python) Source: https://docs.servercore.com/managed-databases/postgresql/connect-to-cluster Connect to a database using Python with the psycopg2 library. This example demonstrates establishing a connection, executing a simple query, and closing the connection. Ensure the psycopg2 library is installed (`pip3 install psycopg2-binary`). ```python import psycopg2 conn = psycopg2.connect(""" host= dbname= user= password= port= """) cur = conn.cursor() cur.execute('SELECT 40+2') print(cur.fetchone()) cur.close() conn.close() ``` -------------------------------- ### Start Fluent Bit Agent Locally Source: https://docs.servercore.com/logs/tools/fluent-bit This command starts the Fluent Bit agent locally using a specified configuration file and verbosity level. This is suitable for testing or when Fluent Bit is installed directly on the host system. ```bash sudo /opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.conf -vv ``` -------------------------------- ### Install and Start Nginx on Debian/Ubuntu Source: https://docs.servercore.com/cloud-servers/load-balancers/configure-balancing/tcp-proxy Installs and starts the Nginx web server on Debian-based systems using apt. This is a prerequisite for configuring Nginx to use the Proxy Protocol. ```bash apt update apt install nginx systemctl start nginx ``` -------------------------------- ### Connect to OS via qemu-iso (Linux) Source: https://docs.servercore.com/dedicated/manage/install-os-from-image Connect to the operating system installed on the server by executing the 'qemu-iso' script without any arguments. This allows access to the OS for configuration changes. ```bash qemu-iso ``` -------------------------------- ### Connect to Database with Go (go-sql-driver) Source: https://docs.servercore.com/managed-databases/mysql-sync/connect-to-cluster Connect to the database using the go-sql-driver for Go. This example demonstrates opening a connection and executing a simple query. ```go package main import ( "database/sql" "fmt" "github.com/go-sql-driver/mysql" ) func main() { connectionString := fmt.Sprintf("%s:%s@tcp(%s:)/%s", "", "", "", "", ) db, err := sql.Open("mysql", connectionString) if err != nil { panic(err.Error()) } defer db.Close() var sum int64 err = db.QueryRow("SELECT 40+2").Scan(&sum) if err != nil { panic(err.Error()) } fmt.Println(sum) } ``` -------------------------------- ### Install pg Node.js Package Source: https://docs.servercore.com/managed-databases/postgresql/connect-to-cluster Installs the 'pg' npm package, which is a PostgreSQL client for Node.js. This is a prerequisite for using the provided JavaScript connection example. ```npm npm install pg ``` -------------------------------- ### Connect with SSL (Go) Source: https://docs.servercore.com/managed-databases/mysql-sync/connect-to-cluster This Go program illustrates how to establish a secure SSL/TLS connection to a database. It uses the `go-sql-driver/mysql` package and requires the root certificate to be read and configured within a `tls.Config` object, which is then registered for the connection. ```go package main import ( "crypto/tls" "crypto/x509" "database/sql" "fmt" "github.com/go-sql-driver/mysql" "io/ioutil" ) func main() { rootCertPool := x509.NewCertPool() pem, err := ioutil.ReadFile("") if err != nil { panic(err) } if ok := rootCertPool.AppendCertsFromPEM(pem); !ok { panic("Failed to append PEM.") } mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, }) connectionString := fmt.Sprintf("%s:%s@tcp(%s:)/%s?tls=custom", "", "", "", "", ) db, err := sql.Open("mysql", connectionString) if err != nil { panic(err) } defer db.Close() var sum int64 ``` -------------------------------- ### Update Repositories and Install Packages using Cloud-config and Bash Source: https://docs.servercore.com/dedicated/manage/user-data Scripts to update package repositories and install specified packages. Cloud-config uses 'package_update' and 'packages' directives, while bash uses 'apt update' and 'apt install'. This example installs 'pwgen' and 'pastebinit'. ```cloud-config #cloud-config package_update: true packages: - pwgen - pastebinit ``` ```bash #!/bin/bash apt update apt install pwgen pastebinit ``` -------------------------------- ### Example OpenStack Flavor Creation Source: https://docs.servercore.com/cloud-servers/create/create-server-with-usb-device An example demonstrating how to create a specific OpenStack flavor with 2 vCPUs, 2GB of RAM, and an 80GB disk, named 'new_flavor'. ```bash openstack flavor create \ --private\ --vcpus 2\ --ram 2048\ --disk 80\ new_flavor ``` -------------------------------- ### Install OpenStack CLI on Windows Source: https://docs.servercore.com/cloud-servers/tools/openstack-cli/configure-openstack-cli Installs the OpenStack CLI on Windows using pip. This guide requires Python 3 and Microsoft C++ Build Tools to be installed first. It covers the installation of the core openstack client and optional clients for Octavia, Glance, and Manila. ```bash pip3 install python-openstackclient openstack --version # Optional: pip3 install python-octaviaclient pip3 install python-glanceclient pip3 install python-manilaclient==3.4.0 ``` -------------------------------- ### Connect to Database with SSL using Go Source: https://docs.servercore.com/managed-databases/timescaledb/connect-to-cluster This Go program demonstrates establishing a secure SSL connection to a database cluster using the `pgx` library. It constructs a connection string that includes SSL parameters and handles potential connection and query errors. Ensure the `pgx` library is imported. ```go package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v4" ) func main() { connectionString := fmt.Sprintf("postgres://%s:%s@%s:/%s?sslmode=verify-ca&sslrootcert=%s", "", "", "", "", "" ) conn, err := pgx.Connect(context.Background(), connectionString) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err) os.Exit(1) } defer conn.Close(context.Background()) var sum int64 err = conn.QueryRow(context.Background(), "SELECT 40+2").Scan(&sum) if err != nil { fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err) os.Exit(1) } fmt.Println(sum) } ``` -------------------------------- ### Example Cluster Response (JSON) Source: https://docs.servercore.com/api/managed-kubernetes An example JSON response for the 'Get All Clusters' API endpoint, illustrating the structure and fields for a Managed Kubernetes cluster. ```json { "clusters": [ { "id": "5803b490-2d6b-418a-8645-eacda0f003c5", "created_at": "2019-11-04T10:21:11.943917Z", "updated_at": "2019-11-04T10:29:22.652987Z", "name": "cluster1", "status": "ACTIVE", "project_id": "c1f35d51fbfc4ba595830d5416fea58a", "network_id": "f6e76442-d33d-4c35-9d73-b5391ca03653", "subnet_id": "a9881ca2-d481-4206-b39a-7f7e758672e3", "kube_api_ip": "203.0.113.101", "kube_version": "1.16.9", "region": "ru-3", "additional_software": null, "enable_autorepair": true, "enable_patch_version_auto_upgrade": true, "kubernetes_options": { "feature_gates": [ "CPUManager" ], "admission_controllers": [ "PodSecurityPolicy" ], "audit_logs": { "enabled": true, "secret_name": "mks-audit-logs" }, "oidc": { "enabled": true, "issuer_url": "https://example.com/", "client_id": "kubernetes", "username_claim": "email", "groups_claim": "groups", "provider_name": "keycloak" } }, "zonal": false, "private_kube_api": false }, { "id": "998e205c-b67c-4941-85cd-c31b09582a4a", "created_at": "2019-11-04T12:54:20.769125Z", "updated_at": "2019-11-04T13:08:08.785385Z", "name": "testing", "status": "ACTIVE", "project_id": "c1f35d51fbfc4ba595830d5416fea58a", "network_id": "b5e2e88d-d393-4b9d-b5e5-9cc89c7843cf", "subnet_id": "31c0a11c-cdb2-442a-a92b-0c5d12631b75", "kube_api_ip": "203.0.113.220", "kube_version": "1.17.6", "region": "ru-1", "additional_software": null, "enable_autorepair": true, "enable_patch_version_auto_upgrade": false, "kubernetes_options": { "feature_gates": [ "CPUManager" ], "admission_controllers": [ "PodSecurityPolicy" ], "audit_logs": { "enabled": true, "secret_name": "mks-audit-logs" }, "oidc": { "enabled": true, "issuer_url": "https://example.com/", "client_id": "kubernetes", "username_claim": "email", "groups_claim": "groups", "provider_name": "keycloak" } }, "zonal": true, "private_kube_api": true } ] } ``` -------------------------------- ### Connect to Database without SSL (Go) Source: https://docs.servercore.com/managed-databases/postgresql/connect-to-cluster Connect to a database using Go with the pgx library. This example establishes a connection using a connection string, executes a query, and closes the connection. Ensure the pgx library is imported (`github.com/jackc/pgx/v4`). ```go package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v4" ) func main() { connectionString := fmt.Sprintf("postgres://%s:%s@%s:/%s", "", "", "", "", ) conn, err := pgx.Connect(context.Background(), connectionString) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err) os.Exit(1) } defer conn.Close(context.Background()) var sum int64 err = conn.QueryRow(context.Background(), "SELECT 40+2").Scan(&sum) if err != nil { fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err) os.Exit(1) } fmt.Println(sum) } ``` -------------------------------- ### Kafka Consumer Connection Example (Go) Source: https://docs.servercore.com/managed-databases/kafka/connect-to-cluster This Go code snippet sets up a Kafka consumer using the Sarama library. It configures SCRAM-SHA-512 authentication, TLS with a custom root certificate, and consumes messages from a specified topic. It handles errors and graceful shutdown. ```go package main import ( "crypto/tls" "crypto/x509" "fmt" "io/ioutil" "os" "os/signal" "strings" "github.com/IBM/sarama" ) const BROKERS = ":" const USER = "" const PASSWORD = "" const TOPIC = "" const CERT = "" func main() { brokers := BROKERS splitBrokers := strings.Split(brokers, ",") conf := sarama.NewConfig() conf.Producer.RequiredAcks = sarama.WaitForAll conf.Version = sarama.V3_3_1_0 conf.Consumer.Return.Errors = true conf.ClientID = "go_client" conf.Metadata.Full = true conf.Net.SASL.Enable = true conf.Net.SASL.User = USER conf.Net.SASL.Password = PASSWORD conf.Net.SASL.Handshake = true conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} } conf.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA512) certs := x509.NewCertPool() pemPath := CERT pemData, err := ioutil.ReadFile(pemPath) if err != nil { fmt.Println("Couldn't load cert: ", err.Error()) panic(err) } certs.AppendCertsFromPEM(pemData) conf.Net.TLS.Enable = true conf.Net.TLS.Config = &tls.Config{ RootCAs: certs, } master, err := sarama.NewConsumer(splitBrokers, conf) if err != nil { fmt.Println("Couldn't create consumer: ", err.Error()) panic(err) } defer func() { if err := master.Close(); err != nil { panic(err) } }() consumer, err := master.ConsumePartition(TOPIC, 0, sarama.OffsetOldest) if err != nil { panic(err) } signals := make(chan os.Signal, 1) signal.Notify(signals, os.Interrupt) doneCh := make(chan struct{}) go func() { for { select { case err := <-consumer.Errors(): fmt.Println(err) case msg := <-consumer.Messages(): fmt.Println("Received messages", string(msg.Key), string(msg.Value)) case <-signals: doneCh <- struct{}{} } } }() <-doneCh } ``` -------------------------------- ### Install gdisk Utility for GPT Partitioning Source: https://docs.servercore.com/dedicated/troubleshooting/replace-disk-raid Installs the 'gdisk' utility, which is used for working with GUID Partition Tables (GPT) on disks. This is a prerequisite for advanced disk partitioning tasks. The '-y' flag automatically confirms any prompts. ```bash apt-get install gdisk -y ``` -------------------------------- ### Get Node by ID Response Example Source: https://docs.servercore.com/api/managed-kubernetes An example JSON response for retrieving details of a specific node within a cluster nodegroup. Includes node ID, creation/update timestamps, hostname, IP, and associated nodegroup and server IDs. ```json { "node": { "id": "94838b31-9ae0-4a23-88ad-256e4f13d345", "created_at": "2019-11-05T15:08:23.672122Z", "updated_at": "2019-11-06T10:50:39.31144Z", "hostname": "first-node", "ip": "198.51.100.101", "nodegroup_id": "63ed5342-b22c-4c7a-9d41-c1fe4a142c13", "os_server_id": "1821e0ef-cd77-4fea-bd39-5b1f470368b5" } } ``` -------------------------------- ### View cloud-init Output Log Source: https://docs.servercore.com/cloud-servers/applications/apache-kafka This command shows how to open the cloud-init output log file using the 'vi' text editor. This log is crucial for diagnosing issues that occur during the initial server setup and configuration, such as problems with user data or permissions. ```bash vi /var/log/cloud-init-output.log ``` -------------------------------- ### Node.js PostgreSQL Connection Example Source: https://docs.servercore.com/managed-databases/postgresql/connect-to-cluster Provides a complete Node.js code example for connecting to a PostgreSQL database using the 'pg' library. It includes SSL configuration with a provided root certificate and demonstrates executing a simple query. ```javascript const fs = require('fs'); const pg = require('pg'); const config = { host: '', port: '', database: '', user: '', password: '', ssl: { rejectUnauthorized: true, ca: fs.readFileSync('').toString(), }, }; const client = new pg.Client(config); client.connect((error) => { if (error) throw error; }); client.query('SELECT 40 + 2 AS sum', (error, res) => { if (error) throw error; console.log(res.rows); client.end(); }); ``` -------------------------------- ### Get Certificate Info - Response Samples Source: https://docs.servercore.com/api/federations Provides example responses for different HTTP status codes when retrieving certificate information. Includes examples for 200 OK, 401 Unauthorized, 403 Forbidden, 404 Not Found, and 500 Internal Server Error. ```json { * "id": "bcceb50a-e4a3-404f-8391-f319e40c1fd5", * "account_id": "242137", * "federation_id": "f9a51b33-9194-4d44-a959-43740b6334a4", * "name": "certificate name", * "description": "certificate description", * "not_before": "2023-06-23T11:26:48Z", * "not_after": "2033-06-23T11:28:28Z", * "fingerprint": "6A822A2645D9A18D1CC40D5B5BDA444AA579AF3B399AF77309ABD5222CC23FC0", * "data": "-----BEGIN CERTIFICATE-----\nMIICmzCCAYMCBgGI6ANFczANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDDAZtYXN0ZXIwHhcNMjMwNjIzMTEyNjQ4WhcNMzMwNjIzMTEyODI4WjARMQ8wDQYDVQQDDAZtYXN0ZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC04rOaDpre/MucE3HXVCnAnpqIqQOeMn696AW2FATnI26x1BsxVAGjcrheAOIu+CxC28m48Ah4+SiTEk/u2X/WbGTd/1GZooz37cge0AWMQGyh8ysZRd6q06kg4QGD1iUtdQyHioMbSr9pPne2QQgSX5/gM9XDuA6dpG9Yv0PIPLFlk3BIUL1qEfUiYbDlrunkN/y4XromJaJPpgXKWraH194bqcgXGQLrCqicKwsRBoQJHg3ODWHjHFOwYODJ1XBsRcAue4J88PKiPV1tZNPVczMptrkqGBYTgOYGjKXGe5EH50RJE4/3Ynurz2s34DSDVJhJOYtGwpfeSuU3i3mVAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGAweCuWJmJXMUdRtgoFIiu6BGotDX5sA/VOm4CRsEXV7/qnBagrAPkRz86KGm4lOPL0X+I13JQh4/OB1gxnPN+BXhNtCWCoj1wA3/BWjs1ow/gaVXzwdy+1mbc/sUBudsLq2Yqs54GgeYsTBKMVpSLKiRg1NebEFlqFmG2hjPzYg1QHL4VBusMQgqt7TTnOfGtdT3Ss9TKGRQ+iwfNL0BtSAKaTRdhNVU4lDYUs788Kw5od/uJj0wTICKO5/PrkX7Uy42+fyU+4SvJynPOy+M+z+s08JC9+eYXixfeeFG1nNWR+DIKXcXaSwNQW+8RweGbOJxQ2BoUKtl0NCHrvxJw=\n-----END CERTIFICATE-----" } ``` -------------------------------- ### Download Root Certificate (Bash) Source: https://docs.servercore.com/managed-databases/mysql-semi-sync/connect-to-cluster This snippet demonstrates how to download the root certificate, save it to the `~/.mysql/` directory, and set appropriate file permissions. This is a prerequisite for establishing an SSL-encrypted connection. ```bash mkdir -p ~/.mysql/ wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.mysql/root.crt chmod 0600 ~/.mysql/root.crt ``` -------------------------------- ### Navigate to Network Class Registry Key (Windows) Source: https://docs.servercore.com/dedicated/manage/install-os-from-image This registry path allows access to network interface class information. It is used to identify and manage network adapters installed on the system. No specific input is required, but understanding the GUID is crucial. ```plaintext HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318} ``` -------------------------------- ### Apply Netplan Configuration and Verify Bond Interface (Ubuntu) Source: https://docs.servercore.com/dedicated/networks/mc-lag These commands apply the Netplan configuration for channel aggregation and verify the status of the bond interface. The `netplan --debug apply` command applies the changes, and `cat /proc/net/bonding/bond0` displays the bond status. ```bash netplan --debug apply ``` ```bash cat /proc/net/bonding/bond0 ``` -------------------------------- ### List Networks Response Sample (GET /v1/networks) Source: https://docs.servercore.com/api/global-router Example of a successful response when listing networks. It returns an array of network objects, each containing detailed information about a network. ```JSON [ { "id": "123e4567-e89b-12d3-a456-426655440000", "name": "Name", "vlan": 2, "router_id": "123e4567-e89b-12d3-a456-426655440000", "zone_id": "123e4567-e89b-12d3-a456-426655440000", "project_id": "123e4567e89b12d3a456426655440000", "vdc_name": "string", "updated_at": "2019-08-24T14:15:22Z", "created_at": "2019-08-24T14:15:22Z", "status": "IMMUTABLE", "account_id": "string", "sv_network_id": "123e4567-e89b-12d3-a456-426655440000", "netops_vlan_uuid": "123e4567-e89b-12d3-a456-426655440000", "tags": [ "resource_tag" ], "inner_vlan": 2, "os_network_id": "123e4567-e89b-12d3-a456-426655440000" } ] ``` -------------------------------- ### Connect to Database with SSL using Go (pgx) Source: https://docs.servercore.com/managed-databases/postgresql/connect-to-cluster This Go snippet shows how to connect to a database cluster securely using SSL with the `pgx` library. It requires downloading the root certificate and constructing a connection string that includes the database user, password, host, database name, SSL root certificate path, and SSL mode. The example queries the sum of 40+2. ```go package main import ( "context" "fmt" "os" "github.com/jackc/pgx/v4" ) func main() { connectionString := fmt.Sprintf("postgres://%s:%s@%s:/%s?sslmode=verify-ca&sslrootcert=%s", "", "", "", "", "" ) conn, err := pgx.Connect(context.Background(), connectionString) if err != nil { fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err) os.Exit(1) } defer conn.Close(context.Background()) var sum int64 err = conn.QueryRow(context.Background(), "SELECT 40+2").Scan(&sum) if err != nil { fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err) os.Exit(1) } fmt.Println(sum) } ``` -------------------------------- ### Windows Disk Management: Shrink Volume and Create New Partition Source: https://docs.servercore.com/dedicated/manage/autoinstall-os This guide explains how to partition disks in Windows using the built-in Disk Management utility. It covers shrinking an existing volume to create unallocated space and then creating a new simple volume from that space. This is useful for managing disk space and creating new partitions without third-party tools. ```bash diskmgmt.msc ``` ```text 1. Connect to the server via RDP or via KVM console. 2. Press the **Win** + **R** key combination. 3. Run the disk management utility: `diskmgmt.msc` 4. Right-click on the partition you want to split and select **Shrink Volume**. 5. In the **Enter the amount of space to shrink in MB** field, specify the size of the space to be allocated. 6. Click **Shrink**. The information about the selected space is displayed with the **Unallocated** mark. 7. Create a new partition by right-clicking on the highlighted space and selecting **New simple volume**. 8. In the **Simple volume size in MB** field, enter the size of the partition. 9. Optional: select a partition letter. 10. Specify the file system of the partition. 11. Click **Finish**. ``` -------------------------------- ### Get Resource by ID Response (JSON Example) Source: https://docs.servercore.com/api/email-service This JSON snippet shows the successful retrieval of a single email resource by its identifier. It includes all the details of the specified resource. ```json { "resource": { "created_at": "2024-05-26T15:16:53+00:00", "dedicated_sender": true, "dns_key": "xncFjGLFGkeq", "id": "448355c9-8c3a-4706-8ca4-ed2970fce631", "login": "1010", "name": "My SES Resource", "password": "NtV4FQscV5BQ", "project_id": "5c4272d6c6274435ae913cff6eceaf22", "status": "active", "updated_at": "2024-05-27T15:16:53+00:00" } } ``` -------------------------------- ### Install Multipath Tools Source: https://docs.servercore.com/block-storage/manage/connect-block-storage-to-proxmox Installs the necessary tools for configuring and managing MultiPath-IO (MPIO). ```bash apt install multipath-tools ``` -------------------------------- ### Kafka Consumer Example (Node.js) Source: https://docs.servercore.com/managed-databases/kafka/connect-to-cluster This Node.js code snippet demonstrates how to create a Kafka consumer. It connects to the Kafka cluster, subscribes to a specified topic, and processes incoming messages. Ensure you have the 'kafkajs' library installed. ```javascript const { Kafka } = require('kafkajs'); const config = { brokers: [':'], ssl: false, sasl: { mechanism: 'scram-sha-512', username: '', password: '', }, }; const kafka = new Kafka(config); const consumer = kafka.consumer({ groupId: 'example' }); const run = async () => { await consumer.connect(); await consumer.subscribe({ topic: '', fromBeginning: true, }); await consumer.run({ eachMessage: async ({ message }) => { console.log({ value: message.value.toString() }); }, }); }; run(); ``` -------------------------------- ### Create Directory and Download File using Bash Script Source: https://docs.servercore.com/managed-kubernetes/node-groups/user-data This bash script creates a directory named '/run/mydir' and then downloads a file from 'http://example.com' into it, saving it as 'index.html'. This functionality is identical to the cloud-config example but implemented directly in bash. ```bash #!/bin/bash mkdir /run/mydir wget http://example.com -O /run/mydir/index.html ``` -------------------------------- ### Kafka Producer Example (Node.js) Source: https://docs.servercore.com/managed-databases/kafka/connect-to-cluster This Node.js code snippet shows how to create a Kafka producer. It connects to the Kafka cluster and sends a single message to a specified topic. It then disconnects from the cluster. Ensure you have the 'kafkajs' library installed. ```javascript const { Kafka } = require('kafkajs'); const config = { brokers: [':'], ssl: false, sasl: { mechanism: 'scram-sha-512', username: '', password: '', }, }; const kafka = new Kafka(config); const producer = kafka.producer(); const run = async () => { await producer.connect(); await producer.send({ topic: '', messages: [{ value: 'message' }], }); await producer.disconnect(); }; run(); ``` -------------------------------- ### Apply Netplan Configuration Source: https://docs.servercore.com/dedicated/networks/internet-via-cloud These commands are used to test and apply network configuration changes made via Netplan on Ubuntu. 'netplan try' allows you to preview changes, and 'netplan apply' makes them persistent. Use with caution as incorrect configurations can disrupt network connectivity. ```bash sudo netplan try ``` ```bash netplan apply ``` -------------------------------- ### Connect to Redis Cluster with Predis (PHP) Source: https://docs.servercore.com/managed-databases/redis/connect-to-cluster Illustrates connecting to a Redis cluster using the Predis library in PHP. It covers installing the library via composer, setting and getting a key, and disconnecting. Requires the 'predis/predis' package. ```bash composer require predis/predis ``` ```php :']; $options = [ 'parameters' => [ 'password' => "" ], 'cluster' => 'predis' ]; $conn = new PredisClient($host, $options); $conn->set('KEY', 'VALUE'); var_dump($conn->get('KEY')); $conn->disconnect(); ?> ```