主机IP | 角色 |
---|---|
192.168.31.135 node1.work.com | master |
192.168.31.136 node2.work.com | slave |
设置hostname
#135机器
[root@localhost ~]# hostnamectl set-hostname node1.work.com
#136机器
[root@localhost ~]# hostnamectl set-hostname node2.work.com
#配置hosts,2个机器都做
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.31.135 node1.work.com
192.168.31.136 node2.work.com
软件安装(2节点都安装)
[root@node1 ~]# yum -y install krb5-server krb5-libs krb5-auth-dialog krb5-workstation
主节点配置
[root@node1 ~]# cat /etc/krb5.conf
# Configuration snippets may be placed in this directory as well
includedir /etc/krb5.conf.d/
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
rdns = false
pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
default_realm = work.com
default_ccache_name = KEYRING:persistent:%{uid}
[realms]
work.com = {
kdc = node1.work.com
admin_server = node1.work.com
}
[domain_realm]
# .example.com = EXAMPLE.COM
# example.com = EXAMPLE.COM
#配置管理员账号
[root@node1 ~]# vim /var/kerberos/krb5kdc/kadm5.acl
*/admin@work.com *
[root@node1 ~]# vi /var/kerberos/krb5kdc/kdc.conf
[kdcdefaults]
kdc_ports = 88
kdc_tcp_ports = 88
[realms]
work.com = {
#master_key_type = aes256-cts
acl_file = /var/kerberos/krb5kdc/kadm5.acl
dict_file = /usr/share/dict/words
admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
}
初始化主节点
[root@node1 ~]# kdb5_util create -r work.com -s
Loading random data
Initializing database '/var/kerberos/krb5kdc/principal' for realm 'work.com',
master key name 'K/M@work.com'
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
Enter KDC database master key:
Re-enter KDC database master key to verify:
创建远程管理账号密码
[root@node1 ~]# kadmin.local
Authenticating as principal root/admin@work.com with password.
kadmin.local: addprinc admin/admin@work.com
WARNING: no policy specified for admin/admin@work.com; defaulting to no policy
Enter password for principal "admin/admin@work.com":
Re-enter password for principal "admin/admin@work.com":
Principal "admin/admin@work.com" created.
kadmin.local: exit
启动主节点
[root@node1 ~]# systemctl enable krb5kdc
Created symlink from /etc/systemd/system/multi-user.target.wants/krb5kdc.service to /usr/lib/systemd/system/krb5kdc.service.
[root@node1 ~]# systemctl enable kadmin
Created symlink from /etc/systemd/system/multi-user.target.wants/kadmin.service to /usr/lib/systemd/system/kadmin.service.
[root@node1 ~]# systemctl start krb5kdc
[root@node1 ~]# systemctl start kadmin
主节点增加配置
[root@node1 ~]# vim /etc/krb5.conf
[realms]
work.com = {
kdc = node1.work.com
kdc = node2.work.com #增加
admin_server = node1.work.com
}
在主节点创建kerberos主从角色
#格式addprinc -randkey host/[hostname]
#ktadd host/[hostname]
[root@node1 ~]# kadmin.local
Authenticating as principal root/admin@work.com with password.
kadmin.local: addprinc -randkey host/node1.work.com
WARNING: no policy specified for host/node1.work.com@work.com; defaulting to no policy
Principal "host/node1.work.com@work.com" created.
kadmin.local: addprinc -randkey host/node2.work.com
WARNING: no policy specified for host/node2.work.com@work.com; defaulting to no policy
Principal "host/node2.work.com@work.com" created.
kadmin.local: ktadd host/node1.work.com
Entry for principal host/node1.work.com with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type des3-cbc-sha1 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type arcfour-hmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type camellia256-cts-cmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type camellia128-cts-cmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type des-hmac-sha1 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node1.work.com with kvno 2, encryption type des-cbc-md5 added to keytab FILE:/etc/krb5.keytab.
kadmin.local: ktadd host/node2.work.com
Entry for principal host/node2.work.com with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type des3-cbc-sha1 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type arcfour-hmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type camellia256-cts-cmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type camellia128-cts-cmac added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type des-hmac-sha1 added to keytab FILE:/etc/krb5.keytab.
Entry for principal host/node2.work.com with kvno 2, encryption type des-cbc-md5 added to keytab FILE:/etc/krb5.keytab.
kadmin.local: exit
同步文件到从节点
[root@node1 ~]# scp /etc/krb5.conf /etc/krb5.keytab node2.work.com:/etc/
The authenticity of host 'node2.work.com (192.168.31.136)' can't be established.
ECDSA key fingerprint is SHA256:X/maKrI1kBkj2QroFg56IZHRoRygS/q/+tIuKyritzU.
ECDSA key fingerprint is MD5:39:14:8c:f9:41:71:e7:21:07:21:71:74:c1:63:b7:76.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2.work.com,192.168.31.136' (ECDSA) to the list of known hosts.
root@node2.work.com's password:
krb5.conf 100% 669 373.7KB/s 00:00
krb5.keytab 100% 1186 958.8KB/s 00:00
[root@node1 ~]# scp /var/kerberos/krb5kdc/{kadm5.acl,kdc.conf,.k5.work.com} node2.work.com:/var/kerberos/krb5kdc/
root@node2.work.com's password:
kadm5.acl 100% 19 19.3KB/s 00:00
kdc.conf 100% 448 266.0KB/s 00:00
.k5.work.com 100% 73 67.0KB/s 00:00
从节点启动同步进程
#kpropd -S 或者systemctl start kprop
[root@node2 ~]# kpropd -S
[root@node2 ~]# vim /var/kerberos/krb5kdc/kpropd.acl
host/node1.work.com@work.com
host/node2.work.com@work.com
在主节点导出数据,并同步至从节点
#备份
[root@node1 ~]# kdb5_util dump /var/kerberos/krb5kdc/kdc.dump
#传递至从节点
[root@node1 ~]# kprop -f /var/kerberos/krb5kdc/kdc.dump node2.work.com
Database propagation to node2.work.com: SUCCEEDED
从节点启动
[root@node2 ~]# systemctl enable krb5kdc
Created symlink from /etc/systemd/system/multi-user.target.wants/krb5kdc.service to /usr/lib/systemd/system/krb5kdc.service.
[root@node2 ~]# systemctl start krb5kdc
至此kerberos主从配置基本完成(可以通过关闭主节点kdc,kinit来验证双节点kdc是否生效),需要配置crontab定时同步数据到从节点即可。从节点不需要启动kadmin,保持数据一致性。