## Cấu hình máy ảo
- 1 máy DC và 1 máy SQL server - 2x2 (4 cores), 8gb RAM, 60gb disk
- 1 máy chạy Sharepoint - 2x2 (4 cores), 16gb RAM, 120gb disk
Bài viết này dựa trên cách setup https://gist.github.com/testanull/e1573437f91ec3726ab5041389c6f28d mn nên đọc trước bài này để biết những phần cần setup để folow theo dễ hiểu.
## Domain Controller and SQL Server Setup
### Setup server

Update win và rename thì tuỳ ý đổi.
Config DNS như sau:

Lấy ipv4 để nhập vào dưới đây:
- Control Panel → Network and Sharing Center → Change adapter settings.
- Nhấn chuột phải vào Ethernet (hoặc card mạng đang dùng) → chọn Properties.
- Chọn dòng Internet Protocol Version 4 (TCP/IPv4) → nhấn Properties

## Setup DC

- Add role and feature

- Setup domain controller

Để thêm 3 account sau:
```
sp_farmadmin – tài khoản quản trị farm SharePoint
sp_service – tài khoản chạy các dịch vụ SharePoint
sql_service – tài khoản chạy dịch vụ SQL Server
```
Mở `Active Directory Users and Computers` -> Click chuột phải vào domain của bạn (ví dụ dc.lab) → New → `Organizational Unit` -> Nhập tên: ServiceAccounts → Nhấn OK.

Tạo `sp_farmadmin`:
Click chuột phải vào OU ServiceAccounts → New → User.
```
First name: SharePoint
Last name: FarmAdmin
User logon name: sp_farmadmin
-> Nhấn Next.
Nhập mật khẩu (ví dụ: P@ssw0rd123!) và:
Bỏ chọn “User must change password at next logon”
Chọn “Password never expires”
-> Nhấn Next → Finish.
```
Tương tự cho `sp_service` và `sql_service`
```
sp_service
First name: SharePoint
Last name: Service
Username: sp_service
sql_service
First name: SQL
Last name: Service
Username: sql_service
```

## SQL server
### Cài đặt SQL Server 2019 Express

- Setup DNS

- Join domain
+ Vào System Properties (chuột phải This PC > Properties > Change settings)
+ Nhấn nút Change... -> Chọn Domain, nhập: dc.lab (domain setup ở DC) -> Nhập tài khoản domain có quyền join (Administrator)
+ Reset máy

- Firewall open port 1433
```
netsh advfirewall firewall add rule name="SQLPort" dir=in action=allow protocol=TCP localport=1433
```
Powershell:
```
New-NetFirewallRule -DisplayName "Allow SQL Port 1433" -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow
```

Cài đặt SQL Server version: SQL Server 2019 Express (https://www.microsoft.com/en-us/download/details.aspx?id=101064)

Trong `Feature Selection` bỏ chọn `Machine Learning Services …`

Chỉnh account của `SQL Server Database Engine` thành `sql_service`

Trong màn hình `Database Engine Configuration` thực hiện chọn `Add` -> nhập `sp_farmadmin`.
Danh sách “SQL Server administrators” nên bao gồm:
```
SQL-SERVER\Administrator
DC\sp_farmadmin
```

Sau khi `Next` hết thì success như sau

### Cấu hình SQL Server
Thực hiện `Install SQL Server Mangement Tools`

Khi click vào ở trên thì sẽ được open 1 trang web như dưới và chọn vào phần tô đỏ để download.

Sau khi tải về thì mở lên và connect như sau:
- `Server Name` -> `SQL-SERVER\SQLEXPRESS`
- `Authentication` giữ nguyên `Windows Authentication` và connect
Change role cho cho tài khoản `sp_farmadmin` là `dbcreator` và `securityadmin`

Thực hiện bật TCP/IP cho SQL Server:


## Sharepoint

Join domain như ở bước setup SQL server
Để add account `sp_farmadmin` vào nhóm `Administrators` thì đầu tiên login bằng tài khoản local admin trước (Administrator)
Thực hiện add account `sp_farmadmin` vào group `Administrator` tại `Computer Management` → `Local Users and Groups` → `Groups` → mở nhóm Administrators -> Nhấn `Add`. Sau đó nhập `sp_farmadmin` -> Nhấn `Check Names → OK → OK`

Add thành công thì logout tài khoản local admin và đăng nhập bằng tài khoản `sp_farmadmin` để thực hiện setup sharepoint.
### Cài đặt SharePoint 2019
Download sharepoint tại `https://www.microsoft.com/en-us/download/details.aspx?id=57462`

Sau khi tải xong file chạy `PrerequisiteInstaller.exe`

Chạy xong thì restart máy và tiếp tục chạy `setup.exe` và nhập key. Cài xong lại tiếp tục restart máy.
```
Enterprise Trial: M692G-8N2JP-GG8B2-2W2P7-YY7J6
Standard trial product key: F2DPD-HPNPV-WHKMK-G7C38-2G22J
```

### Cấu hình Sharepoint
Chạy SharePoint Products Configuration Wizard
- Tạo New Farm

- Database server chỗ này nhập ip đừng nhập hostname và dùng farm service account `sp_service@dc.lab`

- Server role: Single-Server Farm

Tới đây chọn Next là xong.

Request tới http://sp:41296/default.aspx

Vậy là đã cấu hình xong `Central Administration`. Bây giờ đến phần chạy `Initial Farm Configuration Wizard`. Thực hiện login Sharepoint bằng tài khoản `Administrator`. Dùng `sp_farmadmin` sẽ bị denied.
Nhấp vào phần `Configuration Wizards` (góc dưới bên phải) -> → `Launch the Farm Configuration Wizard`

Tiếp tục chọn `Start the Wizard`.

Khi vào được tới giao diện như dưới đây thì chọn và nhập như sau:

- Chọn `User Profile Service Application` (bắt buộc)
- Tích `Use existing managed account` (account sp_service)
- Ngoài ra có thể tick thêm những cái như:
- App Management Service
- Workflow Service
- Business Data Connectivity Service
- Search Service (nếu cần)
Ở đây mình hầu hết là để mặc định chỉ xem đã chọn `User Profile Service Application` và dùng account là `sp_service` hay chưa.
Sau khi ấn `Next` và chờ thì nếu có lỗi như dưới đây thì có thể vào `Timer Job Status ` để xem tiến trình hoàn thành chưa.


Sau khi cấu hình các Service xong, wizard sẽ hỏi bạn tạo một site collection đầu tiên:
- Web Path: / (tức là root site: http://sp:port/)
- Template: chọn một trong các loại:
- Team Site – Dành cho làm việc nhóm (có lịch, tài liệu, task list…)
- Communication Site – Dành cho truyền thông nội bộ, trình bày nội dung đẹp hơn.
Chỉ cần:
Đặt Title, URL (mặc định là /), chọn template phù hợp rồi OK để hoàn tất.

Để check setup thành công chưa thì sau khi hoàn tất bước trên thì truy cập vào http://sp và login nếu hiện thị ra home page như dưới đây thì đã thành công.

Tới đây nên snapshot cả 2 máy: `SQL` và `SharePoint`.
Sau đó Apply bản vá bảo mật mong muốn cho SharePoint.
### Ref:
https://gist.github.com/testanull/e1573437f91ec3726ab5041389c6f28d