Sunday, September 30, 2018

How to display your Windows installation on GRUB during boot after Centos 7 installation




Sometimes when you install Centos 7, your Windlows installation may fil to siaplay in GRUB. To resolve this, you need to run a script to detect operating systems installed then generate the grub configuartion file a new.

1. Check if Windows is detected. This is done by running grub2-mkconfig but discard it’s output

$  sudo grub2-mkconfig > /dev/null 
[sudo] password for wm: 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ae7675c335964b24b4eef02de916ece2
Found initrd image: /boot/initramfs-0-rescue-ae7675c335964b24b4eef02de916ece2.img
Found Windows 7 (loader) on /dev/sda1
done

2. If Windows is listed as above, now run the command again and save the configuration file. It’s good to first make a backup of current configuration file.

$ sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

3. Now if all went well, you should boot into Windows.

Extra
If you would like to edit the names of operating systems displayed by grub, simply access the grub config file and make the edits.

$ sudo vim /boot/grub2/grub.cfg

Friday, September 28, 2018

How to manually move the owncloud data directory to another location


These are the steps taken to manually move a data directory from it’s current location to a new location in ownCloud. Some of the reasons you’d like to move your data directory are:
  • You need to migrate your data to bigger space if your current drive is running out of space
  • You may have issues with your Apache loading .htaccess files needed to secure your data directory from internet access. Instead of enabling .htaccess processing, you could just move the data directory to a new location

Prerequisites
OwnCloud already installed and running on Apache web server, Centos 7
In this tutorial, I assume the following:
  • Your current data directory is /var/www/html/owncloud/data
  • Your new directory is /mnt/new/owncloud

Move the data directory
First of all, copy a backup of your data directory. It’s always important to have a backup.
1. Stop apache web server

[root@centos7box]# systemctl stop httpd

2. Copy/Move the files from current data directory to new data directory. You can use cp, rsync or mv commands to achieve this. Here, I use rsync command with -a option to make sure file attributes are maintained while copying to the new location

[root@centos7box]#rsync -avz /var/www/html/owncloud/data /mnt/new/owncloud

3. Create a symbolic link from the new directory to the old one. For me, this was the step I was missing. Without this, the new owncloud directory would have permission issues. Files would be displayed on the web browser accounts but you can’t open them or download. You also wouldn't be able to upload new files.

[root@centos7box]# ln -s /mnt/new/owncloud /var/www/html/owncloud/data


4. Check if your directory permissions are okay. You should have your directory permissions matching those of the old data directory location. Here is a simple table with the old and new permissions, owners and group

OLD
/var/ root:root 755
/www/ root:root 755
/html/ root:apache 755
/owncloud/ root:apache 755
/data/ apache:apache 770

NEW
/mnt/ root:root 755
/new/ root:apache 755
/owncloud/ apache:apache 770

5. Start apache
[root@centos7box]# systemctl start httpd

Refernces


Thursday, September 27, 2018

How to create your private nameservers


Prerequisites/Requirements

  • VPS installed with CentOS and a web server such as Apache
  • Registered domain name
  • First, point your domain to a working hosting and create two A records in the Zone Editor, each for your two name servers. Eg ns1.example.com and ns2.example.com. Point each of this A records to your server’s IP. Test to see that when you access the nameservers above, they display the landing page of your VPS. You can also ping them to see if they respond with your server IP.
  • In your client area, click on Register Private Nameservers and add the two ns1.example.com and it’s IP and ns2.example.com and it’s IP.
  •  Great, now you are ready to create the DNS files.  
Set up DNS zone on your VPS


1. Access the VPS via SSH

ssh user@hostname
2. Install bind and dnsutils, which will allow us to use the dig command later on

Centos or Fedora: yum install bind dnsutils
Ubuntu ir Debian: apt-get install bind9 dnsutils


3. Create a DNS zone file for the domain that will use the name servers. If the domain is called example.com, here is a sample zone file for the domain. The zone file will be called example.com.db. Save this zone file in /var/named. I will assume your server IP is 10.10.10.10. This file will help map your domain name to the IP.

;
; BIND data file for  example.com
;
$TTL    3h
@       IN      SOA     ns1.example.com. admin.example.com. (
                          1        ; Serial
                          3h       ; Refresh after 3 hours
                          1h       ; Retry after 1 hour
                          1w       ; Expire after 1 week
                          1h )     ; Negative caching TTL of 1 day
;
@       IN      NS      ns1.example.com.
@       IN      NS      ns2.example.com.


example.com.    IN      MX      10      mail.example.com.
example.com.    IN      A       10.10.10.10
ns1                     IN      A       10.10.10.10
ns2                     IN      A       10.10.10.10
www                     IN      CNAME   example.com.
mail                    IN      A       10.10.10.10
ftp                     IN      CNAME   example.com.

 
4. Create similar DNS records as above for your two nameservers, ns1.example.com and ns2.example.com Only replace example.com with ns1.example.com and ns2.example.com in the respective files.

5. Configure reverse DNS records. This zone file teaches our nameservers to resolve a host from an IP address. The file will be called  10.10.10.10.db Also, save this zone file in /var/named

;
; BIND reverse data file for 0.10.10.in-addr.arpa
;
$TTL    604800
0.10.10.in-addr.arpa.      IN      SOA     ns1.example.com.
admin.example.com. (
                          1         ; Serial
                          3h       ; Refresh after 3 hours
                          1h       ; Retry after 1 hour
                          1w       ; Expire after 1 week
                          1h )     ; Negative caching TTL of 1 day
;
0.10.10.in-addr.arpa.       IN      NS      ns1.example.com.
0.10.10.in-addr.arpa.       IN      NS      ns2.example.com.
10.10.10.10.in-addr.arpa.   IN      PTR     example.com.


 
6. Update the BIND configuration file. Note that, at this point, you should have these two files ready. Ie

/var/named/example.com.db
/var/named/10.10.10.10.db

Now, simply open the Bind configuration file using your favourite editor.

vim /etc/named.conf

Then add the following code. Remeber to change example.com to your domain name

zone "example.com" {
       type master;
       file "/var/named/example.com.db";
};

zone "0.217.144.in-addr.arpa" {
       type master;
       file "/var/named/10.10.10.10.db";
};

7. Lastly, add an IP address of a stable DNS server in your /etc/resolv.conf file. For example, if you wish to add google’s DNS server, comment our the content of /etc/resolv.conf and add the following line:

nameserver 8.8.4.4

8. Check binds zone files and configuration
 To  check the configuration files run the following command:

named-checkconf

To check a DNS zone files we can use named-checkzone command:

named-checkzone example.com /var/named/example.com.db

zone example.com/IN: loaded serial 1
OK
For the reverse zone file check

named-checkzone 0.10.10.in-addr.arpa /var/named/10.10.10.10.db

zone 0.168.192.in-addr.arpa/IN: loaded serial 2
OK

9. Restart bind

service named restart

10. You can test the bind server configuration using dig command

dig @10.10.10.10 www.example.com

; <<>> DiG 9.6-ESV-R1 <<>> @10.10.10.10 www.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<