CentOS 7 kickstart file set hostname with hostnamectl - centos7

I used remote HTTP server to install CentOS 7. Following is my kickstart file code for setting hostname, but it didn't work.
%post --nochroot --interpreter=/bin/bash --log=/var/log/hostname_post.log
hostnamectl set-hostname f10web01
%end
%post --interpreter=/bin/bash --log=/var/log/another.log
# did something else successfully here
%end
Any clue why set hostname didn't do the work? Also, log file hostname_post.log was not generated, so seem like the first post section was not executed at all.

Use this instead:
%post --nochroot
hostnamectl set-hostname server.example.com
hostnamectl --pretty set-hostname server.example.com
cp /etc/hostname /mnt/sysimage/etc/hostname
cp /etc/machine-info /mnt/sysimage/etc/machine-info
This is the recommended way to do this according to Red Hat.

Related

Where does puppet pull the hostname info to name the certs in the ssl directory?

When I spin up my AWS machine, the first thing I do is run hostnamectl set-hostname myhost.test.com but then when I install and run puppet, it is pulling standard-1-ami.test.com as the cert name. standard-1-ami is the name of my AMI.
Where is it getting this name from on the OS?
I have this issue as well. Every time I make a new machine, without setting the hostname in a userdata script, I have this issue. I have noticed that the initial hostname is cached somewhere in memory.
Here's how I fix it:
Hostname: new_host ; IP: 192.168.10.50 ; DomainName: inside.myhouse.com
hostnamectl set-hostname new_host
echo "192.168.10.50 new_host.inside.myhouse.com new_host" >> /etc/hosts
echo "new_host" > /etc/hostname
service network restart
These 3 places are where the hostname "lives" or "can be retrieved.
To validate my configs, I run these 3 commands:
$ hostname
new_host
$ hostname -f
new_host.inside.myhouse.com
hostname -i
192.168.10.50
Note that, if your prompt is set to have your hostname displayed, your prompt may not change until you log back in. If the hostname & hostname -f commands work, you can run puppet and it should use the correct hostname.
BTW: I use Red Hat. YMMV.

Change hostname permanently in Google Compute Engine instance after reboot

I've created a Google instance in Google Compute Engine with CentOS operating system, then I installed Cpanel. My problem is with WHM/Cpanel, it needs a hostname to be FQDN hostname, specifically for updating Cpanel or it will fail.
My problem is that after changing the hostname the instance reverts back to the old hostname after rebooting the operating system or resetting/stopping/starting the instance.
I've checked most questions before and I've tried most of the solutions with no luck. It keeps changing after reboot, I've try all the methods below and more:
create sh script in:
/etc/dhcp/dhclient-exit-hooks.d/
change hostname in
/etc/hostname
edit file
/etc/dhclient.conf
then add inside it, for my network interface:
supersede host-name "host.domain.com"
in crontab add to the end:
#reboot hostname="host.domain.com"; sed -i "s/.*Google.*//" /etc/hosts; hostname "$hostname"
But after reboot, the hostname changes back to the instance name.
Is there any other workaround to permanently change my hostname even after reboot.?
Thanks
You could create a similar crontab entry, but instead of using the line in your post, you could use hostnamectl to set the hostname on start-up.
I've tested this with Google's Centos7 and Debian9 images and it works for both. However, I found that with Centos, I had to add a delay before the commands execution (see below).
So for example, open crontab:
sudo crontab -e
Then enter this line for Centos:
#reboot sleep 15 && hostnamectl set-hostname YOUR_HOSTNAME
For Debian this worked:
#reboot hostnamectl set-hostname YOUR_HOSTNAME
I didn't experiment too much with the crontab Centos timings (you may be able to use a lower figure than 15 seconds), but from my experience, using #reboot alone didn't seem to initiate the change on start-up.
Problem of automatic change hostname without restart solve it by create an ".sh" executable file in "/etc/dhcp/dhclient-exit-hooks.d/", ex: below we create file "set_my_hostname.sh", you can create an sh file with any name:
cd /etc/dhcp/dhclient-exit-hooks.d/
nano set_my_hostname.sh
then inside the file put:
hostname hosting.domain.com
save the file and make it executable:
chmod +x set_my_hostname.sh
and to fix, hostname automatic change after reboot, create a cronjob to start at reboot with delay (thanks neilH for his help):
sudo env EDITOR=nano crontab -e
then add this line:
#reboot sleep 20 && hostnamectl set-hostname "hosting.domain.com"
This worked for me, I wanted my hostname to be a subdomain ie: server1.example.com:
1: Change /etc/hosts file add:
127.0.0.1 localhost.localdomain localhost
192.168.1.100 server1.example.com server1
2: Change etc/hostname file (if doesn't exist create it):
add just the sub-domain part ie: server1
3: Change /etc/dhcp/dhclient.conf add:
supersede host-name "server1.example.com";
4: Create a cron job: run sudo crontab -e then add:
#reboot hostnamectl set-hostname server1.example.com
5: sudo reboot
This worked for me in a GCE instance running Ubuntu 16.04:
1: Open /etc/hostname (sudo nano /etc/hostname) and change the hostname to the new one.
2: Open /etc/hosts (sudo nano /etc/hosts). The first line will probably be:
127.0.0.1 localhost
Add your new hostname to the end of the line, so it should look like this:
127.0.0.1 localhost <new_hostname>
3: Open /etc/rc.local (sudo nano /etc/rc.local). Before the line exit 0, add another line:
hostname <new_hostname>
4: That's it! The hostname has been changed permanently. You can either open a new bash shell by running bash or reboot the instance.

Cannot open firefox browser via X11

When I try to start firefox on ec2 instance (centos/7) via X11, I got an error.
Is there a way to solve this?
I'm already confirmed that other GUI application, sucy as xeyes or eog, can be launched.
Env
ec2 side
OS: Centos 7.3.1611 (Core)
SELinux: Enforcing
xauth version: 1.0.9
xterm version: X.Org 7.6.0(295)
xorg-x11-apps.x86_64: 7.7-6.el7
$ sudo cat /etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
X11UseLocalhost no
UsePrivilegeSeparation sandbox # Default for new installations.
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
local side
OS: Mac OS X 10.11.6
XQuartz version: 2.7.11 (xorg-server 1.18.4)
$ sudo cat /etc/ssh/sshd_config
# Apple:
Host *
SendEnv LANG LC_*
Host *
XAuthLocation /opt/X11/bin/xauth
Reproduction scenario
# ec2 side
sudo yum -y install xauth xterm xorg-x11-apps xeyes
exit
# local side
ssh -X fhiyo#ec2-xx-xx-xx-xx.ap-northeast-1.compute.amazonaws.com
# ec2 side
xeyes # OK
sudo yum -y install eog
eog path/to/sample.png # OK
sudo yum -y install firefox
$ firefox
[Parent 20819] WARNING: pipe error (36): Connection reset by peer: file /builddir/build/BUILD/firefox-52.2.0/firefox-52.2.0esr/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 322
###!!! [Parent][MessageChannel] Error: (msgtype=0x46000E,name=PContent::Msg_NotifyLayerAllocated) Channel error: cannot send/recv
...
[Parent 20819] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /builddir/build/BUILD/firefox-52.2.0/firefox-52.2.0esr/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 22
###!!! [Parent][MessageChannel] Error: (msgtype=0x2C0085,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
I had a similar problem when launching Firefox version 52.3.0 with X11 forwarding on CentOS 7 :
WARNING: pipe error (35): Connexion ré-initialisée par le correspondant: file /builddir/build/BUILD/firefox-52.3.0/firefox-52.3.0esr/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 322
And same error (in french) on firefox "Gah, you tab just crash"
To correct this, i tried first to update all the package without success.
So i combined two solutions i found on the net :
1- I opened the "about:config" page (just type about:config in the url field then enter) and changed to "false" the 2 options browser.tabs.config.autostart and browser.tabs.config.autostart2
2- I opened the "about:support" page and click on "Repair Firefox..."
Then it works ! but i still have the following problem : i need to do this each time i relaunch firefox; So i should not close all tabs.
Check your SELinux configuration. In special check that mozilla_plugin_can_network_connect is enabled. You can do: getsebool mozilla_plugin_can_network_connect if answer is off then do setsebool -P mozilla_plugin_can_network_connect=1. Then try again firefox&

Connecting to remote aerospike server - Community edition

I am a beginner with aerospike with Python client. I have an aerospike [build - 3.9.1.1] installed in a google instance.
How can I connect to the server from another instance?
I tried the following in shell and wouldn't budge:
import aerospike
config = {'hosts': [('xx.mmm.nn.oo', 3000)]}
# the IP from ifconfig | grep "inet addr"
client = aerospike.client(config)
client.connect()
This yields exception as below:
ClientError: (-1L, 'Failed to connect', 'src/main/aerospike/as_cluster.c', 459)
In the remote I tried the following:
This works fine:
asinfo -v "namespaces"
Also this works when I do:
telnet xx.mmm.nn.oo 3003
....
namespaces
...
Going desperate, I have tried setting access-address in the local with the IP of the server [xx.mmm.nn.oo] and that didn't work either!
Please help folks!
Issue apparently resolved by allowing connections by editing the iptables:
/sbin/iptables -A INPUT -p tcp -s XXX.XXX.XXX.XXX -j ACCEPT /sbin/iptables -A OUTPUT -p tcp -d XXX.XXX.XXX.XXX -j ACCEPT –

Change Domain Problems

I have been trying to change the domain and have been running into issues. I hope someone can help me out here, I have documented the steps I went through below.
I requested the DNS resouuce from our dns admin team.
.mike-cf.company.com canonical name = mike-cf.company.com.
Name: mike-cf.company.com
Address: 10.52.88.123
I then installed with the -D switch:
bash < <(curl -s -k -B http ://raw.github.com/cloudfoundry/vcap/master/dev_setup/bin/vcap_dev_setup -D mike-cf.company.com)
I noticed that not all the config files in ~/cloudfoundry/.deployments/devbox/config changed, so I changed those using sed command:
$ cd ~/cloudfoundry/.deployments/devbox/config
$ sed -i 's/.vcap.me/.newdomain.com/g' *.yml
I restarted and things were looking good, I was able to run vmc target with no problem but I was not able to register a user.
$ vmc target http://api.mike-cf.company.com/
Successfully targeted to [http://api.mike-cf.company.com]
$ vmc register --email mike#company.com --passwd password
Creating New User: Error 100: Bad request
There was no entried in uaa.log only this in the cloud_controller.log
[2012-09-25 09:06:46.712110] cc - pid=20400 tid=8ee9 fid=4757 DEBUG -- ---> async\nrequest: post http://uaa.mike-cf.company.com/oauth/token\nheaders: {"content-type"=>"application/x-www-form-urlencoded", "accept"=>"application/json", "authorization"=>"Basic Y2xvdWRfY29udHJvbGxlcjpjbG91ZGNvbnRyb2xsZXJzZWNyZXQ="}\nbody: grant_type=client_credentials
[2012-09-25 09:06:46.718338] cc - pid=20400 tid=8ee9 fid=4757 DEBUG -- <---\nresponse: 404\nheaders: {"SERVER"=>"nginx", "DATE"=>"Tue, 25 Sep 2012 16:06:46 GMT", "CONTENT_TYPE"=>"text/html", "CONTENT_LENGTH"=>"162", "CONNECTION"=>"close"}\nbody: \r\n404 Not Foundhttp://uaa.mike-cf.company.com: 404 trace ["/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/uaa-dad29c9030f4/gem/lib/uaa/http.rb:56:in json_parse_reply'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/uaa-dad29c9030f4/gem/lib/uaa/token_issuer.rb:157:inrequest_token'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/bundler/gems/uaa-dad29c9030f4/gem/lib/uaa/token_issuer.rb:128:in client_credentials_grant'", "/home/mike/cloudfoundry/cloud_controller/cloud_controller/app/models/uaa_token.rb:80:inaccess_token'", "/home/mike/cloudfoundry/cloud_controller/cloud_controller/app/models/uaa_token.rb:96:in user_account_instance'", "/home/mike/cloudfoundry/cloud_controller/cloud_controller/app/controllers/users_controller.rb:13:increate'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.0.14/lib/action_controller/metal/implicit_render.rb:4:in send_action'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.0.14/lib/abstract_controller/base.rb:150:inprocess_action'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.0.14/lib/action_controller/metal/rendering.rb:11:in process_action'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/actionpack-3.0.14/lib/abstract_controller/callbacks.rb:18:inblock in process_action'", "/home/mike/cloudfoundry/.deployments/devbox/deploy/rubies/ruby-1.9.2-p180/lib/ruby/gems/1.9.1/gems/activesupport-3.0.14/lib/active_support/callbacks.rb:446:in `run_3844132275556875466__process_action_2824786929479189233_callbacks'"]
[2012-09-25 09:06:46.896386] cc_events - pid=20400 tid=8ee9 fid=4757 INFO -- [2012-09-25 09:06:46 -0700, :USER, "N/A", "POST:/users", "mike#company.com", :FAILED, "Bad request"]
I have found the problem, there seemed to be an issue with the vmc I was using. Once I downgraded VMC I am now able to connect.
gem uninstall vmc
gem install --version '= 0.3.18' vmc
Here is the thread that lead me to the answer
https://groups.google.com/a/cloudfoundry.org/forum/?fromgroups=#!topic/vcap-dev/enY2qKnSJWI
is it possible to see the content of the uaa config file? Make sure it has the correct IP address specified for the NATS message bus, the line should look something like this;
mbus: nats://nats:nats#192.168.1.10:4222/
If that IP address is incorrect, it needs to be changed. I take it the server it is installed on has a static IP address? was it assigned before you installed VCAP?