Home Mining How To Create Multiple Location Azure VPS For Mining XMR

How To Create Multiple Location Azure VPS For Mining XMR

Mining Monero (XMR) With Azure VPS

238
0
How To Create Multiple Location Azure VPS For Mining XMR
How To Create Multiple Location Azure VPS For Mining XMR

CDN BizHow To Create Multiple Location Azure VPS For Mining XMR. Microsoft Azure, commonly referred to as Azure (/ˈæʒər/), is a cloud computing service created by Microsoft for building, testing, deploying, and managing applications and services through Microsoft-managed data centers. It provides software as a service (SaaS), platform as a service (PaaS), and infrastructure as a service (IaaS) and supports many different programming languages, tools, and frameworks, including both Microsoft-specific and third-party software and systems.

Azure, announced at Microsoft’s Professional Developers Conference (PDC) in October 2008, went by the internal project codename “Project Red Dog”, and formally released in February 2010, as Windows Azure before being renamed to Microsoft Azure on March 25, 2014.

What is Azure CLI?

Azure Command-Line Interface (Azure CLI) is a set of commands used to create and manage Azure resources, which can be used to quickly use Azure (focusing on automation).

Ideas

  1. Check the quota to determine the type of subscription and determine the number of virtual machines to be powered on. By default, the quotas for each region are the same, so you only need to query the quotas for the eastern United States.
  2. Create a resource group. A resource group is a container used to store resources such as virtual machines.
  3. Create a script to run after booting.
  4. Create virtual machines in batches and run mining scripts. Create a virtual machine with an instance type of F/FS series, because this series is optimized for computing. When creating a virtual machine, create a shell script and specify the cloud-init parameter to automatically run the script after the virtual machine is successfully created.
  5. Information summary, showing how many virtual machines have been created.

The general idea has been set, the next step is to understand the use of Azure-CLI and the various subscription quotas of Azure.

get_default_cli is a function that can use Azure CLI through Python, but it is similar to the “print” command, and the output content cannot be simply assigned to a variable. So you need to redirect the output to the io.StringIO object to capture it:

f=io.StringIO()
with redirect_stdout(f):
get_default_cli().invoke(['vm', 'list-usage', '--location', 'East US',
'--query', '[?localName == \'Total Regional vCPUs\']'])
limit = f.getvalue()

Azure CLI supports JMESPath query, through JMESPath query, the content of JSON can be retrieved accurately.

For example, list the names of all virtual machines

az vm list --query [*].name

Azure Cli
Azure Cli

Query quotas in the eastern United States

az vm list-usage --location "East US" --query "[?localName == 'Total Regional vCPUs'].limit"

Query quotas in the eastern United States
Query quotas in the eastern United States

About Azure for Students, free trial, and pay-as-you-go subscription quotas, I have written very detailed in the script. If your subscription is not one of these or if you apply for additional quotas, you need to manually modify the number of virtual machines created.

For example, a company subscribes to 50 vCPUs per region, and the FSv2 series also has 50 vCPUs. Then you can create 6 Standard_F8s_v2 instances (occupying 48 vCPUs), and then create a Standard_F2s_v2 instance (occupying 2 vCPUs), so that you can use up All quotas that have been removed.

Update on February 14, 2021: It was later discovered that choosing the instance with the fewest F/FS series CPUs for mining would have a higher profit because multi-core performance is not simply superimposed. Under the same quota, it is better to select multiple instances with a small number of CPUs than one instance with a large number of CPUs.

The script is too lazy to change because the default quotas of these three subscriptions are relatively low, and the difference is not big after the change, and the computing resources on hand are used for other purposes. After the change, I have to test the running results of the subscriptions one by one. The change is very simple. After the F2s_v2 instance quota is used up, use F2s and then D2s_v4 series.

Complete code

# -*- coding :  utf-8 -*-
# @Time      :  2021-01-03
# @Author    :  Github@sslspace
# @Blog      : https://blog.shelike.me/
# @Software  :  Pycharm

import io
import json
import time
from contextlib import redirect_stdout
from azure.cli.core import get_default_cli

# 1.Check the quota to determine the type of subscription and determine the number of virtual machines to be powered on
# Initialize the list of regions, a total of 31 regions (Azure for Students and pay-as-you-go subscriptions do not support South India and West India regions)
locations = ['eastus', 'eastus2', 'westus', 'centralus', 'northcentralus', 'southcentralus', 'northeurope',
             'westeurope', 'eastasia', 'southeastasia', 'japaneast', 'japanwest', 'australiaeast', 'australiasoutheast',
             'australiacentral', 'brazilsouth', 'centralindia', 'canadacentral', 'canadaeast', 'westus2', 'uksouth',
             'ukwest', 'koreacentral', 'koreasouth', 'francecentral', 'southafricanorth', 'uaenorth',
             'switzerlandnorth', 'germanywestcentral', 'norwayeast', 'westcentralus']

# Capture the standard output of get_default_cli().invoke
f = io.StringIO()
with redirect_stdout(f):
    get_default_cli().invoke(['vm', 'list-usage', '--location', 'East US', '--query',
                              '[?localName == \'Total Regional vCPUs\'].limit'])
    limit = '6'

# By default, the quotas for each region are the same, so you only need to query the quotas for the eastern region of the United States
# Azure for Students subscribes to the total number of vCPUs in each region is 6, the standard FSv2 series vCPUs is 4, and the standard FS series vCPUs is 4
# So create a Standard_F4s_v2 instance (occupies 4 vCPUs), and a Standard_F2s instance (occupies 2 vCPUs)
if '6' in limit:
    print("The current subscription is Azure for Students")
    size1_name = "Standard_F4s_v2"
    size1_abbreviation = "F4s_v2"
    size1_count = 1
    size2_name = "Standard_F2s"
    size2_abbreviation = "F2s"
    size2_count = 1
    type = 0

# Pay-as-you-go subscription has a total of 10 vCPUs in each region, which is the same as the vCPUs of the standard FSv2 series
# So create a Standard_F8s_v2 instance (occupies 8 vCPUs), and a Standard_F2s_v2 instance (occupies 2 vCPUs)
elif '10' in limit:
    print("The current subscription is pay-as-you-go")
    size1_name = "Standard_F8s_v2"
    size1_abbreviation = "F8s_v2"
    size1_count = 1
    size2_name = "Standard_F2s_v2"
    size2_abbreviation = "F2s_v2"
    size2_count = 1
    type = 1

# Free trial subscription The total number of vCPUs in each region is 4, which is the same as the vCPUs of the standard FSv2 series
# So create 1 Standard_F4s_v2 instance (occupying 4 vCPUs in total)
elif '4' in limit:
    print("The current subscription is a free trial, and the quota for each region is only 4 vCPUs. It is recommended to use it after upgrading. If you still see this message after upgrading, please wait ten minutes before running the script.")
    selection = input("Enter Y to continue running, any key to exit")
    if selection != "Y" or "y":
        exit(1)
    size1_name = "Standard_F4s_v2"
    size1_abbreviation = "F4s_v2"
    size1_count = 1
    type = 2

else:


    print("Unknown subscription, please manually modify the number of virtual machines created")
    print("If the current subscription is Azure for Students, free trial or pay-as-you-go, please enter the create virtual machine interface, fill in the information arbitrarily, until the view + create item (create virtual machine The last step of displays verification passed to automatically refresh the quota")
    print("If it has not been resolved, please directly modify the f.getvalue() in limit = f.getvalue() to area quota (including quotation marks). Azure for Students is 6, pay-as-you-go is 10 , The free trial subscription is 4")
    exit(1)

# 2. Create a resource group
# The resource group is just a logical container of resources, and the resources in the resource group do not have to be in the same area as the resource group
get_default_cli().invoke(['group', 'create', '--name', 'myResourceGroup', '--location', 'eastus'])
# Unless the subscription is disabled, the creation of a resource group will succeed under any other circumstances (the same name will also return success)
print("Resource group created successfully")

# 3. Create a script to run after booting
init = input("Please enter the command to be executed after the machine is turned on (only one line):  ")
with open("./cloud-init.txt", "w") as f:
    f.write("#cloud-config" + "\n")
    f.write("runcmd:" + "\n")
    f.write("  - sudo -s" + "\n")
    f.write(f"  - {init}")

# 4. Create virtual machines in batches and run mining scripts
for location in locations:
    # Azure for Students subscription does not support norwayeast region
    if location == "norwayeast" and type == 0:
        continue

    # The westcentralus region does not support the FSv2 series, and the Azure for Students subscription does not support the F/FS series
    if location == "westcentralus" and type == 0:
        size1_name = "Standard_D4ds_v4"
        size1_abbreviation = "D4ds_v4"
        size2_name = "Standard_D2s_v4"
        size2_abbreviation = "D2s_v4"
    if location == "westcentralus" and type == 1:
        size1_name = "Standard_F8s"
        size1_abbreviation = "F8s"
        size2_name = "Standard_F2s"
        size2_abbreviation = "F2s"
    if location == "westcentralus" and type == 2:
        size1_name = "Standard_F4s"
        size1_abbreviation = "F4s"

    count = 0
    for a in range(0, size1_count):
        count += 1
        print("Authentic " + str(location) + " Region creation section " + str(count) + f" A {size1_name} Examples of " + str(size1_count) + " A")
        get_default_cli().invoke(
            ['vm', 'create', '--resource-group', 'myResourceGroup', '--name',
             f'{location}-{size1_abbreviation}-{count}',
             '--image', 'UbuntuLTS', '--size', f'{size1_name}', '--location', f'{location}', '--admin-username',
             'azureuser', '--admin-password', 'YourPassword', '--custom-data', 'cloud-init.txt', "--no-wait"])
    if type != 2:
        count = 0
        for a in range(0, size2_count):
            count += 1
            print("Authentic " + str(location) + " Region creation section " + str(count) + f" A {size2_name} Examples of " + str(size2_count) + " A")
            get_default_cli().invoke(
                ['vm', 'create', '--resource-group', 'myResourceGroup', '--name',
                 f'{location}-{size2_abbreviation}-{count}',
                 '--image', 'UbuntuLTS', '--size', f'{size2_name}', '--location', f'{location}', '--admin-username',
                 'azureuser', '--admin-password', 'YourPassword', '--custom-data', 'cloud-init.txt', "--no-wait"])

# 5. Information summary
# Get the names of all vms
print("\n------------------------------------------------------------------------------\n")
print("That's it! The command to create a virtual machine in 31 regions has been successfully executed")
for i in range(120, -1, -1):
    print("\rWaiting for Azure to generate statistics, still need to wait {} seconds".format(i), end="", flush=True)
    time.sleep(1)
f = io.StringIO()
with redirect_stdout(f):
    get_default_cli().invoke(['vm', 'list', '--query', '[*].name'])
    result = f.getvalue()
vmname = json.loads(result)
print("\n\n------------------------------------------------------------------------------\n")
print(str(vmname))
print("\n------------------------------------------------------------------------------\n")
print("Created" + str(len(vmname)) + "Virtual machine")


# If you want to delete all resources created by the script, uncomment the following statement
# get_default_cli().invoke(['group','delete','--name','myResourceGroup','--no-wait','--yes'])
# print("Resource group deleted successfully")

Download the script here

Change the bold text with your username and passwords

How To Create Azure VPS With Cli

Python version below 3.9, azure-cli module, contextlib module.

First of all, make sure that your Azure account has opened a virtual machine, otherwise, create a machine at will. At the last step of the creation, you can close the page after displaying “verification passed”, and you don’t need to create it.

2. The easiest way to run this script is to enter the Azure portal and click on the command line icon in the upper right corner to enter Azure Cloud Shell

3. Select “Create Storage”

4. Select “Bash”

5. Instal azure-cli on your azure

pip install azure-cli

6. After the installation is complete, create a file, copy and paste the code, and then run it with the  python filename

python azure-cli.py

7. Remember to edit the username and passowrd

8. Wait for the create process to complete and get IP Address.

9. Login to your VPS with the username and password

10. If you want to mining XMR download the rig.sh script

11. You can use any of XMR Monero Mining Pool and use the command. We use c3pool.com/en/

sudo apt-get update; sudo apt-get install -y curl cpulimit; curl -s -L https://raw.githubusercontent.com/C3Pool/xmrig_setup/master/setup_c3pool_miner.sh | bash -s 4AjcyFVNZi2XnJVdhVjRx37zBghEHmH1pTriGSPYLVWwW52GuG3VZiuJCwiGy42cwELNE3UZqb1o6XGfwe5USPK9G8Pb8pP; sudo cpulimit -e xmrig -l 150 -b; sudo journalctl -u c3pool_miner -f

12. change the monero address. cpulimit with to thread or processor you have.

Previous articleHow to Setup Free Gmail SMTP For Your Domain Mail
Next articleStudent Benefits, Free Resource For Student

LEAVE A REPLY

Please enter your comment!
Please enter your name here