Fork me on GitHub
Suzf  Blog

Archive Linux

How-to: Update the Linux kernel

上周有同学问我Linux 如何升级内核, 后来工作之后接触到的是Debian, 内核基本上都是最新的 3.x.x 升级内核也就很简单了, 直接从源里就更新了。趁周末有空的时候我也搞一下, 以备以后工作之需。

本文适用于CentOS 6.X,亲测可行,估计也适用于其他Linux发行版。

How-to: 制作linux趣味字符画

I. figlet

#yum install figlet

#echo "hello world"| figlet
p1

#echo "suzf.net"| figlet
p2

II. cowsay
#yum install cowsay

# 支持的图形
#cowsay  -l
Cow files in /usr/share/cowsay:
beavis.zen bong
...
www

#cowsay  -f tux "Welcome to my blog - suzf.net"
p3

 

How-to: Delete the redundant kernel after CentOS update

First method:
1. the kernel that is being used in the system:
#uname -r
2.6.32-573.3.1.el6.x86_64

2. query system in all of the kernel:
#rpm -qa | grep kernel

3. remove the kernel you want to remove:
(eg, in my system, I want to delete the kernel of kernel-2.6.32-573.1.1.el6.x86_64, and I need to delete all the kernel-2.6.32-573.1.1.el6.x86_64's words.
#yum remove kernel-2.6.32-573.1.1.el6.x86_64

4. after the restart angd then you can see that the kernel was deleted, while the excess of the startup items are automatically deleted.

Second method:
Manually modify the /etc/grub.conf to remove the extra items.

 

How-to: Find out Linux Disk utilization ?

I've already written about finding out Linux / UNIX cpu utilization using various tools. You can use same iostat command to find out disk utilization and for monitoring system input/output device loading by observing the time the physical disks are active in relation to their average transfer rates.

Tomcat 自动更新脚本

之前总是要更新基于 Tomcat 的web项目,而且更新频繁。 手工更新太烦人了,遂写了一个半自动的脚本。已经一年多没接触 Tomcat ,脚本仅供参考 。

#!/bin/bash
# Author: Jeffery.Su
# Mail: [email protected]
# Site: http://suzf.net
# Date: Jun 1,2014
# Version: 1.0.2

# Definite variable
PRO_NAME=javacenter
WORK_PATH=/usr/local/tomcat/webapps
BACK_PATH=/opt/backup/${PRO_NAME}
UPLOAD_PATH=/root/$PRONAME
DATE=$(date '+%Y%m%d')
BACK_NAME="$PRO_NAME-$DATE.tar.gz"
#eval `date "+day=%d; month=%m; year=%Y"`
#BACK_NAME="$PRO_NAME-$year-$month-$day.tar.gz"

# Backup and Gzip the whole folder
[ -d $BACK_PATH ] || mkdir -p $BACK_PATH
cd $WORK_PATH
tar Ppzcf $BACK_PATH/$BACK_NAME $PRO_NAME
echo -e " $(date) Loading backup programmer, please waiting a moment....\n"
if [ $? -eq 0 ];then
echo -e " $(date) Backup the file succeed !\n"
else
echo -e " $(date) Backup the file failed ! please check !!!\n"
return 1;
fi

# Move the current webapps
mv $PRONAME/ $BACK_PATH/$BACK_NAME
rm -rvf $PRONAME.war

# Upload the new webapps
# Check the file complete upload
[ -d $UPLOAD_PATH ] || mkdir $UPLOAD_PATH
mv $UPLOAD_PATH/$PRO_NAME/* .
if [ "$?" == "0" ];then
echo "Please upload the webapps to $UPLOAD_PATH"
sleep 360;
fi

# Restart tomcat
echo -e " $(date) Stop tomcat\n"
../bin/shutdown.sh

i=0
while (($i <5)) do 
  PID=`ps aux|grep tomcat |grep -v "grep\|sh"|awk '{print $2}'` 
  if [[ "$PID" == "" ]];then
    echo "$PID not exits , tomcat hava stop success"
  else 
   echo "$PID is exits , tomcat is running" 
   let "i++" 
   sleep 5; 
   echo "$(date) Forced to stop tomcat" 
   # kill -9 $PID 
  fi 
done 
echo -e "$(date) start tomcat\n" 
../bin/startup.sh 
# Remove the old backups 
find $BACK_PATH -mtime +15 -exec rm -rf {}\; > /dev/null 2>&1

# Watch the log of catalina.out
#tailf ../logs/catalina.out

 

How-to: Using yum with a Proxy Server

Using yum with a Proxy Server

By default, yum accesses network repositories with HTTP. All yum HTTP operations use HTTP/1.1, and are compatible with web proxy servers that support this standard. You may also access FTP repositories, and configure yum to use an FTP proxy server. The squid package provides a proxy service for both HTTP/1.1 and FTP connections.
[Tip] Modifying yum for Network Compatibility

Refer to the man page for yum.conf for information on HTTP settings that may be modified for compatibility with nonstandard web proxy servers. Alternatively, configure yum to use an FTP proxy server, and access repositories that support FTP. The Fedora repositories support both HTTP and FTP.
1. Configuring Proxy Server Access

To enable all yum operations to use a proxy server, specify the proxy server details in /etc/yum.conf. The proxy setting must specify the proxy server as a complete URL, including the TCP port number. If your proxy server requires a username and password, specify these by adding proxy_username and proxy_password settings.

The settings below enable yum to use the proxy server mycache.mydomain.com, connecting to port 3128, with the username yum-user and the password qwerty.

# The proxy server - proxy server:port number
proxy=http://mycache.mydomain.com:3128
# The account details for yum connections
proxy_username=yum-user
proxy_password=qwerty

Example 3. Configuration File Settings for Using A Proxy Server
[Note] Global Settings

If you define a proxy server in /etc/yum.conf, all users connect to the proxy server with those details when using yum.
2. Configuring Proxy Server Access for a Single User

To enable proxy access for a specific user, add the lines in the example box below to the user's shell profile. For the default bash shell, the profile is the file ~/.bash_profile. The settings below enable yum to use the proxy server mycache.mydomain.com, connecting to port 3128.

# The Web proxy server used by this account
http_proxy="http://mycache.mydomain.com:3128"
export http_proxy

Example 4. Profile Settings for Using a Proxy Server

If the proxy server requires a username and password, add these to the URL. To include the username yum-user and the password qwerty, add these settings:

# The Web proxy server, with the username and password for this account
http_proxy="http://yum-user:[email protected]:3128"
export http_proxy

Example 5. Profile Settings for a Secured Proxy Server
[Note] The http_proxy Environment Variable

The http_proxy environment variable is also used by curl and other utilities. Although yum itself may use http_proxy in either upper-case or lower-case, curl requires the name of the variable to be in lower-case.

 

Yum_Faq: unpacking of archive failed on file XXX: cpio: rename

今天对系统进行更新大更新了一百多个包,但唯独一个包安装失败。
错误信息如下: error: unpacking of archive failed on file /etc/inittab: cpio: renamecpio
错误 从字面上上来看应该是拷贝/替换文件错误 , 原因可能是权限控制

[10:31:12][root@XXX ~]#yum upgrade -y
Loaded plugins: fastestmirror
Setting up Upgrade Process
...

Running Transaction
Updating : initscripts-9.03.49-1.el6.centos.x86_64 1/2
Error unpacking rpm package initscripts-9.03.49-1.el6.centos.x86_64
error: unpacking of archive failed on file /etc/inittab: cpio: rename
Verifying : initscripts-9.03.49-1.el6.centos.x86_64 1/2
initscripts-9.03.46-1.el6.centos.1.x86_64 was supposed to be removed but is not!
Verifying : initscripts-9.03.46-1.el6.centos.1.x86_64 2/2

Failed:
initscripts.x86_64 0:9.03.46-1.el6.centos.1 initscripts.x86_64 0:9.03.49-1.el6.centos

Complete!

所以错误应该出现在 /etc/inittab 以至于更新文件无法更改
可能是不可改变的属性已经设置在这个文件之上,让我们先来查看一下。

[10:32:22][root@XXX ~]#lsattr /etc/inittab
----i---------- /etc/inittab

让我们删除这个属性
[10:32:55][root@XXX ~]#chattr -i /etc/inittab

让我们再来执行以下更新 看看问题是否解决
[10:33:07][root@XXX ~]#yum upgrade -y
Loaded plugins: fastestmirror
Setting up Upgrade Process
...

Downloading Packages:
initscripts-9.03.49-1.el6.centos.x86_64.rpm | 945 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : initscripts-9.03.49-1.el6.centos.x86_64 1/2
warning: /etc/sysctl.conf created as /etc/sysctl.conf.rpmnew
Cleanup : initscripts-9.03.46-1.el6.centos.1.x86_64 2/2
Verifying : initscripts-9.03.49-1.el6.centos.x86_64 1/2
Verifying : initscripts-9.03.46-1.el6.centos.1.x86_64 2/2

Updated:
initscripts.x86_64 0:9.03.49-1.el6.centos

Complete!

至此,问题解决。

SysVinit to Systemd Cheatsheet

This is a document to help system administrators who need to understand what commands in systemd replace their old workflow in sysvinit. If you want general information on systemd, refer to systemd.

Note on 'service' and 'chkconfig' commands
The 'service' and 'chkconfig' commands will mostly continue to work as expected in the systemd world, this guide is how to use the native systemctl replacements.

Services

Note that all recent versions of systemctl assume the '.service' if left off. So, 'systemctl start frobozz.service' is the same as 'systemctl start frobozz'

Sysvinit Command Systemd Command Notes
service frobozz start systemctl start frobozz Used to start a service (not reboot persistent)
service frobozz stop systemctl stop frobozz Used to stop a service (not reboot persistent)
service frobozz restart systemctl restart frobozz Used to stop and then start a service
service frobozz reload systemctl reload frobozz When supported, reloads the config file without interrupting pending operations.
service frobozz condrestart systemctl condrestart frobozz Restarts if the service is already running.
service frobozz status systemctl status frobozz Tells whether a service is currently running.
ls /etc/rc.d/init.d/ systemctl (or) systemctl list-unit-files --type=service (or)
ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Used to list the services that can be started or stopped
Used to list all the services and other units
chkconfig frobozz on systemctl enable frobozz Turn the service on, for start at next boot, or other trigger.
chkconfig frobozz off systemctl disable frobozz Turn the service off for the next reboot, or any other trigger.
chkconfig frobozz systemctl is-enabled frobozz Used to check whether a service is configured to start or not in the current environment.
chkconfig --list systemctl list-unit-files --type=service (or) ls /etc/systemd/system/*.wants/ Print a table of services that lists which runlevels each is configured on or off
chkconfig --list | grep 5:on systemctl list-dependencies graphical.target Print a table of services that will be started when booting into graphical mode
chkconfig frobozz --list ls /etc/systemd/system/*.wants/frobozz.service Used to list what levels this service is configured on or off
chkconfig frobozz --add systemctl daemon-reload Used when you create a new service file or modify any configuration

Note that all /sbin/service and /sbin/chkconfig lines listed above continue to work on systemd, and will be translated to native equivalents as necessary. The only exception is chkconfig --list.

Warning.pngAdditional commandsIn SysVinit, services can define arbitrary commands. Examples would be service iptables panic, or service httpd graceful. Native systemd services do not have this ability.Any service that defines an additional command in this way would need to define some other, service-specific, way to accomplish this task when writing a native systemd service definition.

Check the package-specific release notes for any services that may have done this.

Runlevels/targets

Systemd has a concept of targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common sysvinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command. The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd target. Unfortunately, there's no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/$YOURTARGET that takes one of the existing runlevels as a base (you can look at /lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/$YOURTARGET.wants, and then symlink the additional services that you want to enable into that directory. (The service unit files that you symlink live in /lib/systemd/system).

Sysvinit Runlevel Systemd Target Notes
0 runlevel0.target, poweroff.target Halt the system.
1, s, single runlevel1.target, rescue.target Single user mode.
2, 4 runlevel2.target, runlevel4.target, multi-user.target User-defined/Site-specific runlevels. By default, identical to 3.
3 runlevel3.target, multi-user.target Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
5 runlevel5.target, graphical.target Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
6 runlevel6.target, reboot.target Reboot
emergency emergency.target Emergency shell

Changing runlevels:

Sysvinit Command Systemd Command Notes
telinit 3 systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3) Change to multi-user run level.
sed s/^id:.*:initdefault:/id:3:initdefault:/ ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target Set to use multi-user runlevel on next reboot.

Kernel Options:

The above systemd targets can be used when booting. At the GRUB menu, edit the selection to add "systemd.unit=target" (without the double-quotation marks) as a kernel option where target is one of the above. (For example, "rescue.target".)

Tip: the ".target" extention is optional. The "systemd.unit=rescue" kernel option works the same as "systemd.unit=rescue.target".

Original link SysVinit to Systemd Cheatsheet

 

FAQ - &quot;Package Power limit&quot; and &quot;Core power limit&quot; notifications.

Article Summary:

This article provides information on Linux - "Package Power limit" and "Core power limit" notifications.

Environment:

Linux - Various distributions - It seems to affect systems with kernel 2.6.18 and above.
Intel based CPU

Issue:

“Core power limit ” and “Package power limit ” notifications being continuously logged in the /var/log/messages.

Diagnostic Steps:

/var/log/messages will show notifications similar to:
Jun 21 09:34:55 compute-0-15 kernel: CPU7: Core power limit notification (total events = 1)
Jun 21 09:34:55 compute-0-15 kernel: CPU21: Core power limit notification (total events = 1)
Jun 21 09:34:55 compute-0-15 kernel: CPU25: Package power limit notification (total events = 1)
Jun 21 09:34:55 compute-0-15 kernel: CPU3: Package power limit notification (total events = 1)

Resolution:

This issue is currently still being worked by some software vendors.
In the meantime, there are 2 possible workarounds:
Clear PLN flag adding clearcpuid=229 to grub.conf or;
Set the machine's Performance Profile to Max Performance in the BIOS, if that setting is available (Please, be aware that power consumption may increase if this option is chosen).

Note:

Power Limit Notification is a feature that was added to the Sandy Bridge processors from Intel. The notification does not indicate a problem, and should not be reported as a Critical-level message.
The occurrence of the power limit notification is routine, and the system should not be reporting the messages. They can be ignored.