eddie

your baddie teddie since 1983.

Category: linux

Setup DHCP server on Fedora or Centos

It’s quite easy to quickly setup a DHCP server on Fedora/Centos machine.

[root@xstorm ~]# dnf -y install dhcp
[root@xstorm ~]# vi /etc/dhcp/dhcpd.conf
# create new
# specify domain name
option domain-name “yourdomain.com”;
# specify DNS server’s hostname or IP address
option domain-name-servers 10.0.0.1;
# default lease time
default-lease-time 600;
# max lease time
max-lease-time 7200;
# this DHCP server to be declared valid
authoritative;
# specify network address and subnet mask
subnet 10.0.0.0 netmask 255.255.255.0 {
# specify the range of lease IP address
range dynamic-bootp 10.0.0.200 10.0.0.254;
# specify broadcast address
option broadcast-address 10.0.0.255;
# specify default gateway
option routers 10.0.0.1;
}

Start DHCP server and enable it on startup

[root@xstorm ~]# systemctl start dhcpd

[root@xstorm ~]# systemctl enable dhcpd

If you have Fedora firewalld running, allow DHCP service (UDP port 67)

[root@xstorm ~]# firewall-cmd –add-service=dhcp –permanent
success
[root@xstorm ~]# firewall-cmd –reload
success

How to setup RSYNC backup on Linux (without password)




The following steps explains how to setup rsync over ssh that doesn’t ask for a password. This is helpful when you are scheduling a cron job for automatic backup using rsync.

1. Test rsync over ssh (with password):

Do a rsync to make sure it asks for the password for your account on the remote server, and successfully copies the files to the remote server.

The following example will synchronize the local folder /home/calvin to the remote folder /backup/calvin (on 192.168.200.10 server).

This should ask you for the password of your account on the remote server.

rsync -avz -e ssh /home/calvin/ root@192.168.200.10:/backup/calvin/

2. ssh-keygen generates keys.

Now setup ssh so that it doesn’t ask for password when you perform ssh. Use ssh-keygen on local server to generate public and private keys.

$ ssh-keygen
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Note: When it asks you to enter the passphrase just press enter key, and do not give any password here.

3. ssh-copy-id copies public key to remote host

Use ssh-copy-id, to copy the public key to the remote host.

ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.200.10

Note: The above will ask the password for your account on the remote host, and copy the public key automatically to the appropriate location.

4. Perform rsync over ssh without password

Now, you should be able to ssh to remote host without entering the password.

ssh 192.168.200.10

Mounting NFS file share for Oracle database




When installing an Iomega NAS to do Oracle database backup over network for a client, i came across a problem when mounting the NFS file share.

ORA-27054: NFS file system where the file is created or resides is not mounted with correct options

It turns out that Oracle requires a certain set of NFS mount options to work properly. After much testing and research online, i’ve collated the below options that works well for Oracle database mounts or backup over direct NFS (no buffer, direct I/O):

Solaris
rw,bg,hard,nointr,rsize=1048576,wsize=1048576,proto=tcp,noac,forcedirectio, vers=3,suid
AIX (5L)
cio,rw,bg,hard,nointr,rsize=1048576,wsize=1048576,proto=tcp,noac,vers=3,timeo=600
HP-UX 11i v3
rw,bg,vers=3,proto=tcp,noac,forcedirectio,hard,nointr,timeo=600,rsize=1048576,
wsize=1048576,suid
Linux x86
rw,bg,hard,nointr,rsize=1048576,wsize=1048576,tcp,actimeo=0,vers=3,timeo=600
Linux x86-64
rw,bg,hard,nointr,rsize=1048576,wsize=1048576,tcp,actimeo=0,vers=3,timeo=600

Linux / Unix / Mac crontab – how to add, install or list jobs

Different Types of cron Configuration

There are two different types of configuration files:

  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.
  2. The user crontabs: User can installer their own jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab

How Do I Install / Create / Edit My Own Cronjobs?

To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e

Syntax of crontab (Field Description)

Your cron job looks as follows for user jobs:

 1 2 3 4 5 /path/to/command arg1 arg2

OR

 
1 2 3 4 5 /root/backup.sh

Where,

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])
  • /path/to/command – Script or command name to schedule

 

Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

 

Your cron job looks as follows for system jobs:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

Example: Install Backup Job Script

If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e
Append the following entry:
0 3 * * * /root/backup.sh
Save and close the file.

More Examples

To run /path/to/command five minutes after midnight, every day, enter:

5 0 * * * /path/to/command

Run /path/to/script.sh at 2:15pm on the first of every month, enter:

15 14 1 * * /path/to/script.sh

Run /scripts/phpscript.php at 10 pm on weekdays, enter:

0 22 * * 1-5 /scripts/phpscript.php

Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am …, everyday, enter:

23 0-23/2 * * * /root/scripts/perl/perlscript.pl

Run /path/to/unixcommand at 5 after 4 every Sunday, enter:

5 4 * * sun /path/to/unixcommand

Task: List All Your crontab Jobs

Type the following command :

# crontab -l
# crontab -u username -l

To remove or erase all crontab jobs use the following command:

# crontab -r
crontab -r -u username

 

adapted from cyberciti.biz

Configuring Virtual Hosting using Apache2 on SLES 10

Originally from: http://www.novell.com/coolsolutions/feature/19856.html

In this guide I tried to explain how to implement Virtual Hosting using Apache2 on SUSE Linux Enterprise Server 10. This guide is ESPECIALLY written for those WEB-ADMINS who are used to configuring Virtual Hosting on Redhat Enterprise Linux(RHEL 3/4). Since on a rhel Server, apache is configured using a single file i.e /etc/httpd/httpd.conf, i.e all of the virtual hosting configurations goes in /etc/httpd/httpd.conf ONLY, while in SUSE Linux Enterprise 10, we don’t edit the httpd.conf for virtual hosting.

What is Virtual Hosting:

Virtual Hosting is the art/method to run multiple websites on a single machine.

Benefits Of Virtual Hosting:

There are millions of websites on the Internet. Without Virtual Hosting it is impossible to run millions of website, because each website requires a dedicated Machine, IP and/or Port as an address to be accessed from across the world/Internet.

Types Of Virtual Hosting:

There are three types of virtual hosting.

  1. IP Based Virtual Hosting (not commonly used)
  2. Port Based Virtual Hosting (not commonly used)
  3. Name Based Virtual Hosting (commonly used)

a. IP Based Virtual Hosting:

    IP based virtual Hosting is the method to run multiple websites on a single machine, but each website must be configured to run on a different/unique IP. To configure the IP base virtual hosting we have to assign multiple IPs to the machine(server).

    Say we have a “Dell Precision 650” machine, to host 3 different websites we must assign 3 unique IP addresses to the machine, and then configure each website to listen on a dedicated IP.

    Advantage:

    Just a single physical machine will host multiple websites, otherwise we need a separate machine to host each website.

    Disadvantage:

    Requires a dedicated IP for each website.

b. Port Based Virtual Hosting:

    • To access the www.test.com, in the url user/surfer has to type the port too, as www.test.com:81
    • To access the www.wxyz.com, in the url user/surfer has to type the port too, as www.wxyz.com:82
    • To access the www.ijkl.com, in the url user/surfer has to type the port too, as www.test.com:83
  • Port base virtual Hosting is the method to run multiple websites on a single machine and even on a single/same IP, but each website must be configured to run on a different/unique Port.

    Say we have a “Dell Precision 650” machine, to host 3 different websites we just need a single dedicated/unique IP-add.

    e.g we have to host www.test.com, www.wxyz.com, and www.ijkl.comon a single machine using single/same IP-addr… we will configure www.test.comto listen on port 81, www.wxyz.comto listen on port 82, and www.ijkl.comto listen on port 83.

    Advantage:

    Just a single physical machine and IP will host multiple websites. No need to purchase multiple machines and IP-add to host multiple websites.

    Disadvantages:

    – It is quite impossible to inform the users/surfers that on which particular port the website is hosted.
    – And user/surfer must has to type the particular port in the url e.g

c. Name Based Virtual Hosting:

    To run multiple websites on a single machine and even on a single/same IP and port, we have to configure the Name-Based Virtual Hosting.

    Advantage:

    A single machine, single IP, and the default http port(80) is used to host several websites.

    Disadvantage:

    Proper DNS configuration will be required to host and access the websites hosted via Name Base Virtual Hosting.

    Note: Since other types of Virtual Hosting(IP and Port base) are not commonly used, thats why we just discuss the Name-Based virtual hosting and used the term “Virtual Hosting” for Name-Based Virtual Hosting.

Step-By-Step Configuration

Configuring Virtual-Hosting using apache2 on SLES 10

  1. First create the Directories and html files for the two websites we host using Virtual Hosting.say e.g
    a1, mkdir /srv/www/example1
    b1, echo "This is the EXAMPLE 1 website" >/srv/www/example1/index.html
    
    a2, mkdir /srv/www/example2
    b2, echo "This is the EXAMPLE 2 website" >/srv/www/example2/index.html
    ********

    After creating directories and html files for the two websites, Now we configure the apache2 to host/run the two websites using virtual hosting.

  2. in /etc/apache2/listen.conf append the following line:
    NameVirtualHost IP_OF_Server:PORT
    i.e
    
    NameVirtualHost 192.168.0.101:80
  3. then change the directory ascd /etc/apache2/vhosts.d

    cp vhost.template example1.conf
    cp vhost.template example2.conf

    NOTE: the virtual host configuration files(in our case example1.conf, and example2.conf) MUST have “.conf” in the end of their names.

  4. Have to change some required parameters as per the environment
    1. Minimal Required Configuration for example1 Websitein /etc/apache2/vhosts.d/example1.conf
      <VirtualHost 192.168.0.101:80> *
      
         ServerName www.example1.org
         DocumentRoot /srv/www/example1
      
         <Directory "/srv/www/example1"> **
            Order allow,deny
            Allow from all
         </Directory>
      
      </VirtualHost>
    2. Minimal Required Configuration for example2 Websitein /etc/apache2/vhosts.d/example2.conf
      <VirtualHost 192.168.0.101:80> 
      
         ServerName www.example2.org
         DocumentRoot /srv/www/example2
      
         <Directory "/srv/www/example2">
            Order allow,deny
            Allow from all
         </Directory>
      
      </VirtualHost>
  5. Restart Apache
    # /etc/init.d/apache2 restart
    or
    # rcapache2 restart

    Now access the websites via your favorite web-browser
    DONE 😉

* If the website is host on the default http port i.e port 80 then its optional to specify the port on rhel, but on a SLES, even the default http port(80) must have to be explicitly specify/define.

** On rhel the Directory Block( <Directory “dir_name”> …</Directory> ) declaration is optional, but on a SLES it is must required within Virtual host Configuration( <VirtualHost IP:Port>…</VirtualHost> ).

© 2017 eddie

Theme by Anders NorenUp ↑