1

I am using Chef to build out a virtual machine on Rackspace. The VM is a RHEL 6.5 box.

I am running into problems building the default Apache2 /etc/httpd/conf/httpd.conf file cleanly for RHEL using the Apache2 recipe (it appears to default to an Ubuntu flavor configuration).

In the recipe config template (apache2/templates/default/apache2.conf.erb) there is no place to define ServerName. Consequently when I test Apache is working properly I get the following

% apachectl configtest
httpd: Could not reliably determine the server's fully qualified domain name, using ##### for ServerName
Syntax OK

where ##### is my DNS, listed in my /etc/hosts and defined in my cookbook recipe attributes/default.rb file as servername.

If I look in the recipe template I don't see any location for the variable ServerName (first 17 lines):

#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf

ServerRoot "<%= node['apache']['dir'] %>"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
<% if %w[debian].include?(node['platform_family']) -%>
LockFile /var/lock/apache2/accept.lock
<% elsif %w[freebsd].include?(node['platform_family']) -%>
LockFile /var/log/accept.lock
<% else %>
LockFile logs/accept.lock
<% end -%>

Now, if I manually go and edit /etc/httpd/conf/httpd.conf, adding a ServerName variable, everything works. Relevant before and after below:

BEFORE

#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf

ServerRoot "/etc/httpd"

AFTER

#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf

ServerRoot "/etc/httpd"
ServerName #####:80

Now when I test Apache:

% apachectl configtest
Syntax OK

Obviously the whole point of using Chef is to not hand edit configuration files, and whenever I rerun my chef recipe with chef-solo I am going to blow this customization away. I am so new to Chef that I don't really want to fork the cookbook on Github and make a new template for RHEL, but maybe that's what I need to do?

I am hoping there is just one configuration setting in my overall recipe I am not defining, that will add this variable to my core Apache httpd.conf file.

Hopefully someone with more experience with Chef, and in particular the Apache2 cookbook, can help me. Thanks in advance.

EDIT #1

A look at netstat -tulpn shows that I think Apache (httpd) is actually working, or at least listening in on port 80:

% netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1274/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1677/master         
tcp        0      0 **.***.*.***:3306           0.0.0.0:*                   LISTEN      1585/mysqld         
tcp        0      0 :::80                       :::*                        LISTEN      6663/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1274/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1677/master

Is it looking more and more like a networking (DNS) issue?

EDIT #2

Based on the helpful comments to my original post I think I originally misdiagnosed this. I just built a new Ubuntu VM and installed Apache2 by hand using sudo apt-get install apache2 (ie. not using chef-solo) and I see the same installed layout of apache2 that my Chef recipe created on my RHEL VM. I also get the same warning when running apachectl configtest:

apache2: Could not reliably determine the server's fully qualified domain name, using ##### for ServerName
Syntax OK

When I point the browser on Ubuntu to 127.0.0.1:80 I see the 'It works!' standard Apache response. So, my issue is not really an issue. My thinking now is that this is a network problem. iptables?

EDIT #3

I just ssh'd into my RHEL VM and installed Firefox. I then opened it up and pointed it to 127.0.0.1:80 and I get the default page. I think this categorically confirms that I have a DNS issue. Time to speak to my networking admin.

tatlar
  • 3,080
  • 2
  • 29
  • 40
  • The problem is deeper than I thought. The apache2 Chef cookbook is aimed specifically at Debian/Ubuntu style installs of Apache 2, which means that virtual host files are installed under `/etc/httpd/sites-available/` and not under `/etc/httpd/conf.d/`. I think I am going to have to write my own recipe... Bummer... – tatlar Mar 13 '14 at 16:12
  • Hmmm. I actually take that back. In the Apache 2 cookbook in `attributes/default.rb` there is a `case` statement that chooses how to install apache2 based on the platform type. This chooses whether the package is `httpd` (RHEL and others), `apache2` (Debian/Ubuntu), or others. – tatlar Mar 13 '14 at 16:23
  • 1
    The apache2 cookbook does not assume you're on a Debian-family OS, but it does manage the apache configs in Debian style -- by using (sites|mods)-(available|enabled) and all that. I find it much better than what RHEL/CentOS do (essentially nothing really), but you might disagree. – cassianoleal Mar 13 '14 at 19:13
  • Thanks @cassianoleal. I understand that now. However, it still seems to be an issue. I am at the point where I am going to nuke the VM and start from scratch, installing by hand. If the issue persists at least I know it's not Chef, and probably the DNS or something network related. – tatlar Mar 13 '14 at 20:40
  • 1
    Isn't that just the characteristic of the default site that it has no `ServerName` declared? Wouldn't it otherwise stop to act as the default site? I've seen the warning message too often that I would really worry about, but isn't it the case if apache can't resolve its own host name (reverse lookup of the IP address? only guessing). – StephenKing Mar 13 '14 at 21:57
  • @StephenKing - so you see this `ServerName` alert all the time but your sites work anyway? Maybe the problem is not what I think it is then. I just edited my post to add the output from `netstat` and it looks like `httpd` is listening on port 80. ??? – tatlar Mar 13 '14 at 22:19
  • 1
    Yes, [this question](http://stackoverflow.com/questions/9541460/httpd-could-not-reliably-determine-the-servers-fully-qualified-domain-name-us) has the right answer. It does not matter, if this warning is emitted and it is emitted as the own host name could not be determined. Apache is running, as this is only a warning. – StephenKing Mar 14 '14 at 02:29

1 Answers1

1

As per the helpful comments from users cassianoleal and StephenKing, this "error" was actually a red herring. It is just an Apache warning that has no effect on if httpd is actually running or not.

The problem was really that I wasn't updating my iptables config. Once I installed the Chef cookbook simple_iptables and added a simple_iptables_rule to my Chef recipe to update my iptables to listen on ports 80 and 443, everything worked.

Live and learn I guess.

For the record, Chef is highly recommended if you aren't using it yet!

tatlar
  • 3,080
  • 2
  • 29
  • 40