從零構建ipa-server.實現ldap+kerberos域用戶驗證(開放防火墻,命令版)
1,實驗環境:
一臺主機物理主機兩臺虛擬機。
物理主機的ip:192.168.9.6/24 gw:192.168.9.254 dns:8.8.8.8
一臺虛擬機(server)網卡類型為自動橋接:ip:192.168.9.4/24 gw:192.168.9.254 dns不用配置,裝ipa-server 會自動配置
一臺虛擬機(client)網卡類型為自動橋接:ip:192.168.9.5/24 gw:192.168.9.254 dns:192.168.9.4
2,IPA-server服務安裝前條件:
1,必須要有完整的主機名
2,一個靜態的ip地址
3,能夠對主機名做解析(正向和反向解析)
5,開通防火墻規則和服務
6, 做時間ntp同步
3,步驟
1,設置主機名
[root@localhost ~]# hostnamectl set-hostname server.zhuxu.vip```
[root@localhost ~]# hostname server.zhuxu.vip
2,一個靜態的ip地址上面準備工作已經完成
3,能夠對主機名做解析(正向和反向解析) 裝ipa-server 會自動配置
4,hosts文件也要對主機名做解析。不能解析到127.1
[root@server ~]# vim /etc/hosts
添加192.168.9.4 server.zhuxu.vip
5,開通防火墻規則和服務
TCP Ports:
* 80, 443: HTTP/HTTPS
* 389, 636: LDAP/LDAPS
* 88, 464: kerberos
* 53: bind
UDP Ports:
* 88, 464: kerberos
* 53: bind
* 123: ntp
[root@server ~]# iptables -F 清除iptables規則
[root@server ~]# systemctl stop iptables 停止iptables服務
[root@server ~]# systemctl disable iptables 禁止iptables 開機啟動
開放相應的端口
[root@client ~]# firewall-cmd --permanent
--add-port={80/tcp,443/tcp,389/tcp,636/tcp,88/tcp,464/tcp,53/tcp,88/udp,464/udp,53/udp,123/udp}
放行 http https ldap ldaps kerberos dns ntp
[root@server ~]# firewall-cmd --permanent --add-service={http,https,ldap,ldaps,kerberos,dns,ntp}
放行tcp的7389端口
[root@server ~]# firewall-cmd --permanent --add-port=7389/tcp
重新加載firewalld
[root@server ~]# firewall-cmd --reload
我已經查過了,這些端口都是selinux的安全端口,不需要開放安全端口。
[root@server ~]# semanage port -l --來查看selinux開放的安全端口
6,vim /etc/chrony.conf 註釋前三個時間服務,編輯最後一個為:server ntp1.aliyun.com iburst
[root@server ~]#systemctl restart chronyd.service 重啟時間服務
7,配置好yum源,我這選擇掛載光盤來做yum倉庫。
[root@server ~]# vim /etc/yum.repos.d/server.repo
在文件中輸入以下內容
[base]
name=redhat7
baseurl=file:///mnt
enabled=1
gpgcheck=0
掛載光盤到/mnt下(請確保光盤是連接狀況)
[root@server ~]# mount /dev/cdrom /mnt
服務器端安裝條件準備好了:
## 4,安裝ipa-server
ipa-server 依賴於dns服務才能工作,我們要裝的包有:ipa-server bind bind-dyndb-ldap ipa-server-dns
bind 是提供dns服務,bind-dyndb-ldap是提供dns和ldap連接組件等,
ipa-server-dns提供了ipa-server與dns連接組件等(根據安裝系統時候選的包不同,這個包有可能裝過了)
[root@server ~]# yum install -y ipa-server bind bind-dyndb-ldap ipa-server-dns
5,配置ipa-server
[root@server ~]# ipa-server-install --setup-dns ---安裝ipa-server自動配置dns
Server host name [server.zhuxu.vip]: ---回車鍵(默認)
Please confirm the domain name [zhuxu.vip]: ---回車鍵(默認)
Please provide a realm name [ZHUXU.VIP]: ---回車鍵(默認)
Directory Manager password: ---設置目錄管理的密碼 最少是8位
IPA admin password: ---設置ipa 管理員admin的密碼 最少8位 一定要記住,後面要用到
Do you want to configure DNS forwarders? [yes]: no ---你想配置dns為轉發器嗎? 選擇no
Do you want to search for missing reverse zones? [yes]: yes --你想配置dns的反向域嗎?選擇yes
Continue to configure the system with these values? [no]: yes --繼續配置系統其他的值? 選擇yes
[root@server ~]# systemctl enable sssd --開機自啟動sssd服務(sssd:system security service deamon 系統安全服務)
[root@server ~]# systemctl start sssd --開啟sssd服務(可能默認已經開啟了)
[root@server ~]# authconfig --enablemkhomedir --update 創建的用戶,默認創建用戶家目錄,更新認證信息
5.1驗證ipa-server和dns.
5.1.1驗證ipa-server
[root@server ~]# kinit admin ---必須要登陸admin 才能管理域
Password for [email protected]:
[root@server ~]# ipa user-find --all 查看所有域用戶的信息
1 user matched
dn: uid=admin,cn=users,cn=accounts,dc=zhuxu,dc=vip
User login: admin
....
Number of entries returned 1
5.1.2驗證dns,正反向解析
[root@server ~]# dig -t a server.zhuxu.vip 查看server.zhuxu.vip 的A 記錄
[root@server ~]# dig -t ptr 4.9.168.192.in-addr.apra 查看server.zhuxu.vip 的PTR記錄
6,用命令配置(圖形配置請看上篇文章)
6.1添加用戶:
[root@server ~]# ipa user-add tom --first=t --last=om --homedir=/home/tom --shell=/bin/bash --password
註解:添加用戶tom,--first=t --last=om 這兩個選項必選表示用戶的姓和名 --homedir 指定家目錄 --shell 指定shell類型 --password 指定密碼
Password:
Enter Password again to verify:
6.2添加一個主機
[root@server ~]# ipa host-add client.zhuxu.vip --ip-address=192.168.9.5
註解:添加主機client.zhuxu.vip --ip-address指定ip地址
ipa: ERROR: The host was added but the DNS update failed with:
DNS reverse zone 168.192.in-addr.arpa. for IP address 192.168.9.5 is not managed by this server
報了一個錯,說沒有主機的ptr記錄。不用管,對結果沒有影響。
如果手動修改dns的zone.添加一條ptr記錄重啟ipa服務,再添加主機就不會報錯了。
還有一種圖形方法添加。登錄管理頁面添加即可。
1,客戶端配置
1,修改主機名
[root@localhost ~]# hostnamectl set-hostname client.zhuxu.vip
[root@localhost ~]# hostname client.zhuxu.vip
2,```
hosts文件也要對主機名做解析。不能解析到127.1
vim /etc/hosts 添加 192.168.9.5 client.zhuxu.vip client
3,能夠對主機名做解析(正向和反向解析)把dns改成server.zhuxu.vip 的地址
4,開通防火墻規則和服務
TCP Ports:
* 80, 443: HTTP/HTTPS
* 389, 636: LDAP/LDAPS
* 88, 464: kerberos
* 53: bind
UDP Ports:
* 88, 464: kerberos
* 53: bind
* 123: ntp
[root@client ~]# firewall-cmd --permanent --add-port={80/tcp,443/tcp,389/tcp,636/tcp,88/tcp,464/tcp,53/tcp,88/udp,464/udp,53/udp,123/udp}
[root@server ~]# iptables -F 清除iptables規則
[root@server ~]# systemctl stop iptables 停止iptables服務
[root@server ~]# systemctl disable iptables 禁止iptables 開機啟動
放行 http https ldap ldaps kerberos dns ntp
[root@server ~]# firewall-cmd --permanent --add-service={http,https,ldap,ldaps,kerberos,dns,ntp}
放行tcp的7389端口
[root@server ~]# firewall-cmd --permanent --add-port=7389/tcp
重新加載firewalld
[root@server ~]# firewall-cmd --reload
5,vim /etc/chrony.conf 註釋前三個時間服務,編輯最後一個為:server ntp1.aliyun.com iburst
[root@server ~]#systemctl restart chronyd.service 重啟時間服務
6,配置好yum源,我這選擇掛載光盤來做yum倉庫。
[root@server ~]# vim /etc/yum.repos.d/server.repo
在文件中輸入以下內容
[base]
name=redhat7
baseurl=file:///mnt
enabled=1
gpgcheck=0
掛載光盤到/mnt下(請確保光盤是連接狀況)
[root@server ~]# mount /dev/cdrom /mnt
## 2,配置客戶端
### 2.1,下載客戶工具
[root@client ~]# yum install -y ipa-client
### 2.2,加入域
root@client ~]# ipa-client-install --domain=zhuxu.vip --no-ntp --realm=ZHUXU.VIP --mkhomedir 加入域,不啟用ntp,創建用戶時自動創建家目錄
Continue to configure the system with these values? [no]: yes ---繼續配置系統其他的值? 選擇yes
User authorized to enroll computers: admin ---域管理員
Password for [email protected]: ---密碼
### 2.3驗證用戶能否登錄
[root@client ~]# ssh [email protected]
Password:
Password expired. Change your password now.
Current Password:
New password:
Retype new password:
Last failed login: Sat Jul 28 07:05:23 CST 2018 from client.zhuxu.vip on ssh:notty
There were 18 failed login attempts since the last successful login.
Last login: Sat Jul 28 06:44:46 2018 from client.zhuxu.vip
tom用戶登錄成功。如果修改密碼通過不了,客戶端和服務器端臨時關閉selinux。就可以通過了
從零構建ipa-server.實現ldap+kerberos域用戶驗證(開放防火墻,命令版)