20141210-1 选题

This commit is contained in:
DeadFire 2014-12-10 16:16:48 +08:00
parent 5cdb8d3f4e
commit 0c763de017
3 changed files with 499 additions and 0 deletions

View File

@ -0,0 +1,102 @@
How to configure rsyslog client for remote logging on CentOS
================================================================================
**rsyslog** is an open source utility widely used on Linux systems to forward or receive log messages via TCP/UDP protocols. rsyslog daemon can be configured in two scenarios. Configured as a log collector server, rsyslog daemon can gather log data from all other hosts in the network, which are configured to send their internal logs to the server. In another role, rsyslog daemon can be configured as a client which filters and sends internal log messages to either a local folder (e.g. /var/log) or a remote rsyslog server based on routing facility.
Assuming that you already have a rsyslog server [up and running][1] on your network, this guide will show you how to set up a CentOS system to route its internal log messages to a remote rsyslog server. This will greatly improve your system's disk usage, especially if you don't have a separate large partition dedicated for /var directory.
### Step One: Install Rsyslog Daemon ###
On CentOS 6 and 7, rsyslog daemon comes preinstalled. To verify that rsyslog is installed on your CentOS system, issue the following command:
# rpm -qa | grep rsyslog
# rsyslogd -v
![](https://farm8.staticflickr.com/7502/15988316295_ac2e07e7f3_z.jpg)
If for some reason rsyslog daemon is missing on your system, issue the following command to install it:
# yum install rsyslog
### Step Two: Configure Rsyslog Daemon as a Client ###
The next step is to transform your CentOS machine into a rsyslog client which sends all of its internal log messages to the central remote log server.
To do so, open the main rsyslog configuration file located in /etc path with your favorite text editor:
# nano /etc/rsyslog.conf
After the file is opened for editing, you need to add the following statement at the bottom of the file. Replace the IP address with your remote rsyslog server's IP address.
*.* @192.168.1.25:514
The above statement tells rsyslog daemon to route every log message from every facility on the system to the remote rsyslog server (192.168.1.25) on UDP port 514.
If for some reasons you need a more reliable protocol like TCP, and the rsyslog server is configured to listen for TCP connections, you must add an extra @ character in front of the remote host's IP address as in the below excerpt:
*.* @@192.168.1.25:514
Note that you can also replace the IP address of the rsyslog server with its DNS name (FQDN).
If you want to forward log messages from a specific facility only, let's say kernel facility, then you can use the following statement in your rsyslog configuration file.
kern.* @192.168.1.25:514
Once you have modified the configuration, you need to restart the daemon to activate the change:
**On CentOS 7:**
# systemctl restart rsyslog.service
**On CentOS 6:**
# service rsyslog restart
In another scenario, let's assume that you have installed an application named "foobar" on your machine, which generates logs to /var/log/foobar.log file. Now you want to direct only its logs to a remote rsyslog server. This can be achieved by loading imfile module in the rsyslog configuration as follows.
First load the imfile module. This must be done just once.
module(load="imfile" PollingInterval="5")
Then specify the path to the log file that the imfile module should monitor:
input(type="imfile"
File="/var/log/foobar.log"
Tag="foobar"
Severity="error"
Facility="local7")
Finally, direct local7 facility to the remote rsyslog server:
local7.* @192.168.1.25:514
Don't forget to restart rsyslog daemon.
### Step Three: Enable Rsyslog Daemon to Auto-start ###
To automatically start rsyslog client after every system reboot, run the following command to enable it system-wide:
**On CentOS 7:**
# systemctl enable rsyslog.service
**On CentOS 6:**
# chkconfig rsyslog on
### Summary ###
In this tutorial I demonstrated how to turn a CentOS system into rsyslog client to force it to send its log messages to a remote rsyslog server. Here I assume that the connection between a rsyslog client and rsyslog server is secure (e.g., within corporate network protected by a firewall). Under any circumstances do not configure a rsyslog client to forward log messages over insecure networks or, especially, over the Internet as the syslog protocol is a clear-text protocol. For secure transmission, consider encrypting syslog messages using [TLS/SSL][2].
--------------------------------------------------------------------------------
via: http://xmodulo.com/configure-rsyslog-client-centos.html
作者:[Caezsar M][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/caezsar
[1]:http://xmodulo.com/configure-syslog-server-linux.html
[2]:http://www.rsyslog.com/doc/rsyslog_tls.html

View File

@ -0,0 +1,248 @@
How to create a custom backup plan for Debian with backupninja
================================================================================
Backupninja is a powerful and highly-configurable backup tool for Debian based distributions. In the [previous tutorial][1], we explored how to install backupninja and how to set up two backup actions for the program to perform. However, we should note that those examples were only "the tip of the iceberg," so to speak. In this post we will discuss how to leverage custom handlers and helpers that allow this program to be customized in order to accomplish almost any backup need that you can think of.
And believe me - that is not an overstatement, so let's begin.
### A Quick Review of Backupninja ###
One of backupninja's distinguishing features is the fact that you can just drop plain text configuration or action files in /etc/backup.d, and the program will take care of the rest. In addition, we can write custom scripts (aka "handlers") and place them in /usr/share/backupninja to handle each type of backup action. Furthermore, we can have these scripts be executed via ninjahelper's ncurses-based interactive menus (aka "helpers") to guide us to create the configuration files we mentioned earlier, minimizing the chances of human error.
### Creating a Custom Handler and Helper ###
Our goal in this case is to create a script to handle the backup of chosen home directories into a tarball with either gzip or bzip2 compression, excluding music and video files. We will simply name this script home, and place it under /usr/backup/ninja.
Although you could achieve the same objective with the default tar handler (refer to /usr/share/backupninja/tar and /usr/share/backupninja/tar.helper), we will use this approach to show how to create a useful handler script and ncurses-based helper from scratch. You can then decide how to apply the same principles depending on your specific needs.
Note that since handlers are sourced from the main script, there is no need to start with #!/bin/bash at the top.
Our proposed handler (/usr/share/backupninja/home) is as follows. It is heavily commented for clarification. The getconf function is used to read the backup action's configuration file. If you specify a value for a variable here, it will override the corresponding value present in the configuration file:
# home handler script for backupninja
# Every backup file will identify the host by its FQDN
getconf backupname
# Directory to store backups
getconf backupdir
# Default compression
getconf compress
# Include /home directory
getconf includes
# Exclude files with *.mp3 and *.mp4 extensions
getconf excludes
# Default extension for the packaged backup file
getconf EXTENSION
# Absolute path to date binary
getconf TAR `which tar`
# Absolute path to date binary
getconf DATE `which date`
# Chosen date format
DATEFORMAT="%Y-%m-%d"
# If backupdir does not exist, exit with fatal error
if [ ! -d "$backupdir" ]
then
mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
fi
# If backupdir is not writeable, exit with fatal error as well
if [ ! -w "$backupdir" ]
then
fatal "Directory $backupdir is not writable"
fi
# Set the right tar option as per the chosen compression format
case $compress in
"gzip")
compress_option="-z"
EXTENSION="tar.gz"
;;
"bzip")
compress_option="-j"
EXTENSION="tar.bz2"
;;
"none")
compress_option=""
;;
*)
warning "Unknown compress filter ($tar_compress)"
compress_option=""
EXTENSION="tar.gz"
;;
esac
# Exclude the following file types / directories
exclude_options=""
for i in $excludes
do
exclude_options="$exclude_options --exclude $i"
done
# Debugging messages, performing backup
debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
-f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
$includes
# Redirect standard output to a file with .list extension
# and standard error to a file with .err extension
$TAR -c -p -v $compress_option $exclude_options \
-f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
$includes \
> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
[ $? -ne 0 ] && fatal "Tar backup failed"
Next, we will create our helper file (/usr/share/backupninja/home.helper) so that our handlers shows up as a menu in ninjahelper:
# Backup action's description. Separate words with underscores.
HELPERS="$HELPERS home:backup_of_home_directories"
home_wizard() {
home_title="Home action wizard"
backupname=`hostname --fqdn`
# Specify default value for the time when this backup actions is supposed to run
inputBox "$home_title" "When to run this action?" "everyday at 01"
[ $? = 1 ] && return
home_when_run="when = $REPLY"
# Specify default value for backup file name
inputBox "$home_title" "\"Name\" of backups" "$backupname"
[ $? = 1 ] && return
home_backupname="backupname = $REPLY"
backupname="$REPLY"
# Specify default directory to store the backups
inputBox "$home_title" "Directory where to store the backups" "/var/backups/home"
[ $? = 1 ] && return
home_backupdir="backupdir = $REPLY"
# Specify default values for the radiobox
radioBox "$home_title" "Compression" \
"none" "No compression" off \
"gzip" "Compress with gzip" on \
"bzip" "Compress with bzip" off
[ $? = 1 ] && return;
result="$REPLY"
home_compress="compress = $REPLY "
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$home_title: Includes"
formItem "Include:" /home/gacanepa
formDisplay
[ $? = 0 ] || return 1
home_includes="includes = "
for i in $REPLY; do
[ -n "$i" ] && home_includes="$home_includes $i"
done
done
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$home_title: Excludes"
formItem "Exclude:" *.mp3
formItem "Exclude:" *.mp4
# Add as many “Exclude” text boxes as needed to specify other exclude options
formItem "Exclude:"
formItem "Exclude:"
formDisplay
[ $? = 0 ] || return 1
home_excludes="excludes = "
for i in $REPLY; do
[ -n "$i" ] && home_excludes="$home_excludes $i"
done
done
# Save the config
get_next_filename $configdirectory/10.home
cat > $next_filename <<EOF
$home_when_run
$home_backupname
$home_backupdir
$home_compress
$home_includes
$home_excludes
# tar binary - have to be GNU tar
TAR `which tar`
DATE `which date`
DATEFORMAT "%Y-%m-%d"
EXTENSION tar
EOF
# Backupninja requires that configuration files be chmoded to 600
chmod 600 $next_filename
}
### Running Ninjahelper ###
Once we have created our handler script named home and the corresponding helper named home.helper, let's run ninjahelper command to create a new backup action:
# ninjahelper
And choose create a new backup action.
![](https://farm8.staticflickr.com/7467/15322605273_90edaa5bc1_z.jpg)
We will now be presented with the available action types. Let's select "backup of home directories":
![](https://farm9.staticflickr.com/8636/15754955450_f3ef82217b_z.jpg)
The next screens will display the default values as set in the helper (only 3 of them are shown here). Feel free to edit the values in the text box. Particularly, refer to the scheduling section of the documentation for the right syntax for the when variable.
![](https://farm8.staticflickr.com/7508/15941578982_24b680e1c3_z.jpg)
![](https://farm8.staticflickr.com/7562/15916429476_6e84b307aa_z.jpg)
![](https://farm8.staticflickr.com/7528/15319968994_41705b7283_z.jpg)
When you are done creating the backup action, it will show in ninjahelper's initial menu:
![](https://farm8.staticflickr.com/7534/15942239225_bb66dbdb63.jpg)
Then you can press ENTER to show the options available for this action. Feel free to experiment with them, as their description is quite straightforward.
Particularly, "run this action now" will execute the backup action in debug mode immediately regardless of the scheduled time:
![](https://farm8.staticflickr.com/7508/15754955470_9af6251096_z.jpg)
Should the backup action fail for some reason, the debug will display an informative message to help you locate the error and correct it. Consider, for example, the following error messages that were displayed after running a backup action with bugs that have not been corrected yet:
![](https://farm9.staticflickr.com/8662/15754955480_487d040fcd_z.jpg)
The image above tells you that the connection needed to complete the backup action could not be completed because the remote host seems to be down. In addition, the destination directory specified in the helper file does not exist. Once you correct the problems, re-run the backup action.
A few things to remember:
- If you create a custom script in /usr/share/backupninja (e.g., foobar) to handle a specific backup action, you also need to write a corresponding helper (e.g., foobar.helper) in order to create, through ninjahelper, a file named 10.foobar (11 and onward for further actions as well) in /etc/backup.d, which is the actual configuration file for the backup action.
- You can execute your backups at any given time via ninjahelper as explained earlier, or have them run as per the specified frequency in the when variable.
### Summary ###
In this post we have discussed how to create our own backup actions from scratch and how to add a related menu in ninjahelper to facilitate the creation of configuration files. With the previous [backupninja article][2] and the present one I hope I've given you enough good reasons to go ahead and at least try it.
--------------------------------------------------------------------------------
via: http://xmodulo.com/create-custom-backup-plan-debian.html
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:http://xmodulo.com/backup-debian-system-backupninja.html
[2]:http://xmodulo.com/backup-debian-system-backupninja.html

View File

@ -0,0 +1,149 @@
How to use Evernote from the command line on Linux
================================================================================
This week let's continue our journey into the depth of the Linux command line to manage and organize information. After managing [your personal expenses][1] from the command line, I propose you to manage your notes from the command line, in particular, when your notes are stored in Evernote. In case you have never heard about it, [Evernote][2] specializes in a user-friendly online service for note-taking with cloud synchronization across multiple devices. Besides offering fancy web-based APIs, Evernote has released Evernote clients for Windows, Mac, [Android][3] and iOS. However, there is, up to today, no official Linux client available. Hopefully, among the plethora of unofficial Linux programs, one emerges and attracts all the command line warriors that we are: [Geeknote][4]
### Installation of Geeknote ###
Geeknote is developed in Python. So before trying anything, make sure that you have Python (version 2.7 preferably) and git installed.
#### Debian, Ubuntu and Linux Mint ####
$ sudo apt-get install python2.7 git python-setuptools
$ git clone git://github.com/VitaliyRodnenko/geeknote.git
$ cd geeknote
$ sudo python2.7 setup.py install
#### Fedora or CentOS/RHEL ####
$ sudo yum install git
$ git clone git://github.com/VitaliyRodnenko/geeknote.git
$ cd geeknote
$ sudo python setup.py install
#### Arch Linux ####
For Arch Linux users, just use the package from the [AUR][5].
### Basic Usage of Geeknote ###
Once you installed Geeknote, you should link Geeknote with your Evernote account with:
$ geeknote login
Then enter your email address, your password, and your two-factor authentication code. If you do not have the latter, just ignore it and press ENTER.
![](https://farm8.staticflickr.com/7525/15761947888_7bc71bf216_o.jpg)
Obviously you need an Evernote account to do all of this, so go register first.
Once you are all set and ready, you can start playing around, creating new notes and editing them.
But first, you should set your favorite text editor with:
$ geeknote settings --editor vim
Then, the general syntax to create a new note is:
$ geeknote create --title [title of the new note] (--content [content] --tags [comma-separated tags] --notebook [comma-separated notebooks])
In the above, only the title field is required, which corresponds to the title of the new note. The other flags serve to add additional metadata for the note: add some tag(s) as relevant keywords for your note, and specify in which notebook(s) to place the note. Also, if your title or content contain spaces, don't forget to place them in quotation marks.
For example:
$ geeknote create --title "My note" --content "This is a test note" --tags "finance, business, important" --notebook "Family"
Naturally, the next step is to edit your notes. The syntax is very similar:
$ geeknote edit --note [title of the note to edit] (--title [new title] --tags [new tags] --notebook [new notebooks])
Note that the optional parameters such as title, tags, and notebook, serve to modify the metadata of the note. For example, you can rename a note with:
$ geeknote edit --note [old title] --title [new title]
Now that the basis of creating and editing is done, the more advanced features are search and deletion. You can search through your notes with the syntax:
$ geeknote find --search [text-to-search] --tags [comma-separated tags] --notebook [comma-separated notebooks] --date [date-or-date-range] --content-search
By default, the above command will search notes by their titles. With "--content-search" option, it will search notes by their content.
For example:
$ geeknote find --search "*restaurant" --notebooks "Family" --date 31.03.2014-31.08.2014
Show all the notes with a specific title by running:
$ geeknote show [title]
![](https://farm8.staticflickr.com/7538/15327089024_32867cded6_o.jpg)
My favorite trick though is probably to use:
$ geeknote show "*"
which will display all your notes and allow you to chose one in particular.
And remove a note with:
$ geeknote remove --note [title]
Be careful as this is a real removal. It will delete the note from your cloud storage.
Finally, there are a lot of options to manage tags and notebooks. I think that the most useful one is probably to display the list of notebooks.
$ geeknote notebook-list
![](https://farm8.staticflickr.com/7472/15762063420_43e3ee17da_o.jpg)
From there, everything is pretty similar. As you can guess, listing all your tags is via:
$ geeknote tag-list
Creating a notebook is done via:
$ geeknote notebook-create --title [notebook title]
While creating a tag is:
$ geeknote tag-create --title [tag title]
Once you get the hang of it, the syntax is really coherent and clear, which is very appreciable.
If you still want more, don't forget to go checkout the [official documentation][6].
### Bonus ###
As a bonus, Geeknote comes with the utility gnsync, which allows for file synchronization between your Evernote account and your local computer. However, I find its syntax a bit dry:
$ gnsync --path [where to sync] (--mask [what kind of file to sync] --format [in which format] --logpath [where to write the log] --notebook [which notebook to use])
What all of this means is the following.
- **--path /home/adrien/Documents/notes/**: location of note files to synchronize with Evernote.
- **--mask "*.txt"**: synchronize only plain text files. By default, gnsync will try to sync every file.
- **--format markdown**: whether you want them as plain or markdown format (the default is plain).
- **--logpath /home/adrien/gnsync.log**: where to write the log for synchronization. In case it goes wrong, gnsync will write logging information there.
- **--notebook "Family"**: in which notebook to synchronize note files. Note that if you leave it empty, a new notebook named after your synced folder will be created.
To conclude, Geeknote is a fancy little command-line client for Evernote. I personally don't use Evernote that much, but it remains pretty nice and useful. The command line aspect makes it both geeky and easy to combine with a shell script of some sort. Also, there exists a fork program of Geeknote on Git, named [geeknote-improved-git][7] in Archlinux AUR, which pretends to have a few more features and a more active development than the other branch. From what I could see, it is really worth taking a look at.
What do you think of Geeknote? Is it something you would consider using? Or would you rather stick to the traditional applications? Let us know in the comments.
--------------------------------------------------------------------------------
via: http://xmodulo.com/evernote-command-line-linux.html
作者:[Adrien Brochard][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/adrien
[1]:http://xmodulo.com/manage-personal-expenses-command-line.html
[2]:https://evernote.com/
[3]:http://xmodulo.com/go/android_tutorial
[4]:http://www.geeknote.me/
[5]:https://aur.archlinux.org/packages/geeknote-git/
[6]:http://www.geeknote.me/documentation/
[7]:https://aur.archlinux.org/packages/geeknote-improved-git/