centos上安装keystone,启动httpd失败,bind 5000端口失败的原因
今天,在centos7上安装keystone,都是按照官方文档安装的,安装文档:
#!/bin/bash
HOST_IP=`ip addr |grep inet|grep -v 127.0.0.1|grep -v inet6|grep -E "ens|eth"|awk '{print $2}'|tr -d "addr:" | awk -F '/' '{print $1}'`
# 打印帮助信息
usage()
{
cat << HELP
-f,--conf deploy config file
HELP
exit 1;
}
#打印错误代码并退出
die()
{
ecode=$1;
shift;
echo -e "${CRED}$*,exit $ecode${C0}" | tee -a $LOG_NAME;
exit $ecode;
}
db_keystone="keystone"
keystone_user="keystone"
keystone_pass="123456"
admin_pass="123456"
MysqLdport="3306"
MysqLdbpassword="123456"
MysqLdbadm="root"
dbbackendhost="${HOST_IP}"
MysqLcommand="MysqL --port=$MysqLdbport --password=$MysqLdbpassword --user=$MysqLdbadm --host=$dbbackendhost"
echo "drop database IF EXISTS ${db_keystone};" | ${MysqL_commnd}
echo "CREATE DATABASE IF NOT EXISTS ${db_keystone} default character set utf8;" | ${MysqL_commnd}
echo "CREATE DATABASE IF NOT EXISTS ${db_keystone} default character set utf8;"|$MysqLcommand
echo "GRANT ALL ON $db_keystone.* TO '$keystone_user'@'%' IDENTIFIED BY '$keystone_pass';"|$MysqLcommand
echo "GRANT ALL ON $db_keystone.* TO '$keystone_user'@'localhost' IDENTIFIED BY '$keystone_pass';"|$MysqLcommand
echo "GRANT ALL ON $db_keystone.* TO '$keystone_user'@'$HOST_IP' IDENTIFIED BY
'$keystone_pass';"|$MysqLcommand
yum install -y centos-release-openstack-newton
yum install -y openstack-keystone httpd mod_wsgi python-keystoneclient\ python-openstackclient
crudini --set /etc/keystone/keystone.conf database connection \
"MysqL+pyMysqL://${keystone_user}:${keystone_pass}@${dbbackendhost}/${db_keystone}"
crudini --set /etc/keystone/keystone.conf token provider fernet
su -s /bin/sh -c "keystone-manage db_sync" keystone
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
keystone-manage bootstrap --bootstrap-password ${admin_pass} \
--bootstrap-admin-url http://${HOST_IP}:35357/v3/ \
--bootstrap-internal-url http://${HOST_IP}:35357/v3/ \
--bootstrap-public-url http://${HOST_IP}:5000/v3/ \
--bootstrap-region-id RegionOne
cat /etc/httpd/conf.d/httpd.conf | grep "^ServerName" || \
echo "ServerName ${HOST_IP}" >>/etc/httpd/conf.d/httpd.conf
ln -sfT /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
systemctl enable httpd.service
systemctl restart httpd.service
cat << EOF >/root/keystone_adminrc
export OS_USERNAME=admin
export OS_PASSWORD=${admin_pass}
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://${HOST_IP}:35357/v3
export OS_IDENTITY_API_VERSION=3
EOF
在启动httpd的时候报错了,为什么呢?报错信息如下:
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:5000
Oct 19 08:50:25 openstack-node2 httpd[13804]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:5000
不能绑定5000端口,为什么呢?可以在/var/log/audit/audit.log日志中看到如下日志:
type=AVC msg=audit(1476793246.655:1564): avc: denied { name_bind } for pid=2540 comm="httpd" src=5000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:commplex_main_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1476793246.655:1564): arch=c000003e syscall=49 success=no exit=-13 a0=5 a1=7f82cdb502e8 a2=10 a3=7ffcd4c232fc items=0 ppid=1 pid=2540 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
原来centos默认是启动了SELinux的,SELinux的作用是啥呢?
Selinux极大的增强了Linux系统的安全性,能将用户权限关在笼子里,如httpd服务,apache默认只能访问/var/www目录,并只能监听80和443端口,因此能有效的防范0-day类的攻击。举例来说,系统上的 Apache 被发现存在一个漏洞,使得某远程用户可以访问系统上的敏感文件(比如 /etc/passwd 来获得系统已存在用户),而修复该安全漏洞的 Apache 更新补丁尚未释出。此时 SELinux 可以起到弥补该漏洞的缓和方案。因为 /etc/passwd 不具有 Apache 的访问标签,所以 Apache 对于 /etc/passwd 的访问会被 SELinux 阻止。
CentOS系统自带的chcon工具只能修改文件、目录等的文件类型和策略,无法对端口、消息接口和网络接口等进行管理,semanage能有效胜任SELinux的相关配置工作。
所以要是能够启动keystone,需要安装openstack-selinux包实现对openstack服务的安全策略自动管理。
其实你如果对安全要求不高的话,又不想安装openstack-selinux,有一个终极大招就是,执行命令setenforce 0,就会关掉安全监测。
虽然我安装了openstack-selinux之后,httpd可以正常启动了,但是安全策略是如何制定呢?还需要进一步研究semanage port的增加等原理,等以后再写篇博客详细说一下。
大家有兴趣可以看一下这篇博客Selinux管理工具semanage,http://www.toxingwang.com/linux-unix/linux-basic/722.html,自行了解一下semanage的用法。