从零构建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,能够对主机名做解析(正向和反向解析)
4,hosts文件也要对主机名做解析。不能解析到127.1
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。就可以通过了

猜你喜欢

转载自blog.51cto.com/zhuxu91313/2151380