- Check your firewall
- Do you use sudo and therefor have different runtime variables (or a different environment)? This couldn’t be confirmed by my colleagues :/
- Check the logfile file permissions if no log-messages show up
In Oracle Linux most of the host-related config can be changed in /etc/sysconfig/
Edit the following files:
- /etc/sysconfig/network
- /etc/hosts
Change suspicious-looking entries in /etc/sysconfig/keyboard from “en” into “de”
Hint for the desktop:
- Move windows: control-windows arrow
Change these files:
- /etc/hosts (fqdn, then shorthostname, seperated via tab)
- /etc/hostname (short hostname)
#equivalents to these:
chkconfig --add <service> chkconfig --level 345 <service> on
chkconfig --del <service>
#are:
update-rc.d <service> defaults update-rc.d <service> start 20 3 4 5
update-rc.d -f <service> removeThe other options can be easily changed in the terminal, but the tab shifting needs to be configured like so:
gsettings set org.gnome.Terminal.Legacy.Keybindings:/org/gnome/terminal/legacy/keybindings/ next-tab '<Primary>Tab'
gsettings set org.gnome.Terminal.Legacy.Keybindings:/org/gnome/terminal/legacy/keybindings/ prev-tab '<Primary><Shift>Tab'Nrpe Tipps:
This assumes an nrpe setup is already at place and only this check has to be added.
It also requires the file check_multi at /usr/lib64/nagios/plugins/ with execute permissions.
- Download it here: https://github.com/flackem/check_multi (?)
# check if multiple disks are attached at all
df -h # df -l if df -h doesnt respond
# check if check_multi config file exists
cat /etc/nagios/check_multi_disk.cmd
# make sure this exists in /etc/nagios/nrpe.cfg:
command[check_disk]=/usr/lib64/nagios/plugins/check_multi -f /etc/nagios/check_multi_disk.cmd -r 32
# check the command locally:
/usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_disk
/usr/lib64/nagios/plugins/check_nrpe -H 127.0.0.1 -c check_disk #alternative for ssl handshake errorExample content of /etc/nagios/check_multi_disk.cmd
command[disk1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /
command[disk2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /home
command[disk3]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /bootWhat to check? Basically everything that starts with /dev:
[root@somehost-blade1 ~]# df -h | grep ^/dev
/dev/mapper/ol_somehost--blade1-root 50G 6.9G 44G 14% /
/dev/mapper/ol_nhhbc015--blade1-home 225G 94M 225G 1% /home
/dev/sda1 497M 168M 330M 34% /bootGet more information on config reload errors:
/usr/lib/icinga2/safe-reload /etc/sysconfig/icinga2Required for the localhost template to work that comes with the icinga installation
yum install nagios-plugins-allIn order to trigger remote nagios-plugins this package is necessary
yum install nagios-plugins-nrpeInstall these packages. Nagios-plugins-all is an overkill, but it is really small so its okay.
yum install -y nrpe nagios-plugins-nrpe nagios-plugins-all xinetd/etc/xinetd.d/nrpe has to exist in a specific way:
cat << EOF > /etc/xinetd.d/nrpe
# default: off
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
type = UNLISTED
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/sbin/nrpe
server_args = -c /etc/nagios/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 monitoring-server
}
EOFRestarting xinetd is required
chkconfig xinetd on
service xinetd restartCheck if the setup works locally
/usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_disk
/usr/lib64/nagios/plugins/check_nrpe -H 127.0.0.1 -c check_disk #alternative for ssl handshake errorIf a connection using telnet on port 22 is possible, but port 5666 shows “no route to host” the reason is probably an iptables-rule.
Check current Iptables rules:
iptables --listWorks on Centos 7:
iptables -A INPUT -s monitoring-server -p tcp -m tcp --dport 5666 -m state --state NEW,ESTABLISHED -j ACCEPT
yum install iptables-services
service iptables reloadThere are a few steps to see the tables in an SQLite database:
Connect to the db
sqlite3 grafana.db # assumes grafana.db exists in current directoryQuery the db
# List the tables in your database:
.tables
# List how the table looks:
.schema tablename
# Print the entire table:
SELECT * FROM tablename;
# List all of the available SQLite prompt commands:
.help
# Close sqlite
.exitWhat to do when you cant start mysql as root (maybe not exactly right)
service mysqld stop
/usr/bin/mysqld start --skip-grant-tables -user=root
# mysqld_safe --skip-grant-tables & # alternatively
mysql -u root
# mysql # alternatively
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;What to do when your mysql wont start generally
service mysqld stop
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
service mysqld startOverall important commands
mysqladmin -u root -p'abc' password '123456' --change root password
show databases;
use testdatabase; --enables you to query the selected database
show tables;
describe testtable; --show available columns / attributes
select * from testtable where id=1\G --display columns nicely; for tables with many columnsSET PASSWORD FOR 'user-name-here'@'hostname' = PASSWORD('new-password');yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmThen check whether it’s enabled
yum repolistSource: https://uhesse.com/2011/06/01/adrci-a-survival-guide-for-the-dba/
[oracle@uhesse ~]$ adrci
ADRCI: Release 11.2.0.2.0 - Production on Wed Jun 1 10:20:08 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
ADR base = "/u01/app/oracle"
adrci> show home
ADR Homes:
diag/tnslsnr/uhesse/listener
diag/rdbms/orcl/orcl
adrci> set homepath <insert one of the ADR homes>
adrci> purge -age 2880 -type trace
adrci> show tracefile -rtDifferences in software architectures:
- x86-64: Initial description for 64-bit architecture
- amd64 : x86-64 for amd or intel processors (basically just a new name for the same thing)
- i386 : 32 bit architecture
Some usefull hacks
#Check whether a folder belongs to a package
rpm -q -whatprovides /etc/profile
#List all installed packages
rpm -qa | less
#Search for a specific package
rpm -qa | grep -i name
#Uninstall a package
rpm -e name
#Update a package with a new rpm in the current directory
rpm -U local_upgrade.rpmFor me this was useful to prevent apt from overwriting my self-compiled git.
sudo apt-mark hold <package>
sudo apt-mark showholdfire this up multiple times
sudo apt-get autoremoveFor CentOS and Red Hat Enterprise Linux 6.x:
# Centos extras repository (contains for example nrpe checks)
sudo wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
sudo rpm -Uvh epel-release-latest-6*.rpm
# RHEL/CentOS 6 32-Bit
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
# RHEL/CentOS 6 64-Bit
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpmAlternatively you can just grab the .repo configration file
# For Oracle Linux 6.x:
cd /etc/yum.repos.d/
wget http://public-yum.oracle.com/public-yum-ol6.repoIf this shows: “Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again” Maybe it is because of old certificates. An alternative would be to use repositorise with only http and not https. However, sticking with https, try:
yum --disablerepo=epel -y update ca-certificatesyum install yum-downloadonly
yum install --downloadonly --downloaddir=<directory> <package>Proxy for cpan
perl -MCPAN -e shell
o conf init /proxy/
http://172.16.8.250:3128
o conf commit
exitProxy for git
git config --global http.proxy http://172.16.8.250:3128; git config --global https.proxy http://172.16.8.250:3128
git config --global --unset http.proxy; git config --global --unset https.proxyProxy for bash
#Just add the following to the end of you bashrc:
export http_proxy=http://172.16.8.250:3128 && export https_proxy=http://172.16.8.250:3128 && export ftp_proxy=http://172.16.8.250:3128
#Unset them:
export http_proxy= && export https_proxy= && export ftp_proxy=#cleanup all branches which were merged
git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs git branch -d
# remove remote tracking branches
git remote prune originHere’s how to do it with rebase and keep both the commit date and the author date:
git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase -f <commit/branch before wrong author and email, or --root to rebase all>Git 2.x Installation on Linux (taken from here: https://oracle-base.com/articles/linux/git-2-installation-on-linux)
The version of Git available from the Yum repositories is typically quite old. This article describes the manual installation of Git 2.x on Linux. The same method should work for all the RHEL clones (Oracle Linux, CentOS) and Fedora.
Install the prerequisite packages and remove the any current Git installation.
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y
yum install gcc perl-ExtUtils-MakeMaker -y
yum remove git -yDownload the latest Git installation from kernel.org and unpack it.
cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-2.2.2.tar.gz
tar xzf git-2.2.2.tar.gzInstall it.
cd git-2.2.2
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc
Test it, by checking the version.
git --versionSet General information required by git
git config --global user.name "flyck"
git config --global user.email "felix.brilej@googlemail.com"
git config --global core.autocrlf false #Leave all line-ending business to the userShow general information required by git
git config user.name
git config user.email
git config http.proxyFixes this error: “Local SSL issuer certificate error”
- Alternatively i could just install that ssl certificate, probably the more advanced solution
git config --global http.sslVerify falseInstall ssh key
# check if ssh-agent is running
ps -e | grep [s]sh-agent
# start the ssh-agent if it's not running
ssh-agent /bin/bash
# Unlock the ssh key
ssh-add ~/.ssh/id_rsagit commit .... git reset --soft HEAD~1
# edit files as needed
git add ... git commit -c ORIG_HEADif your commit is total crap:
git reset --hard HEAD~1Suppose your project is in a directory called “project”, and you want only those commits which touch project/dirB.
git clone project/ subproject/
cd subproject
git filter-branch --prune-empty --subdirectory-filter dirB HEADThe subproject will now contain the git history which touches dirB.
git show-ref -d --tags |
cut -b 42- | # to remove the commit-id
sort |
sed 's/\^{}//' | # remove ^{} markings
uniq -c | # count identical lines
sed 's/2\ refs\/tags\// a /' | # 2 identicals = annotated
sed 's/1\ refs\/tags\//lw /'https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches
A command which gets me out of “detached HEAD” error message and properly connects local and remote branch:
git checkout -b my-crazy-feature origin/feature/my-crazy-featureHow to fetch all remote branches:
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all --tags
git pull --allCounts the contributions in local branches
git log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}'Alternative: install that ssl certificate, probably the more advanced solution
git config --global http.sslVerify false# happens after installing git using the normal ubuntu repositories
apt-get install git
git clone https://tfs.somesite.com
error: gnutls_handshake() failed: A TLS packet with unexpected length was received. while accessing https://tfs.somesite.comsudo apt-get remove git
sudo apt-get install dpkg-dev
# download everything to get ready to compile
mkdir ~/git-openssl
cd ~/git-openssl
sudo apt-get source git
sudo apt-get build-dep git
sudo apt-get install libcurl4-openssl-dev
sudo dpkg-source -x git_1.7.9.5-1.dsc
cd git_1.7.9.5
vim debian/control # replace all instances of “libcurl4-gnutls-dev” with “libcurl4-openssl-dev” (I used sudo vim debian/control) using vim: :%s/libcurl4-gnutls-dev/libcurl4-openssl-dev/gc
sudo dpkg-buildpackage -rfakeroot -uc -b
# if it's faling on test, you can remove the line TEST=test from the file debian/rules (I used sudo vim debian/rules to edit the file)
sudo dpkg -i ../git_1.7.9.5-1_amd64.deb
sudo apt-mark hold git # makes it so git doesn't get overwritten by updatesShow certificate-chain openssl s_client -connect pop.gmx.net:995 -showcerts
- the shown certificat has to copied to a .pem file from BEGIN to END
- next the program “c_rehash” has to be executed in that directory
c_rehash . - in case the parent directory is registered as “sslcertpath” the certificate error is now
resolved
ssl sslcertck sslcertpath /home/rtracker/.fetchmail/certs
Alternative for Ubuntu This is knowledge I gained from a whole lot of debugging, I’m not exactly sure about this one
- Also add the CA as certifcate
- When testing the openssl directly add the CA as a ca-cert file
sudo cp /usr/share/ca-certificates/outlook.dc.somesite.com.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
openssl s_client -CAfile ~/.fetchmail/certs/somesite.hh.pem -connect 10.120.20.218:995 -showcertsConvert a .cer into a .pem file
openssl x509 -inform der -in certificate.cer -out certificate.pemList all of a modules dependencies with just a one liner.
Requires that Devel::Modlist is installed.
perl -d -MDevel::Modlist=nocore script.pl- ssh root@alpha
- enter password
- ssh-keygen -t rsa -P ” -f ~/.ssh/id_dsa
- ssh-copy-id -i ~/.ssh/id_dsa.pub root@omega
- ssh root@omega (for testing)
Enable / Disable remote root access
#Set a root password
sudo passwd root
#Reverting that back:
sudo passwd -l rootAllow remote root login: in /etc/ssh/sshd_config: # PermitRootLogin yes service ssh reload
Execute one and the same bash-command on multiple systems
mpssh -f ~/banks.txt -v "uptime"Some quick commands:
# check information comming from selinux:
tail /var/log/audit/audit.log
# audit2allow tool is part of the following package (turns audit logs to allow-policies):
yum install setroubleshoot
# increase loglevel:
semodule -DB- Delete snapshots (need permission of people in charge for this)
- Using the vsphere interface, add a harddisk-device to the system
- Identify the new harddisk (a reboot might be required)
fdisk -l # The disk that doesnt have a valid partition table is the one we just added- SCSI bus might need to be rescanned, therefor do the following:
echo "- - -" > /sys/class/scsi_host/hostX/scan #do this for all hosts in hopes to find the correct one
- SCSI bus might need to be rescanned, therefor do the following:
- Format the identified disk (optional, disk partition is not necessary for data-only disks)
fdisk /dev/identified_diskwhat follows is an interactive dialog
- “n” for “new Partition”
- “p” for “primary partition”
- “1” for partition number, since so far we dont have any partition number on this disk
- first cylinder: “enter”
- last cylinder: “enter”
- “t” to change the partitinos system ID, in this case “1” will be set automatically
- Hex Code: 8e for Linux LVM
- “w” to write the changes and exit
- Alternatively you can also use cfdisk, for me cfdisk was able to create a proper partition while fdisk couldnt
- Check on those changes by firing um fdisk again
fdisk -l - Add the newly created disk to the volumegroup
- pvcreate <disk>
- vgdisplay
- vgextend <volumegroup> <disk>
- pvscan
- Add the added space to the volumepath
- Extend the volumepath
lvdisplay lvextend <volumepath> <disk> # alternatively: lvextend -l +100%FREE -n <volumepath>
- Extend the volumepath
- Extend the filesystem. For extX file systems fire up the following:
resize2fs <volumepath>
vim /etc/udev/rules.d/70-persistent-net.rules be carefull when more than one adapter is present. otherwise: delete the first block and change the last word in the second block to from eth1 eth0
Handy tool to analyze full disks: ncdu
Only display the filesize and filename
ls -lh | awk '{print $5 "\t" $9}'Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37
In ubuntu other motds may come from /etc/update-motd/
echo -en "\033[1;34m" > /etc/motd
echo "Text of your motd file....." >> /etc/motd
echo -en "\033[0m" >> /etc/motdPut one of the following settings in ~/.bashrc
# yellow (for non-root users)
export PS1='\[\033[33m\]\u@\H:\w \[\033[m\]'
# red (for root)
export PS1='\[\033[1;31m\]\u@\H:\w \[\033[m\]'More good examples
There are multiple solutions for this, it might be interesting looking into this indepth
firefox & disown
firefox &
firefox #now press C-zUse the “at”-tool to reset the config after 5 minutes (at-jobs). Useful for ipconfig or firewall config-changes to ensure connectivity.
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtimeList the privileges like this:
sudo -l -U myuserHow to read the syntax: http://toroid.org/sudoers-syntax
more useful examples: http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
rsync -avz source root@192.168.0.1:/destination/Warning! Cronjobs may restart every minute and as a side effect send report-mails if an error occurs.
Sample cronjob:
59 23 * * * /home/john/bin/backup.sh > /home/john/logs/backup.log 2>&1The normal way:
curl http://somesite/file1 > file1
curl http://somesite/file2 > file2
diff file1 file2Using process substitution we can have this way faster:
diff <(curl http://somesite/file1) <(curl http://somesite/file2)Process substitution gives you similar capabilities to piping. Except piping only allows you to pipe the output from a single command into another. In the diff scenario, we need to pipe the output from mutltiple commands into another. And that’s what process substitution allows us to do.
grep -iE "(warning|error|critical)" /var/log/fetchmail.log
# -i flag to ignore the case
# -E flag to enable regular expressionsPrerequesite: Have another system in the same subnet (we call it System A)
#From system A
arp -a
nhhrvl038 (10.120.38.254) at 00:24:a8:68:c3:00 [ether] on eth0
#Ping them once from System A
ping system_b_IP
#Again from system A
arp -a
nhhrvl038 (10.120.38.254) at 00:24:a8:68:c3:00 [ether] on eth0
? (system_b_IP) at 00:0c:29:46:b5:55 [ether] on eth0find -type f -exec sed -i -e 's/sqlplus/sqlplus64/g' {} \;
#search for string in current directory
grep -R 'string' dir/
# fill in a specific configuration:
sudo -E sed -i -e "s/password_secret =.*/password_secret = $(pwgen -s 128 1)/" /etc/graylog/server/server.confperl -MCPAN -e 'my $c = "CPAN::HandleConfig";
$c->load(doit => 1, autoconfig => 1);
$c->edit(prerequisites_policy => "follow"); $c->edit(build_requires_install_policy => "yes");
$c->commit'Example from AGerler:
cat /etc/logrotate.d/fetchmail
/var/log/fetchmail.log {
weekly
create 0644 rtracker adm
rotate 4
compress
delaycompress
}- weekly: time interval
- create: chmod parameter, owner und group
- rotate: Amount of “rotates” a logfile persists before it gets deleted
- compress: whether the log file should be zipped or not
- delaycompress: the log only gets zipped after the rotation has been completed (file-handle reasons)
Reduce a logfile to its last 200 lines while preserving the access rights.
logfile="/path/to/logfile"; echo "$(tail -n 200 $logfile)" > $logfilemount -t iso9660 /dev/scd0 /media/cdrom/Look at opened ports:
netstat -tulpenLook at the processes behind them (actually active ports):
# Use a grep filter here because you will be getting way too much info
netstat -tapen | grepLowercase filenames
for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; doneReplace blanks in filenames with _
for i in *; do mv "${i}" `echo ${i} | sed 's/ /_/g'`; done- Download final package sources from here: http://ftp.gnu.org/gnu/screen/
- Install required packages
yum remove screen # remove the preinstalled screen version yum install ncurses-devel # fixes the termcap error you might get yum install gcc # fixes a whole bunch of requirement errors
ps -ef | grep certain_usertar -xzf datei.tar.gz- -x extract
- -f file to be unpacked
- -z first gzip, then tar
http://brendangregg.com/ebpf.html
Using the terminal:
df -h #check if disk-space is available
df -i #show inodes as additional information
free -mh #show RAM and swap
lscpu # Show CPU information (number of cores, etc.)
mytop -u root --prompt # current mysql performance, inklusive Sessions:
vmstat 2 10 # Gives hints about CPU and memory during execution of performance-impaired process
iostat -xk 2 12 # Gives hints about I/O during execution of performance-impaired process
cat /proc/meminfo # Infos about processes in general
htop # Which processes take the most storage? Careful, green means actual space, yellow means provisionedUsing vSphere:
- Check the VMs “Perfomance”-Tab, the CPU and RAM specifically
- Check the Hypervisors “Performance”-Tab (sort by hosts and clusters)
- Check the used Storages for Warnings
A big tool which does it all (but may be complicated to use):
sar
ksar # graphical interfaceTo debug binaries that misbehave and dont give obvious logs try the following:
- Look in the system messages log (/var/log/messages)
- Use strace and look out for file permission errors which might cause the binary to stop
strace -pid <PID> -f
- Debug the binary with gdb (u are going pretty deep in here)
strace -f pid-file (child-threads followen) (not confirmed)Short of that, you can always look in the process init script. For instance, the SSH daemon is started with the script in /etc/init.d/sshd. Sometimes the PID will be defined there (search for pid, PID, PIDFILE, PID_FILE, etc.). For anything that sources /etc/init.d/functions, the PID will live in /var/run/*.pid.