如何使用Rsync命令同步两个Samba4 AD DC之间的SysVol目录
如何使用Rsync命令同步两个Samba4 AD DC之间的SysVol目录
Samba4 Active Directory Domain Controllers (AD DCs) can use the rsync command to synchronize their SysVol directories. This can be useful when replicating AD DCs across multiple sites.
The rsync command is a versatile tool that can be used for a variety of purposes. In this article, we will show you how to use rsync to synchronize the SysVol directories of two Samba4 AD DCs.
Before we begin, you will need to have two Samba4 AD DCs up and running. For this tutorial, we will be using two CentOS 7 servers.
On Server 1, we will install and configure Samba4 as an AD DC. On Server 2, we will install Samba4, but we will not configure it as an AD DC. We will only use it to sync the SysVol directory from Server 1.
Installing Samba4 on Server 1
First, we will install Samba4 on Server 1. Samba4 is available in the default repositories of most Linux distributions.
On CentOS 7, we can install Samba4 using the yum package manager:
yum install samba4
Once Samba4 is installed, we can start the Samba daemons and enable them to start automatically at boot time:
systemctl start smb systemctl enable smb
Configuring Samba4 as an AD DC
Next, we will configure Samba4 as an AD DC. We will use the samba-tool utility to create a new AD DC.
Before we can use samba-tool, we need to create a DNS zone for our AD domain. In this tutorial, we will be using the domain name ad.example.com.
We can create a DNS zone for our AD domain using the samba-tool dns zonecreate command:
samba-tool dns zonecreate ad.example.com 127.0.0.1 -U Administrator
Replace ad.example.com with your own AD domain name.
Next, we will use the samba-tool domain provision command to provision a new AD DC. This command will create a new AD domain and configure the Samba server as an AD DC.
We need to provide a few parameters to the samba-tool domain provision command. The --realm parameter specifies the AD domain name. The --server-role parameter specifies the role of the Samba server. In our case, we want to configure the Samba server as an AD DC, so we will set it to dc.
We will also use the --dns-backend parameter to specify that we want to use the Samba internal DNS server.
samba-tool domain provision --realm=ad.example.com --server-role=dc --dns-backend=SAMBA_INTERNAL
Once the AD DC is provisioned, we need to configure Samba to start automatically at boot time:
systemctl enable samba-ad-dc
Installing Samba4 on Server 2
Next, we will install Samba4 on Server 2. We can install Samba4 using the yum package manager:
yum install samba4
Once Samba4 is installed, we can start the Samba daemons and enable them to start automatically at boot time:
systemctl start smb systemctl enable smb
Configuring Server 2 to Sync the SysVol Directory from Server 1
Now that Samba4 is installed on both servers, we can configure Server 2 to sync the SysVol directory from Server 1.
We will use the rsync command to sync the SysVol directory from Server 1 to Server 2. The rsync command is a versatile tool that can be used for a variety of purposes. In this case, we will use it to synchronize the SysVol directory of two Samba4 AD DCs.
First, we need to create a directory on Server 2 that will be used to store the synchronized SysVol directory. In this tutorial, we will use the /var/lib/samba/sysvol directory.
We can create the /var/lib/samba/sysvol directory using the mkdir command:
mkdir /var/lib/samba/sysvol
Next, we will use the rsync command to sync the SysVol directory from Server 1 to Server 2. We need to provide a few parameters to the rsync command.
The -avz parameter tells rsync to run in archive mode, which will preserve the permissions, ownership, and timestamps of the files that are being synchronized. The -e parameter specifies the SSH command to use for connecting to the remote server. In our case, we will use the ssh command.
The root@server1:/var/lib/samba/sysvol/ parameter specifies the source directory on Server 1. The /var/lib/samba/sysvol/ parameter specifies the destination directory on Server 2.
rsync -avz -e 'ssh -p 22' root@server1:/var/lib/samba/sysvol/ /var/lib/samba/sysvol/
Replace server1 with the IP address or hostname of your Server 1.
Once the SysVol directory has been synchronized, we need to set the proper permissions on the /var/lib/samba/sysvol directory. We can do this using the chown and chmod commands:
chown -R root:root /var/lib/samba/sysvol chmod -R 0700 /var/lib/samba/sysvol
Testing the Synchronization
Now that the SysVol directory has been synchronized, we can test the synchronization by creating a test file on Server 1 and verifying that it appears on Server 2.
First, we will create a test file on Server 1. We can do this using the touch command:
touch /var/lib/samba/sysvol/ad.example.com/testfile
Next, we will use the rsync command to sync the SysVol directory from Server 1 to Server 2. We will use the same command that we used earlier:
rsync -avz -e 'ssh -p 22' root@server1:/var/lib/samba/sysvol/ /var/lib/samba/sysvol/
Finally, we will check the /var/lib/samba/sysvol directory on Server 2 to verify that the test file appears:
ls -l /var/lib/samba/sysvol/ad.example.com/testfile
If the test file appears, then the synchronization is working properly.
相关文章