Tips for managing, administering Ubuntu servers. I have spent hundreds of hours working on Ubuntu serves. Some tasks are not very obvious to do and have wasted many hours of research and testing. I hope this guide can save time for other Ubuntu admins.
Monday, October 1, 2018
Stopping ALL your proxmox services in Proxmox PVE 5.x
Sometime you just need to STOP promox pve services in your hardware nodes because they froze or not functioning properly. These commands below will help you stop all your proxmox services:
killall -9 corosync
Restart all Proxmox services in PVE 5.x
Sometime you just need to restart promox pve services in your hardware nodes because they froze or not functioning properly. These commands below will help you restart all your proxmox services:
killall -9 corosync
killall -9 corosync
systemctl restart pve-cluster
systemctl restart pvedaemon
systemctl restart pveproxy
systemctl restart pvestatd
Tuesday, September 11, 2018
Setup outgoing email using Rackspace SMTP for your ubuntu server using Postfix
Follow this very easy steps to send outgoing emails from your ubuntu server using Rackspace Email server SMTP.
Step 1 - Prepare required software
aptitude update
apt-get install postfix libsasl2-modules
Step 2 - Configure Postfix's main.cf
Add the following to /etc/postfix/main.cf:
relayhost = secure.emailsrvr.com
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_mechanism_filter = AUTH LOGIN
smtp_sasl_security_options =
Step 3 - Set your username and password into sasl_password
Add the Rackspace Email username and password to /etc/postfix/sasl_passwd by running these commands:
echo 'secure.emailsrvr.com username@domain.com:secretpassword' > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
Step 4 - Restart Postfix
service postfix restart
Step 5 - Send test email
echo "My message body" | mail -s "Test Email Subject" somebody@gmail.com
That is all... 5 easy steps will get your server sending email reliably using Rackspace Email account!
Sunday, May 27, 2018
Preparation commands I do for every new Ubuntu Server
For every Ubuntu server I build, I always take time to configure it should have a good base. A good base for any type of server is having its Time Zone, Locales, and Character sets set correctly. Another software which is usually required is the Ubuntu PPA software repository system.
Here are the commands I usually execute for every Ubuntu server I create:
apt-get -y dist-upgrade
Here are the commands I usually execute for every Ubuntu server I create:
UPDATE AND UPGRADE
apt-get updateapt-get -y dist-upgrade
SETTING TIME ZONE
dpkg-reconfigure tzdata
SETTING LOCALES
locale-gen en_US en_US.UTF-8
INSTALL PPA REPOSITORY SUPPORT
apt-get install software-properties-common python-software-properties
UNINSTALL POSTFIX (if you don't need to send email)
service stop postfix
apt-get remove postfix
apt-get purge
apt-get autoclean
Tuesday, April 17, 2018
Sunday, February 18, 2018
Quick how to guide to create EXT4 partition from a free disk partition using LVM
This is a quick guide to create a usable EXT4 partition from an unused disk partition with LVM.
In this example my UNUSED DISK PARTITION is on /dev/sda4
*** THIS WILL ERASE ALL CONTENT IN /dev/sda4 ***
change partition type by entering 't', '4', '31'
't' is for changing partition type
'4' is to select partition #4
'31' is to select Linux LVM partition type
check to make sure partition type has been set properly by pressing 'p' then ENTER, you should see something like this (I highlighted partition 4 which shows Linux LVM:
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 528383 524288 256M EFI System
/dev/sda3 528384 33554432 33026049 15.8G Linux LVM
/dev/sda4 33556480 586072334 552515855 263.5G Linux LVM
Every LVM volume involves creating these 3 types of sub lvm systems:
1. Physical volume (PV)
2. Volume group (VG) (I named mine vg_ssd_data)
3. Logical volume (LV) (I named mine lv_ssd_data)
Type the following commands:
pvcreate /dev/sda4
vgcreate vg_ssd_data /dev/sda4
lvcreate -l 100%FREE -n lv_ssd_data vg_ssd_data
lvs (this command is optional - only to display your logical volumes - see below)
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data pve twi-a-tz-- 8.25g 0.00 0.55
root pve -wi-ao---- 3.75g
swap pve -wi-ao---- 1.88g
lv_ssd_data vg_ssd_data -wi-a----- 263.46g
In this example my UNUSED DISK PARTITION is on /dev/sda4
*** THIS WILL ERASE ALL CONTENT IN /dev/sda4 ***
STEP 1 - PREPARE THE PARTITION TO TYPE: linux LVM
fdisk /dev/sdachange partition type by entering 't', '4', '31'
't' is for changing partition type
'4' is to select partition #4
'31' is to select Linux LVM partition type
check to make sure partition type has been set properly by pressing 'p' then ENTER, you should see something like this (I highlighted partition 4 which shows Linux LVM:
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 528383 524288 256M EFI System
/dev/sda3 528384 33554432 33026049 15.8G Linux LVM
/dev/sda4 33556480 586072334 552515855 263.5G Linux LVM
STEP 2 - CREATE PV, then VG, then LV
Every LVM volume involves creating these 3 types of sub lvm systems:
1. Physical volume (PV)
2. Volume group (VG) (I named mine vg_ssd_data)
3. Logical volume (LV) (I named mine lv_ssd_data)
Type the following commands:
pvcreate /dev/sda4
vgcreate vg_ssd_data /dev/sda4
lvs (this command is optional - only to display your logical volumes - see below)
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data pve twi-a-tz-- 8.25g 0.00 0.55
root pve -wi-ao---- 3.75g
swap pve -wi-ao---- 1.88g
lv_ssd_data vg_ssd_data -wi-a----- 263.46g
STEP 3 - GET YOUR DEVICE MAPPER NAME
Enter the following command to display all your logical volumes, to get your device mapper path.
(I highlighted my logical volume which shows the device mapper path)
lvdisplay
--- Logical volume ---
LV Path /dev/vg_ssd_data/lv_ssd_data
LV Name lv_ssd_data
VG Name vg_ssd_data
LV UUID dDqnRP-1wt2-UHcI-gE3T-WYle-HtNB-cWbfis
LV Write Access read/write
LV Creation host, time e1, 2018-02-18 10:18:07 -0600
LV Status available
# open 0
LV Size 263.46 GiB
Current LE 67445
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5
--- Logical volume ---
LV Path /dev/pve/swap
LV Name swap
VG Name pve
LV UUID QzAL07-mdzD-RoH5-ulXa-gwGt-FtTN-XRhA4q
LV Write Access read/write
LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
LV Status available
# open 2
LV Size 1.88 GiB
Current LE 480
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/pve/root
LV Name root
VG Name pve
LV UUID 2LuMFi-XzY9-TWNf-uiH3-qdAc-Y5Xa-r6ajdz
LV Write Access read/write
LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
LV Status available
# open 1
LV Size 3.75 GiB
Current LE 960
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Name data
VG Name pve
LV UUID hBfLjZ-Zqib-TMwJ-7dQh-qBrJ-7XHZ-D1G2lQ
LV Write Access read/write
LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
LV Pool metadata data_tmeta
LV Pool data data_tdata
LV Status available
# open 0
LV Size 8.25 GiB
Allocated pool data 0.00%
Allocated metadata 0.55%
Current LE 2112
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
STEP 4 - MAKE THE EXT4 PARTITION
The command below will create the EXT4 partition:
mkfs.ext4 /dev/vg_ssd_data/lv_ssd_data
the result should look similar to this:
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 69063680 4k blocks and 17268736 inodes
Filesystem UUID: 123a79fb-226e-45b2-ab97-bdd8df335538
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
STEP 5 - CREATE THE DIRECTORY WHERE WE WILL MOUNT THE PARTITION
The following 2 commands will create a directory and set its partition to 777 (all access - this is just for my example - you probably want to restrict your permission)
mkdir /mnt/ssd_data
chmod -R 777 /mnt/ssd_data
STEP 6 - GET UUID USING COMMAND BLKID
The following command 'blkid' will show you the UUID which you will need to mount your newly created partition.
blkid
My result looks like:
/dev/sda2: UUID="72B0-472C" TYPE="vfat" PARTUUID="43003f1e-9cbd-461c-ba1f-b288196eaf8d"
/dev/sda3: UUID="ceYVkY-WxbN-UQME-i6Gt-frKB-rDeW-StrMMz" TYPE="LVM2_member" PARTUUID="ac2082b2-aed1-432d-8102-86246ab4d738"
/dev/mapper/pve-swap: UUID="d44d4cfc-c6b2-4f75-b24a-a6ec99e6d748" TYPE="swap"
/dev/mapper/pve-root: UUID="d41800f7-bf3a-42fb-bbd2-9f4519d99bd6" TYPE="ext4"
/dev/sda1: PARTUUID="491629a5-bea8-4a61-84a7-b4610e8b4607"
/dev/sda4: UUID="Iv347n-th9t-fC3v-UpUc-bHFN-LKOA-shD5Eg" TYPE="LVM2_member" PARTUUID="bfc4c91b-148b-429c-a9eb-b6d80a1dd685"
/dev/sdb: PTUUID="05ca81c9-9745-4fb2-bd15-ced9e1525169" PTTYPE="gpt"
/dev/sdc: PTUUID="8e2952c8-96a6-4c41-a9a8-0ae9cde93182" PTTYPE="gpt"
/dev/mapper/vg_ssd_data-lv_ssd_data: UUID="123a79fb-226e-45b2-ab97-bdd8df335538" TYPE="ext4"
STEP 6 - ADDING YOUR PARTITION TO FSTAB
The following command, you will edit your FSTAB (filesystem table) to add a line which will tell your computer to AUTOMATICALLY MOUNT the partition everytime the computer starts (cold / warm start)
nano /etc/fstab
add the following line (note the UUID in RED and DIRECTORY in BLUE):
UUID=123a79fb-226e-45b2-ab97-bdd8df335538 /mnt/ssd_data ext4 defaults,noatime,nodiratime,noacl,data=writeback,barrier=0,nobh,errors=remount-ro 0 2
STEP 7 - FINALLY! MOUNT AND CHECK YOUR PARTITION FREE DISK SPACE
The following command will mount all your partition by reading your settings from the filesystem table (/etc/fstab)
mount -a
(mount -a does not have any output when successful)
The following command will show FREE DISK SPACE for all your MOUNTED PARTITIONS:
df -h
Filesystem Size Used Avail Use% Mounted on
udev 24G 0 24G 0% /dev
tmpfs 4.8G 9.2M 4.8G 1% /run
/dev/mapper/pve-root 3.7G 1.8G 1.7G 52% /
tmpfs 24G 45M 24G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 24G 0 24G 0% /sys/fs/cgroup
/dev/fuse 30M 24K 30M 1% /etc/pve
tmpfs 4.8G 0 4.8G 0% /run/user/0
/dev/mapper/vg_ssd_data-lv_ssd_data 259G 61M 246G 1% /mnt/ssd_data
Thursday, February 1, 2018
PHP 5.4 5.5 5.6 Nginx PHP5-FPM - 502 Bad Gateway Issue Solved
I have been battling this issue:
PHP 5.4 5.5 5.6 Nginx PHP5-FPM - 502 Bad Gateway Issue Solved
for several days. Here are the symptoms:
When you execute a PHP script it does not show any output on the browser, just WHITE PAGE!
In the Nginx log you will see error log like this:
2018/02/01 12:56:18 [error] 16526#16526: *122 readv() failed (104: Connection reset by peer) while reading upstream, client:
In the PHP FPM log you will see error log like this:
[pool www] child 21970 exited on signal 11 (SIGSEGV) after 57.041592 seconds from start
This was very difficult to troubleshoot because I literally was getting no useful clue of what is happening.
I tried to upgrade my outdated PHP from 5.4.x to 5.6 but unsuccessful because my Ubuntu server version was so old (12.04 LTS Precise Pangolin) :-(
So I dediced to keep troublshotting by process of elimination.
The breakthrough came when I disabled X-Cache extension! After disabling X-Cache my script WORKS!
At first to test I just removed all the content of the xcache module/extension. Mine was located in:
/etc/php5/conf.d/20-xcache.ini
(I emptied the file) then executed:
service php5-fpm restart
Evidently there was some kind of incompatibility or issue which happened with some other things being upgraded overtime. So I decided to just remove X-Cache all together using this command:
apt-get remove php5-xcache
service php5-fpm restart
Now all my problems have been resolved and I am happy this issue is solved!
PHP 5.4 5.5 5.6 Nginx PHP5-FPM - 502 Bad Gateway Issue Solved
for several days. Here are the symptoms:
When you execute a PHP script it does not show any output on the browser, just WHITE PAGE!
In the Nginx log you will see error log like this:
2018/02/01 12:56:18 [error] 16526#16526: *122 readv() failed (104: Connection reset by peer) while reading upstream, client:
In the PHP FPM log you will see error log like this:
[pool www] child 21970 exited on signal 11 (SIGSEGV) after 57.041592 seconds from start
This was very difficult to troubleshoot because I literally was getting no useful clue of what is happening.
I tried to upgrade my outdated PHP from 5.4.x to 5.6 but unsuccessful because my Ubuntu server version was so old (12.04 LTS Precise Pangolin) :-(
So I dediced to keep troublshotting by process of elimination.
The breakthrough came when I disabled X-Cache extension! After disabling X-Cache my script WORKS!
At first to test I just removed all the content of the xcache module/extension. Mine was located in:
/etc/php5/conf.d/20-xcache.ini
(I emptied the file) then executed:
service php5-fpm restart
Evidently there was some kind of incompatibility or issue which happened with some other things being upgraded overtime. So I decided to just remove X-Cache all together using this command:
apt-get remove php5-xcache
service php5-fpm restart
Now all my problems have been resolved and I am happy this issue is solved!
Wednesday, January 17, 2018
Initial steps to properly setup Ubuntu Server
Every time I deploy a new ubuntu server for some kind of web development project I always have a list of commands I have to execute to prepare the server. These are what I call initial preparation for ubuntu server. The purpose for these initial setup commands to make sure we have the latest updates, set locale settings and setup security logins.
Here are my list of commands for ubuntu initial setup (grouped by purpose)
apt-get upgrade
apt-get install build-essential
apt-get install curl
dpkg-reconfigure locales
dpkg-reconfigure tzdata
nano ~/.ssh/authorized_keys
As you can see... the commands above WILL NOT install any specific server functionality. But it will setup a solid base for you to start building whatever server you need.
Here are my list of commands for ubuntu initial setup (grouped by purpose)
Group 1 - Initial Updates
apt-get updateapt-get upgrade
apt-get install build-essential
apt-get install curl
Group 2 - Set Local Settings (language and time zone)
locale-gen en_US en_US.UTF-8dpkg-reconfigure locales
dpkg-reconfigure tzdata
Group 3 - Setup Security and Login
ssh-keygen -t rsanano ~/.ssh/authorized_keys
(optional) - to support PPA and Python
apt-get install software-properties-commonAs you can see... the commands above WILL NOT install any specific server functionality. But it will setup a solid base for you to start building whatever server you need.
Subscribe to:
Posts (Atom)