Labels

Monday, April 23, 2012

How to use YUM to install and uninstall packages

Introduction
To update the system applying the most recent corrective patches of security and to the operating system is not as difficult as many do not suppose, nor either must be a hell of dependencies between packages RPM as some others argue. The reality of the things is that it is much very simple and single requires of good bandwidth or very many patience. Next we presented/displayed the procedures to use yum and to make easily what some denominate "horrible, difficult and complicated ".

Please note there are some changes that apply to Fedora Core 3. You will need to install GPG Key for yum in FC3.

Creating Yum Repo's For FC3.

To update system. Update of the system with all the dependencies that are necessary:

Code:
yum update
Searches. To make a search of some package or term in the data base in some of the formed deposits yum in the system:

Code:
 yum search any-package
Example:

Code:
yum search httpd
I hope this will help you understand how to use yum more effeciently. Any erros in this how please notify me.
Consultation of information. To consult the information contained in a package in individual:

Code:
 yum info any-package
Example:

Code:
yum info httpd
Installation of packages. Installation of paquetería with automatic resolution of dependencies:

Code:
 yum install any-package
Example.

Code:
yum install gkrellm
Uninstalling packages. Desinstalación of packages along with everything what it depends on these:

Code:
yum remove any-package
Example.

Code:
yum remove gkrellm
Listing Packages. The following thing will list all the packages available in the data base yum and that can settle:

Code:
 available yum list|less
The following thing will list all the packages installed in the system:

Code:
 yum list installed|less
The following thing will list all the packages installed in the system and that can (they must) be updated:

Code:
 yum list updates|less
Cleaning of the system.

Yum leaves as result of its use heads and packages RPM stored in the interior of the directory located in the route /var/cache/yum/. Particularly the packages RPM that have settled can occupy much space and is by such reason agrees to eliminate them once no longer they have utility. Also it agrees to do the same with the old heads of packages that no longer are in the data base. In order to make the corresponding cleaning, the following thing can be executed:

Code:
 yum clean all
Group install

Code:
yum groupinstall "groupname"

Monday, April 2, 2012

Shell+Script Learning Notes--Basic

1.              To display the current Shell that you are in
# echo $SHELL
2.              How to check the bash shell version
# bash -version
GNU bash, version 3.2.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

3.              There are two ways you can execute this script.

The first is by “sourcing” the script. All this did was send the lines in your file except for those that started with the # to the current shell. So running the script is identical to typing the following at the command prompt
$ . ./simple.sh

The other way you can execute your script is to make it executable and use it as a command.
$ ./simple.sh

specify which shell to run within your script.  #!/bin/bash at the beginning of your script.

How to find the installation path for a software under linux?

You can use:
which fluidpoint
to see where it is executing from (if it's in your $PATH). Or:
find / -name fluidpoint 2> /dev/null
to look for a file named fluipoint and redirect errors on virtual filesystems.
Usually they are in /sbin, /usr/sbin, /usr/local/bin or ~ as a hidden directory.



  
If you use an RPM based distribution (CentOS, RHEL, SUSE, openSUSE) you can use rpm -ql
Example:
rpm -ql findutils
/bin/find
/usr/bin/find
/usr/bin/xargs
/usr/share/doc/packages/findutils
/usr/share/doc/packages/findutils/AUTHORS
/usr/share/doc/packages/findutils/COPYING
/usr/share/doc/packages/findutils/NEWS
/usr/share/doc/packages/findutils/README
/usr/share/doc/packages/findutils/THANKS
/usr/share/doc/packages/findutils/TODO
/usr/share/info/find.info.gz
/usr/share/man/man1/find.1.gz
Things aren't installed to locations in the Linux/UNIX world like they are in the Windows (and even somewhat in the Mac) world. They are more distributed. Binaries are in /bin or /sbin, libraries are in /lib, icons/graphics/docs are in /share, configuration is in /etc and program data is in /var. The /bin,lib,sbin contain the core applications needed for booting and the /usr contains all the other user and system applications

Monday, March 26, 2012

How to install Linux / UNIX *.tar.gz tarball files

1: Uncompress tarball
To uncompress them, execute the following command(s) depending on the extension:
$ tar zxf file.tar.gz
$ tar zxf file.tgz
$ tar jxf file.tar.bz2
$ tar jxf file.tbz2

Now change directory
$ ls
$ cd path-to-software/

# 2: Build and install software

Generally you need to type 3 commands as follows for building and compiling software:
# ./configure
# make
# make install

Where,
  • ./configure will configure the software to ensure your system has the necessary functionality and libraries to successfully compile the package
  • make will compile all the source files into executable binaries.
  • Finally, make install will install the binaries and any supporting files into the appropriate locations.

# 3: Read INSTALL / README file

Each tarball comes with installation and build instructions. Open INSTALL or README file for more information:
$ vi INSTALL

Sysadmin

Friday, March 23, 2012

Undoing a git push

http://stackoverflow.com/questions/1270514/undoing-a-git-push

You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.
Then you need to 'force' push the old reference.
git push -f origin cc4b63bebb6:alpha-0.3.0
You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].
In this scenario, you will have to delete and recreate the branch.
git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0
If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.
git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8

indent multiple lines quickly in vim

http://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi

 
"re-indent" means "indent lines according to your indentation settings." shiftwidth
General Commands
>>   Indent line by shiftwidth spaces
<<   De-indent line by shiftwidth spaces
5>>  Indent 5 lines
5==  Re-indent 5 lines

>%   Increase indent of a braced or bracketed block (place cursor on brace first)
=%   Reindent a braced or bracketed block (cursor on brace)
<%   Decrease indent of a braced or bracketed block (cursor on brace)
]p   Paste text, aligning indentation with surroundings

=i{  Re-indent the 'inner block', i.e. the contents of the block
=a{  Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block

>i{  Increase inner block indent
<i{  Decrease inner block indent
You can replace { with } or B, e.g. =iB is a valid block indent command. Take a look at "Indent a Code Block" for a nice example to try these commands out on.
Also, remember that
.    Repeat last command
, so indentation commands can be easily and conveniently repeated.
Re-indenting complete files
Another common situation is requiring indentation to be fixed throughout a source file:
gg=G  Re-indent entire buffer
You can extend this idea to multiple files:
" Re-indent all your c source code:
:args *.c
:argdo normal gg=G
:wall
Or multiple buffers:
" Re-indent all open buffers:
:bufdo normal gg=G:wall
In Visual Mode
Vjj> Visually mark and then indent 3 lines
In insert mode
These commands apply to the current line:
CTRL-T   insert indent at start of line
CTRL-D   remove indent at start of line
0 CTRL-D remove all indentation from line
Ex commands
These are useful when you want to indent a specific range of lines, without moving your cursor.
:< and :> Given a range, apply indentation e.g.
:4,8>   indent lines 4 to 8, inclusive
Indenting using markers
Another approach is via markers:
ma     Mark top of block to indent as marker 'a'
...move cursor to end location
>'a    Indent from marker 'a' to current location
Variables that govern indentation
You can set these in your .vimrc file.
set expandtab       "Use softtabstop spaces instead of tab characters for indentation
set shiftwidth=4    "Indent by 4 spaces when using >>, <<, == etc.
set softtabstop=4   "Indent by 4 spaces when pressing <TAB>

set autoindent      "Keep indentation from previous line
set smartindent     "Automatically inserts indentation in some cases
set cindent         "Like smartindent, but stricter and more customisable
Vim has intelligent indentation based on filetype. Try adding this to your .vimrc:
if has ("autocmd")
    " File type detection. Indent based on filetype. Recommended.
    filetype plugin indent on
endif

Wednesday, March 21, 2012

Install Eclipse SDK 3.7.1 (Indigo) on Red Hat 4.4.6-3

http://www.if-not-true-then-false.com/2010/linux-install-eclipse-on-fedora-centos-red-hat-rhel/
  1.  yum groupinstall x11
  2. Install Sun/Oracle Java JDK 7 or Java JDK 6     "yum install java-1.6.0-openjdk.x86_64"
  3. Download Eclipse SDK 3.7.1 (Indigo) or Eclipse for C++ developer
  4. pscp source root@host:target
  5. install Xming-6-9-0-31-setup.exe on windows local machine, launch Xming.
  6. Using PUTTY connect to remote server, be sure to set ssh->x11->check "enable x11 forwarding"
  7. change to root user  "su -"
  8. run eclips at background on remote server

PSCP- transfer files between local and remote server

Here's a neat way to transfer files between your Windows PC and your Linux (Ubuntu) project using Ethernet.

PuTTY is a program that connects one device to another over the network.  It supports SSH and Telnet, among others. 

PuTTY is a “client” application that talks to a “host”.  The host must be running an SSH server (which is often the case for iMX Linux enabled systems).

A Windows version exists and this is ideal for transferring files between your Windows PC and a Linux Platform.


Select the Windows Installer version.  This installs the programs and help files you will need.

File transfers can be done using PSCP (Putty Secure CoPy) or by using PSFTP (Putty Secure File Transfer Protocol). 

PSFTP can be launched from the Windows Start.

PSCP must be launched from within a DOS box (StartWingdings"">àRun and enter cmd, then press OK).  Before
running PSCP, you need to set the path variable.  At the DOS command prompt, type

set PATH=C:\Program Files\PuTTY

This assumes you installed PuTTY in C:\Program Files\PuTTY (default).  Note the “\” slash.   

This will only work for the lifetime of that particular console window. To set your PATH more permanently on Windows NT, 2000, and XP, use the Advanced tab of the System Control Panel (right-click on MyComputer then select Properties).  Click the Environment Variables button, high-light “path” and edit it.  Add “;C:\Program Files\PuTTY” at the end of
the line.  You can then verify the path is correct by typing “path” at the DOS prompt.

The format for pscp is straight forward:

pscp [options] source destination

To copy a Windows file to Linux system, at the DOS prompt, type

pscp c:/music.mp3  ubuntu@10.0.0.3:/home/ubuntu/Music

which will copy the file music.mp3 to my Music folder into Linux.  My Ubuntu EVK has an ip address as 10.0.0.3.  (Note that you can use either / or \ for the Windows files and directories, but you must use / when specifying the Linux files.)

The reverse works as well (copy Linux file to Windows)

            pscp ubuntu@10.0.0.3:/home/ubuntu/Music/music.mp3 c:/

This copies the music.mp3 file from Linux into my C root directory.

There are many other options available, including the ability to use the ftp protocol as well.  See the help file for more information.

Starting PSCP
PSCP is a command line application. This means that you cannot just double-click on its icon to run it and instead you have to bring up a console window. With Windows NT, 2000, and XP, it is called a ‘Command Prompt’.

The basics
To receive (a) file(s) from a remote server:
pscp [options] [user@]host:source target
So to copy the file /etc/hosts from the server example.com as user fred to the file c:\temp\example-hosts.txt, you would type:
pscp fred@example.com:/etc/hosts c:\temp\example-hosts.txt
To send (a) file(s) to a remote server:
pscp [options] source [source...] [user@]host:target
So to copy the local file c:\documents\foo.txt to the server example.com as user fred to the file /tmp/foo you would type:
pscp c:\documents\foo.txt fred@example.com:/tmp/foo
You can use wildcards to transfer multiple files in either direction, like this:
pscp c:\documents\*.doc fred@example.com:docfiles
pscp fred@example.com:source/*.c c:\source
However, in the second case (using a wildcard for multiple remote files) you may see a warning saying something like ‘warning: remote host tried to write to a file called ‘terminal.c’ when we requested a file called ‘*.c’. If this is a wildcard, consider upgrading to SSH-2 or using the ‘-unsafe’ option. Renaming of this file has been disallowed’.
This is due to a fundamental insecurity in the old-style SCP protocol: the client sends the wildcard string (*.c) to the server, and the server sends back a sequence of file names that match the wildcard pattern. However, there is nothing to stop the server sending back a different pattern and writing over one of your other files: if you request *.c, the server might send back the file name AUTOEXEC.BAT and install a virus for you. Since the wildcard matching rules are decided by the server, the client cannot reliably verify that the filenames sent back match the pattern.
PSCP will attempt to use the newer SFTP protocol (part of SSH-2) where possible, which does not suffer from this security flaw. If you are talking to an SSH-2 server which supports SFTP, you will never see this warning. (You can force use of the SFTP protocol, if available, with -sftp - see section 5.2.2.6.)
If you really need to use a server-side wildcard with an SSH-1 server, you can use the -unsafe command line option with PSCP:
pscp -unsafe fred@example.com:source/*.c c:\source
This will suppress the warning message and the file transfer will happen. However, you should be aware that by using this option you are giving the server the ability to write to any file in the target directory, so you should only use this option if you trust the server administrator not to be malicious (and not to let the server machine be cracked by malicious people). Alternatively, do any such download in a newly created empty directory. (Even in ‘unsafe’ mode, PSCP will still protect you against the server trying to get out of that directory using pathnames including ‘..’.)

5.2.1.1 user

The login name on the remote server. If this is omitted, and host is a PuTTY saved session, PSCP will use any username specified by that saved session. Otherwise, PSCP will attempt to use the local Windows username.

5.2.1.2 host

The name of the remote server, or the name of an existing PuTTY saved session. In the latter case, the session's settings for hostname, port number, cipher type and username will be used.

5.2.1.3 source

One or more source files. Wildcards are allowed. The syntax of wildcards depends on the system to which they apply, so if you are copying from a Windows system to a UNIX system, you should use Windows wildcard syntax (e.g. *.*), but if you are copying from a UNIX system to a Windows system, you would use the wildcard syntax allowed by your UNIX shell (e.g. *).
If the source is a remote server and you do not specify a full pathname (in UNIX, a pathname beginning with a / (slash) character), what you specify as a source will be interpreted relative to your home directory on the remote server.

5.2.1.4 target

The filename or directory to put the file(s). When copying from a remote server to a local host, you may wish simply to place the file(s) in the current directory. To do this, you should specify a target of .. For example:
pscp fred@example.com:/home/tom/.emacs .
...would copy /home/tom/.emacs on the remote server to the current directory.
As with the source parameter, if the target is on a remote server and is not a full path name, it is interpreted relative to your home directory on the remote server.

5.2.2 Options

PSCP accepts all the general command line options supported by the PuTTY tools, except the ones which make no sense in a file transfer utility. See section 3.8.3 for a description of these options. (The ones not supported by PSCP are clearly marked.)
PSCP also supports some of its own options. The following sections describe PSCP's specific command-line options.

5.2.2.1 -ls list remote files

If the -ls option is given, no files are transferred; instead, remote files are listed. Only a hostname specification and optional remote file specification need be given. For example:
pscp -ls fred@example.com:dir1
The SCP protocol does not contain within itself a means of listing files. If SCP is in use, this option therefore assumes that the server responds appropriately to the command ls -la; this may not work with all servers.
If SFTP is in use, this option should work with all servers.

5.2.2.2 -p preserve file attributes

By default, files copied with PSCP are timestamped with the date and time they were copied. The -p option preserves the original timestamp on copied files.

5.2.2.3 -q quiet, don't show statistics

By default, PSCP displays a meter displaying the progress of the current transfer:
mibs.tar          |   168 kB |  84.0 kB/s | ETA: 00:00:13 |  13%
The fields in this display are (from left to right), filename, size (in kilobytes) of file transferred so far, estimate of how fast the file is being transferred (in kilobytes per second), estimated time that the transfer will be complete, and percentage of the file so far transferred. The -q option to PSCP suppresses the printing of these statistics.

5.2.2.4 -r copies directories recursively

By default, PSCP will only copy files. Any directories you specify to copy will be skipped, as will their contents. The -r option tells PSCP to descend into any directories you specify, and to copy them and their contents. This allows you to use PSCP to transfer whole directory structures between machines.

5.2.2.5 -batch avoid interactive prompts

If you use the -batch option, PSCP will never give an interactive prompt while establishing the connection. If the server's host key is invalid, for example (see section 2.2), then the connection will simply be abandoned instead of asking you what to do next.
This may help PSCP's behaviour when it is used in automated scripts: using -batch, if something goes wrong at connection time, the batch job will fail rather than hang.

5.2.2.6 -sftp, -scp force use of particular protocol

As mentioned in section 5.2.1, there are two different file transfer protocols in use with SSH. Despite its name, PSCP (like many other ostensible scp clients) can use either of these protocols.
The older SCP protocol does not have a written specification and leaves a lot of detail to the server platform. Wildcards are expanded on the server. The simple design means that any wildcard specification supported by the server platform (such as brace expansion) can be used, but also leads to interoperability issues such as with filename quoting (for instance, where filenames contain spaces), and also the security issue described in section 5.2.1.
The newer SFTP protocol, which is usually associated with SSH-2 servers, is specified in a more platform independent way, and leaves issues such as wildcard syntax up to the client. (PuTTY's SFTP wildcard syntax is described in section 6.2.2.) This makes it more consistent across platforms, more suitable for scripting and automation, and avoids security issues with wildcard matching.
Normally PSCP will attempt to use the SFTP protocol, and only fall back to the SCP protocol if SFTP is not available on the server.
The -scp option forces PSCP to use the SCP protocol or quit.
The -sftp option forces PSCP to use the SFTP protocol or quit. When this option is specified, PSCP looks harder for an SFTP server, which may allow use of SFTP with SSH-1 depending on server setup.

5.2.3 Return value

PSCP returns an ERRORLEVEL of zero (success) only if the files were correctly transferred. You can test for this in a batch file, using code such as this:
pscp file*.* user@hostname:
if errorlevel 1 echo There was an error

5.2.4 Using public key authentication with PSCP

Like PuTTY, PSCP can authenticate using a public key instead of a password. There are three ways you can do this.
Firstly, PSCP can use PuTTY saved sessions in place of hostnames (see section 5.2.1.2). So you would do this:
  • Run PuTTY, and create a PuTTY saved session (see section 4.1.2) which specifies your private key file (see section 4.20.7). You will probably also want to specify a username to log in as (see section 4.14.1).
  • In PSCP, you can now use the name of the session instead of a hostname: type pscp sessionname:file localfile, where sessionname is replaced by the name of your saved session.
Secondly, you can supply the name of a private key file on the command line, with the -i option. See section 3.8.3.18 for more information.
Thirdly, PSCP will attempt to authenticate using Pageant if Pageant is running (see chapter 9). So you would do this:
  • Ensure Pageant is running, and has your private key stored in it.
  • Specify a user and host name to PSCP as normal. PSCP will automatically detect Pageant and try to use the keys within it.
For more general information on public-key authentication, see chapter 8.

Thursday, March 8, 2012

Sudo Allows People In Group Admin To Run All Commands

I like the way Ubuntu Linux works - all people in admin groups should able to run all commands after running it via sudo "command-name". How do I setup sudo under CentOS or Red Hat Enterprise Linux to allow all members of the 'admin' group to run all commands?

/etc/sudoers files allows particular users or groups to run various commands as he root user, without needing the root password. This is useful for delegating roles and permissions to other users without sharing the root password. This file must be edited with the visudo command. Login as the root user and enter:
# visudo
Append the following line:
## Allows people in group admin to run all commands
%admin  ALL=(ALL)       ALL
Save and close the file. Finally, add a group called admin:
# groupadd admin
Add a user called vivek (existing user) to group admin:
# usermod -a -G admin vivek
Verify group membership:
# id vivek
Sample Outputs:
uid=5001(vivek) gid=5001(vivek) groups=5001(vivek),10(admin)
Login as user vivek and to run any command as the root type:
$ sudo /etc/init.d/httpd restart
To gain root shell, enter:
$ sudo -s
When prompted for a password, enter vivek's password.

How Do I Keep Track Of All Users In Admin Group?

sudo can log both successful and unsuccessful attempts (as well as errors) to syslog (default is /var/log/secure), a log file, or both. By default sudo will log via syslog but this is changeable at configure time or via the sudoers file.
# tail -f /var/log/secure
# grep something /var/log/secure

Please note that sudo will normally only log the command it explicitly runs. If a user runs a command such as sudo su or sudo sh, subsequent commands run from that shell will not be logged, nor will sudo’s access control affect them. The same is true for commands that offer shell escapes (including most editors).

Wednesday, March 7, 2012

Thursday, January 26, 2012

linux 统计文件个数

查看某文件夹下文件的个数
ls -l |grep "^-"|wc -l or grep -v "^d"

find ./company -type f | wc -l
查看某文件夹下文件的个数,包括子文件夹里的。

ls -lR|grep "^-"|wc -l
查看某文件夹下文件夹的个数,包括子文件夹里的。
ls -lR|grep "^d"|wc -l
说明:
ls -l
长列表输出该目录下文件信息(注意这里的文件,不同于一般的文件,可能是目录、链接、设备文件等)
grep "^-"
这里将长列表输出信息过滤一部分,只保留一般文件,如果只保留目录就是 ^d
wc -l
统计输出信息的行数,因为已经过滤得只剩一般文件了,所以统计结果就是一般文件信息的行数,又由于一行信息对应一个文件,所以也就是文件的个数。

Friday, January 20, 2012

Comparison of InnoDB and MySQL Cluster (ndb)

link from: http://stackoverflow.com/questions/5300490/mysql-cluster-ndb-vs-mysql-replication-innodb-for-rails-3-apps-pros-cons
There is a good comparison of InnoDB and MySQL Cluster (ndb) recently posted to the docs...worth taking a look: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-compared.html
The Cluster architecture consists of a pool of MySQL Servers that are accessed by the application(s); these MySQL Servers don't actually store the Cluster data, the data is partitioned over the pool of data nodes below. Every MySQL Server has access to the data in all of the data nodes. If one MySQL server changes a piece of data then it is instantly visible to all of the other MySQL Servers.
Obviously, this architecture makes it extremely easy to scale out the database. Unlike sharding, the application doesn't need to know where the data is held - it can just load balance across all available MySQL Servers. Unlike scaling out with MySQL replication Cluster allows you to scale writes just as well as reads. New data nodes or MySQL servers can be added to an existing Cluster with no loss of service to the application.
MySQL Cluster's shared-nothing architecture means that it can deliver extremely high availability (99.999%+). Every time you change data, it is synchronously replicated to a second data node; if one data node fails then the applications read & write requests are automatically handled by the backup data node.
Due to the distributed nature of MySQL Cluster, some operations can be slower (for example JOINs that have thousands of interim results - though there is a prototype solution available which addresses this) but others can be very fast and can scale extremely well (e.g. primary key reads and writes). You have the option of storing tables (or even columns) in memory or on disk and by choosing the memory option (with changes checkpointed to disk in the backgoround) transactions can be very quick.
MySQL Cluster can be more complex to set up than a single MySQL server but it can prevent you having to implement sharding or read/write splitting in your application. Swings and roundabouts.
To get the best performance and scalability out of MySQL Cluster you need may need to tweak your application (see Cluster performance tuning white paper: http://www.mysql.com/why-mysql/white-papers/mysql_wp_cluster_perfomance.php). If you own the application this isn't normally a big deal but if you're using someone else's application that you can't modify then it could be a problem.
A final note is that it doesn't need to be all or nothing - you can choose to store some of your tables in Cluster and some using other storage engines, this is a per-table option. Also you can replicate between Cluster and other storage engines (for example, use Cluster for your run-time database and then replicate to InnoDB to generate complex reports).

The easiest and fastest way to try to MySQL Cluster is to use Severalnines Configurator ( www.severalnines.com/config ).
It will automate the deployment for you and setup everything best practice. To run reporting of Cluster using innodb, as Mat suggests, you can look at http://johanandersson.blogspot.com/2009/05/ha-mysql-write-scaling-using-cluster-to.html . Good luck!

Thursday, January 12, 2012