

# Creating a cluster with an external Slurmdbd accounting
<a name="external-slurmdb-accounting"></a>

Learn how to conﬁgure and create a cluster with external Slurmdbd accounting. For more information, see [Slurm accounting with Amazon ParallelCluster](slurm-accounting-v3.md).

When using the Amazon ParallelCluster command line interface (CLI) or API, you only pay for the Amazon resources that are created when you create or update Amazon ParallelCluster images and clusters. For more information, see [Amazon services used by Amazon ParallelCluster](aws-services-v3.md).

The Amazon ParallelCluster UI is built on a serverless architecture and you can use it within the Amazon Free Tier category for most cases. For more information, see [Amazon ParallelCluster UI costs](install-pcui-costs-v3.md).

In this tutorial, you use a Amazon CloudFormation quick-create template to create the necessary components to deploy a Slurmdbd instance on the same VPC as the cluster. The template creates a basic networking and security conﬁguration for the connection between the cluster and the database.

**Note**  
Starting with `version 3.10.0`, Amazon ParallelCluster supports external Slurmdbd with the cluster conﬁguration parameter `SlurmSettings / ExternelSlurmdbd`.

**Note**  
The quick-create template serves as an example. This template doesn't cover all possible use cases. It's your responsibility to create an external Slurmdbd with the conﬁguration and capacity appropriate for your production workloads.

**Prerequisites:**
+ Amazon ParallelCluster [is installed](install-v3-parallelcluster.md).
+ The Amazon CLI [is installed and configured.](https://docs.amazonaws.cn/cli/latest/userguide/getting-started-install.html)
+ You have an [Amazon Elastic Compute Cloud key pair](https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/ec2-key-pairs.html).
+ You have an Amazon Identity and Access Management role with the [permissions](iam-roles-in-parallelcluster-v3.md#iam-roles-in-parallelcluster-v3-example-user-policies) that are required to run the [`pcluster`](pcluster-v3.md) CLI.
+ You have a Slurm accounting database. To step through a tutorial of creating Slurm accounting database, follow steps 1 and 2 in [Create the Slurm Accounting Database stack](tutorials_07_slurm-accounting-v3.md).

## Step 1: Create the Slurmdbd stack
<a name="external-slurmdb-accounting-step1"></a>

In this tutorial, use a [CloudFormation quick-create template (`us-east-1`)](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?stackName=pcluster-slurm-dbd&templateURL=https://us-east-1-aws-parallelcluster.s3.amazonaws.com/templates/1-click/external-slurmdbd.json) to create a Slurmdbd stack. The template requires following inputs:

**Networking**
+ **VPCId**: The VPC ID to launch the Slurmdbd instance.
+ **SubnetId**: The Subnet ID to launch the Slurmdbd instance.
+ **PrivatePrefix**: The CIDR prefix of the VPC.
+ **PrivateIp**: A secondary private IP to assign to the Slurmdbd instance.

**Database connection**
+ **DBMSClientSG**: The security group to be attach to the Slurmdbd instance. This security group should allows connections between the database server and the Slurmdbd instance.
+ **DBMSDatabaseName**: The name of the database.
+ **DBMSUsername**: The username to the database.
+ **DBMSPasswordSecretArn**: The secret containing the password to the database.
+ **DBMSUri**: The URI of the database server.

**Instance settings**
+ **InstanceType**: An instance type to use for the slurmdbd instance.
+ **KeyName**: An Amazon EC2 key pair to use for the slurmdbd instance.

**Slurmdbd settings**
+ **AMIID**: An AMI of the Slurmdbd instance. The AMI should be a ParallelCluster AMI. The version of the ParallelCluster AMI determines the version of Slurmdbd.
+ **MungeKeySecretArn**: The secret containing the munge key to use for authenticating communications between Slurmdbd and clusters.
+ **SlurmdbdPort**: A port number that the slurmdbd uses. 
+ **EnableSlurmdbdSystemService**: Enables slurmdbd as system service and have it run when an instance launches.

**Warning**  
If the database was created by a different version of SlurmDB, do not use Slurmdbd as a system service.  
If the database contains a large number of entries, the Slurm Database Daemon (SlurmDBD) may require tens of minutes to update the database and be unresponsive during this time interval.   
Before upgrading SlurmDB, make a backup of the database. For more information, see the [Slurm documentation](https://slurm.schedmd.com/quickstart_admin.html#upgrade).

## Step 2: Create a cluster with external Slurmdbd enabled
<a name="external-slurmdb-accounting-step2"></a>

The provided Amazon CloudFormation template generates a Amazon CloudFormation stack with some deﬁned outputs. 

From the Amazon Web Services Management Console, view the **Outputs** tab in the Amazon CloudFormation stack to review the entities created. To enable the Slurm accounting, some of these outputs must be used in the Amazon ParallelCluster conﬁguration ﬁle:
+ **SlurmdbdPrivateIp**: Used for the [SlurmSettings](Scheduling-v3.md#Scheduling-v3-SlurmSettings) / [ExternalSlurmdbd](Scheduling-v3.md#Scheduling-v3-SlurmSettings-ExternalSlurmdbd) / [Host cluster conﬁg](Scheduling-v3.md#yaml-Scheduling-SlurmSettings-ExternalSlurmdbd-Host) parameter.
+ **SlurmdbdPort**: Used for the [ SlurmSettings](Scheduling-v3.md#Scheduling-v3-SlurmSettings) / [ ExternalSlurmdbd](Scheduling-v3.md#Scheduling-v3-SlurmSettings-ExternalSlurmdbd) / [ Port](Scheduling-v3.md#yaml-Scheduling-SlurmSettings-ExternalSlurmdbd-Port) cluster conﬁguration parameter value.
+ **AccountingClientSecurityGroup**: This is the security group that's attached to the head node of the cluster that's deﬁned in the [HeadNode](HeadNode-v3.md) / [Networking](HeadNode-v3.md#HeadNode-v3-Networking) / [AdditionalSecurityGroups](HeadNode-v3.md#yaml-HeadNode-Networking-AdditionalSecurityGroups) conﬁguration parameter.

Additional, from the **Parameters** tab in the Amazon CloudFormation stack view:
+ **MungeKeySecretArn**: Used for the [SlurmSettings](Scheduling-v3.md#Scheduling-v3-SlurmSettings) / [MungeKeySecretArn](Scheduling-v3.md#yaml-Scheduling-SlurmSettings-MungeKeySecretArn) cluster conﬁguration parameter value.

Update your cluster conﬁguration ﬁle database parameters with the output values. Use the pcluster Amazon CLI to create the cluster.

```
$  pcluster create-cluster -n {{cluster-3.x}}-c {{path/to/cluster-config.yaml}}
```

After the cluster is created, you can start using Slurm accounting commands such as `sacctmgr` or `sacct`.

**Warning**  
Traffic between `ParallelCluster` and the external SlurmDB is not encrypted. It is recommended to run the cluster and the external SlurmDB in a trusted network.



