Got error from Apache after upgraded Debian to Jessie (8.x)

I upgraded my Debian server to Jessie yesterday, due to I didn’t update all the configs, I found some errors, and got to fix them.

Error message:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 89 of /etc/apache2/apache2.conf:
Invalid command ‘LockFile’, perhaps misspelled or defined by a module not included in the server
configuration
Action ‘configtest’ failed.
The Apache error log may have more information.

Solution:

Edit /etc/apache2/apache2.conf, replace line 89:
LockFile ${APACHE_LOCK_DIR}/accept.lock
with this line:
Mutex file:${APACHE_LOCK_DIR} default

Another error:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 17 of /etc/apache2/sites-enabled/000-default.conf:
Either all Options must start with + or -, or no Option may.

Action ‘configtest’ failed.
The Apache error log may have more information.

So just add symbol + for the options without prefix symbol and it works again.

Error: Read-only file system on Linux

Today I found that there is a strange situation, in certain mount point on my web server (Debian GNU/Linux 7.8), every process with write behavior will get messages like this (That’s the result from command touch test):

touch: cannot touch `test’: Read-only file system

I don’t think I mount it as read-only, so I check it with(the mount point is /srv):

$ mount | grep srv

And I got:

/dev/sdb1 on /srv type ext4 (ro,relatime,data=ordered)

Very strange … there was something wrong, could I remount it with r/w? I tried:

$ sudo mount -o remount,rw,relatime,data=ordered /srv

Hmmmm …

mount: cannot remount block device /dev/sdb1 read-write, is write-protected

Okay, seems I need to check the filesystem …

$ sudo umount /srv
$ sudo fsck.ext4 /dev/sdb1

The process didn’t take a very long time, just within few mins, and that’s the result:

e2fsck 1.42.5 (29-Jul-2012)
/dev/sdb1: recovering journal
/dev/sdb1 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 796453/122077184 files (3.8% non-contiguous), 321192367/488281498 blocks

Let’s mount it again:

$ sudo mount -o rw,relatime,data=ordered /srv 

Oh, I didn’t get any error message this time, let’s check it again:

$ mount | grep srv

And … it’s good again

/dev/sdb1 on /srv type ext4 (rw,relatime,data=ordered)

Okay, nice … it’s very easy this time, I’ve got some disks with damaged partition before, event I can’t not recognize its partition type, though I fixed it, but I didn’t record the process that time, haha.

How to check battery status in cli under Debian/Ubuntu based Linux?

You may need to install upower via sudo apt-get install upower first

Use upower with parameter -e / --enumerate to list the devices:

peter@peter-MacBookPro ~ $ upower -e
/org/freedesktop/UPower/devices/line_power_ADP1
/org/freedesktop/UPower/devices/battery_BAT0

Then use -i / --show-info with the device path to show the details

peter@peter-MacBookPro ~ $ upower --show-info /org/freedesktop/UPower/devices/battery_BAT0
native-path: BAT0
vendor: *********************************
model: *********************************
power supply: yes
updated: Sat 14 Feb 2015 04:11:52 PM CST (9 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
energy: 7.63 Wh
energy-empty: 0 Wh
energy-full: 55.75 Wh
energy-full-design: 57.7 Wh
energy-rate: 15.946 W
voltage: 10.9 V
time to empty: 28.7 minutes
percentage: 13%
capacity: 96.6205%
History (charge):
1423901482 13.000 discharging
History (rate):
1423901512 15.946 discharging
1423901482 14.978 discharging
1423901452 14.740 discharging
1423901422 16.179 discharging

It’s pretty easy to show all details in one line command:

$ upower -e | xargs -n 1 upower -i
native-path: ADP1
power supply: yes
updated: Sat 14 Feb 2015 09:58:27 AM CST (22532 seconds ago)
has history: no
has statistics: no
line-power
online: no

native-path: BAT0
vendor: *********************************
model: *********************************
power supply: yes
updated: Sat 14 Feb 2015 04:13:52 PM CST (7 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: discharging
energy: 7.08 Wh
energy-empty: 0 Wh
energy-full: 55.75 Wh
energy-full-design: 57.7 Wh
energy-rate: 18.069 W
voltage: 10.846 V
time to empty: 23.5 minutes
percentage: 12%
capacity: 96.6205%
History (charge):
1423901602 12.000 discharging
History (rate):
1423901632 18.069 discharging
1423901602 16.164 discharging
1423901572 15.799 discharging
1423901542 16.767 discharging
batteryCliStatusScreenshot
upower screenshot

Building NAT on Debian GNU/Linux with iptables

interfaces:

eth0(internal):
192.168.1.254
eth1(external):
aaa.bbb.ccc.ddd

enable forwarding:

sudo sysctl net.ipv4.ip_forward=1

iptables commands(can be saved to a shell script):

clean up old rules

iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

accept loopback traffic

iptables -A INPUT -i lo -j ACCEPT

allow internal connections

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

masquerade

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

reject connections from eth1

iptables -A FORWARD -i eth1 -o eth1 -j REJECT

Easy and fast!

backup the rules:


sudo iptables-save > /path/savedConfig

auto load the rules:


sudo sh -c "echo 'pre-up iptables-restore < /path/savedConfig' >> /etc/network/interfaces