Pages

Saturday, March 21, 2015

Configuring Postfix as a Local Network Relay

This howto assumes that the relay server’s IP address is 192.168.1.22 and is running RHEL/CentOS 7. Only mail from the 192.168.1.0/24 network should be accepted and relayed.

Install Postfix

[root@rhce-server ~]# yum install postfix

Configure Systemd

[root@rhce-server ~]# systemctl enable postfix
[root@rhce-server ~]# ^enable^start

Configure the Firewall

[root@rhce-server ~]# firewall-cmd --add-service=smtp
success
[root@rhce-server ~]# firewall-cmd --add-service=smtp --permanent 
success

Configure Postfix

Postfix’s main configuration file is located at /etc/postfix/main.cf.
Configure Postfix to listen on the correct interface.
inet_interfaces = all
Configure the trusted network.
mynetworks = 192.168.1.0/24
Configure the list of domains that this Postfix service should consider itself the final destination for. In my case the server is named rhce-server.
mydestination = rhce-server, localhost.localdomain, localhost
Configure all mail not destined for this server to be relayed to another SMTP server. I am using Time Warner Cable’s SMTP server for Northeast Ohio. The brackets tell Postfix to turn off MX lookups.
relayhost = [smtp-server.neo.rr.com]

Restart Postfix

[root@rhce-server postfix]# systemctl restart postfix

Send a Test Email

[root@rhce-server postfix]# mail -s "rhce-server test" josh@example.com
testing our null postfix configuration
.
EOT
With any luck we should be all set. You can verify the mail was successfully relayed in /var/log/maillog.

Tuesday, February 10, 2015

Running pfSense in Proxmox/KVM with PCI Passthrough

Below is how I was able to get pfSense 2.2 running under Proxmox 3.3 with PCI passthrough for two Intel NICs. My first attempts were trying to utilize VirtIO and e1000 network devices but the performance was abysmal. With PCI passthrough I was able to achieve native throughput in my environment.
I am assuming that you have Proxmox running and a pfSense virtual machine already created.

Configure the Proxmox Test Repository

The first thing we need to do is enable the Proxmox test repository so that we may install the 3.10 kernel.
echo 'deb http://download.proxmox.com/debian wheezy pvetest' >> /etc/apt/sources.list

Install the 3.10 Kernel

apt-get install pve-kernel-3.10.0-6

Edit Grub Configuration

We need to pass a kernel flag to enable IOMMU. In my case I am using an AMD processor and added amd_iommu=on to the following line in /etc/default/grub. If you are using an Intel processor you would add intel_iommu=on.
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on"
Update the Grub configuration
update-grub
Reboot the server. By default the 3.10 kernel should be selected.

Identify Your NICs

Identify the PCI devices you want to passthrough to your virtual machine.
lspci
In my case I was looking for my Intel NICs.
lspci | grep Intel

03:00.0 Ethernet controller: Intel Corporation 82541PI Gigabit Ethernet Controller (rev 05)
04:00.0 Ethernet controller: Intel Corporation 82541PI Gigabit Ethernet Controller (rev 05)
You will need to note their addresses.

Edit the Virtual Machine Configuration

Below is an example of my working configuration. You can find these configurations in /etc/pve/qemu-server/. The file you are looking for will correspond with the virtual machine ID. In my case 100.conf.
boot: cdn
bootdisk: ide0
cores: 2
cpu: qemu32
hostpci0: 03:00.0,pcie=1,driver=vfio
hostpci1: 04:00.0,pcie=1,driver=vfio
ide0: local:100/vm-100-disk-1.qcow2,format=qcow2,size=16G
ide2: local:iso/pfSense-LiveCD-2.2-RELEASE-i386.iso,media=cdrom,size=206916K
machine: pc-q35-2.0
memory: 1024
name: pfSense
onboot: 1
ostype: other
smbios1: uuid=0f590e3e-88a0-4084-8a6f-f5a2380a01fa
sockets: 2
tablet: 0
Notice that I added the hostpci0, hostpci1, and machine options. The hostpciX options identify which PCI devices we want to passthrough. As we found above I was looking for my NICs at 03:00.0 and 04:00.0. The machine must be set to pc-q35-2.0 for PCI passthrough to work with FreeBSD from my experience.

Conclusion

With those options set you should be able to boot your pfSense virtual machine and see your PCI devices natively.

Wednesday, January 7, 2015

Using Apache as a Reverse Proxy with SiteMinder for Authentication

When using Apache as a reverse proxy to pass authentication to another application from SiteMinder you may need to send the header variable to your application. By default Apache is not passing these variables on and you need to set them up for your proxy.

RequestHeader set REMOTE_USER %{HTTP:UID}s

Above is an example of the variable UID being returned by SiteMinder and being assigned to the variable REMOTE_USER that will be provided to the end application.

Wednesday, February 19, 2014

Detect a New Disk and Grow a Filesystem in Linux without Rebooting

If you have ever wanted to add a new hard disk to a Linux VMware guest without rebooting here is the solution. After running this command you should be able to use the new disk as you please. This is really useful for growing an LVM filesystem on the fly.
Run this command after adding the new disk to you VMware configuration. This will allow your Linux guest to detect the new disk and assign it as a device.
ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done
Once you have ran this command you can grow the LVM filesystem as usual. (Where X is the new device added.)
# Create a new partition on the new disk. Assign it the type of Linux LVM, 8e.
fdisk /dev/sdX

# Create the new physical volume.
pvcreate /dev/sdX1

# Extend the volume group of your choice.
vgextend /dev/VolumeGroupName /dev/sdX1

# Confirm the new physical extents are available and take note of the number.
vgdisplay

# Extend a logical volume where 1234 is the number of PEs you would like to add.
lvextend -l +1234 /dev/VolumeGroupName/LogVolName

# Resize the EXT filesystem.
resize2fs /dev/VolumeGroupName/LogVolName

# Confirm the new space is available.
df -h
Once complete you should have extra space on your Linux guest.

Sunday, February 16, 2014

Recursive Directory/File Permissions

I’m constantly needing to recursively set different permissions on files and directories to make suPHP happy. I’m posting this here for easy reference.
# Directories
find . -type d -exec chmod 755 {} +

# Files
find . -type f -exec chmod 644 {} +

Friday, August 3, 2012

Why I Chose Unraid for my Home Storage Solution

Unraid

Description

Unraid is a Slackware Linux based operating system that provides an easy way to create network attached redundant storage. It's best suited for archival purposes. It allows for the loss of one disk without losing data.

Unraid has three different licenses you can use, Basic (free), Plus ($69), and Pro ($119). Look at the license page for a description on how they differ.

Advantages

  • Runs off of a USB flash drive. You don't lose a SATA port or disk for the operating system.
  • Mix and match hard drives and sizes. You can put drives of any size in the array. You only lose the largest disk in the array for parity. (Similar to a Drobo)
  • Web interface. A simple web interface lets you configure everything.
  • Supports various protocols including SMB, AFP, and NFS.
  • No vendor lock-in. Although you're using the proprietary Unraid system, all data is stored on the disks in the ReiserFS filesystem
  • Since it's using ReiserFS, if you lose more than one disk at a time you'll be able to get data off the rest of the disks in the broken array.
  • Use your own hardware. I built a little server with an Atom processor for less than the price of the cheapest Drobo.
  • Set it and forget it. I've had my system running for almost two years
  • Stable. I set mine up and have basically forgotten about it. It just works and has been since May 2011 when I configured it.
  • Spins down drives when not in use, unlike RAID-5.
  • Support and community. There's a very active forum and wiki to help you with any issues, add additional functionality, and much more.

Disadvantages

  • Price could be. I purchased the $70 license. If you only have 3 disks and don't require some of the extra features, there is a free version.
  • Write speeds. If you have the need to push stuff to the server at more than 30MB/sec, this may not be the best choice. If you're just archiving stuff, it really is not an issue. You can also speed the writes up with a cache drive.

Why I Chose Unraid

Throughout my history of having redundant storage at home I've had two previous setups that really failed me.

Linux Software RAID-5

Linux software RAID is great, but I had two drives fail at once. I lost everything. With Unraid I would've been able to recover some of the data on the drives that had not failed. You also cannot mix and match drive sizes and the disks never spin down.

Drobo

I had the second generation Firewire 800 Drobo. Transfer speeds were horrible. It still needed a computer running to serve data. I accidentally plugged the wrong power supply into it and it stopped working. I was now stuck buying another expensive Drobo to get my data or coming up with another solution. That is when I found Unraid.

The Drobo is actually a really nice device. The newer ones are supposed to be a lot faster and some even have sharing capabilities. It's just too expensive and they've got you with vendor lock-in.

Links

If I haven't sold it to you yet, here's a few links to learn more about Unraid.

Wednesday, August 1, 2012

MySQL: Change Collation on an Existing Table

I recently ran across an issue where a table's collation was set to latin1_swedish_ci and it really should have been utf8_unicode_ci. Just changing the collation didn't seem to be doing the trick because some characters were still messed up. That's when I realized you need to convert the current character set to UTF8. After doing this everything worked as expected.

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci