应用安装手册
整理:罗代均 [email protected]
转自:http://hi.baidu.com/luodaijun/blog/item/c9cbddb4c302a4628ad4b2d7.html
目录
1.Linux常用命令2
2.一块网卡绑定多个IP3
3.安装JDK4
4.安装Tomcat4
5.安装Nginx5
6.安装Apache FtpServer5
7.安装memcached6
9.安装ffmpeg7
10.Nginx双机故障转移shell脚本8
1.Linux常用命令
查看编辑文本文件,用图形化的gedit
gedit /filepath
查看环境变量
env
设置别名
alias 别名='原命令'
如: alias startTomcat='/usr/local/tomcat/bin/startup.sh'
查看当前所在目录
pwd
查看磁盘空间使用情况
df
列出所有文件,包括隐藏文件
ls -l –a
设置所有用户都具有读写权限
chmod 777 /data/www/index.html
递归下级目录
chmod -R 777 /data/www
设置文件为可执行
chmod 755 /home/oracle/startOracle.sh
或者chmod +x /home/oracle/startOracle.sh
改变文件所有者
chown user:usergroup /path
chown -R user:usergroup /path
查看进程,并用正则过滤
ps -ef | grep java
杀死进程
kill -9 pid
pkill -9 process_name
如: pkill -9 java , pkill -9 nginx
动态更新显示文件内容,查看不断变化的文件
tail -f /usr/local/tomcat/log/catalina.out
删除文件及递归删除子目录
rm /filepath
rm -rf /path
查找文件
find /path -name *.swf
I/O重定向
如将查找到的结果输出到abc.txt
find /home/oracle -name *.jsp > abc.txt
压缩解压
(1).tar.gz
解压:tar zxvf abc.tar.gz
压缩:tar czvf abc.tar.gz path
(2).tar
压缩: tar xvf abc.tar path
解压: tar zxvf abc.tar
(3).bz
解压:bzip –d abc.bz
(4).bz2
解压:bzip2 –d abc.bz2
(5).gz
解压:gzip –d abc.gz
(6).tar.bz2
解压:tar jxvf abc.tar.bz2
压缩:tar jcvf abc.tar.bz2 path
2.一块网卡绑定多个IP
#绑定多个ip
/sbin/ifconfig eth0:1 192.168.1.40 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.40 dev eth0:1
/sbin/arping -I eth0 -c 3 -s 192.168.1.40 192.168.1.1
# setting DNS
gedit /etc/resolv.conf
# setting Gateway
route add default gw 192.168.1.1
3.安装JDK
安装jdk
chmod 755 jdk-xxx.bin
./jdk-xxx.bin
mv jdk-xxx /usr/local/jdk
设置环境变量
编辑 /etc/profile or ~/.bash_profile or ~/.bashrc
----------/etc/profile---------------------------
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
------------end----------------------------------
使环境变量立即生效
source /etc/profile
检查是否安装成功,如下命令查看JDK版本
java -version
解决Java GUI程序乱码问题
cd $JAVA_HOME/jre/lib/fonts
mkdir fallback
cd fallback
#把某个中文字体链接进 fallback 目录,这里文泉驿字体
cp /path_of_wqyttf wqy-zenhei.ttf
mkfontdir
mkfontscale
4.安装Tomcat
tar zxvf apache-tomcat-xxx.tar.gz
mv apache-tomcat-xxx /usr/local/tomcat
cp -rf /usr/local/tomcat/webapps/* /data/www
使tomcat当前窗口运行
/usr/local/tomcat/bin/catalina.sh
tomcat后台运行
/usr/local/tomcat/bin/startup.sh
查看后台运行的tomcat输出日志
tail -f /usr/local/tomcat/logs/catalina.out
开机运行tomcat
-----------/etc/rc.d/rc.local----------------------
/usr/local/tomcat/bin/startup.sh
----------end--------------------------------------
5.安装Nginx
安装依赖包
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
编译安装
tar zxvf nginx-xxxx.tar.gz
cd nginx-xxxx
./configure --prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf
make && make install
启动Nginx
/usr/local/nginx/sbin/nginx
关闭Nginx
pkill -9 nginx
命令太长,创建简单点的别名
----------~/.bash_profile---------------------
alias startnginx="/usr/local/nginx/sbin/nginx"
alias killnginx="pkill -9 nginx"
---------end----------------------------------
生效
source ~/.bash_profile
6.安装Apache FtpServer
Apache FtpServer纯Java开发,安装配置非常简单
tar zxvf ftpserver-1.0.5.tar.gz
mv ftpserver-xxx /usr/local/ftpserver
配置文件为res/conf/ftpd-typical.xml, 密码存储在res/conf/user.properties
如下示例使用明文存储密码,也可以使用MD5加密
---------------ftpd-typical.xml-------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd"
id="myServer"
anon-enabled="false"
max-logins="5"
max-anon-logins="0"
max-login-failures="3"
login-failure-delay="30000">
<listeners>
<nio-listener name="default" port="21">
<ssl>
<keystore file="./res/ftpserver.jks" password="password" />
</ssl>
</nio-listener>
</listeners>
<file-user-manager file="./res/conf/users.properties"
encrypt-passwords="clear"/>
</server>
-------------------end---------------------------------
注意encrypt-passwords属性,clear表示明文,md5表示使用MD5加密
-------------------user.properties----------------------
# Password is "ftp",明文填写
ftpserver.user.ftp.userpassword=ftp
ftpserver.user.ftp.homedirectory=/data/ftp
ftpserver.user.ftp.enableflag=true
ftpserver.user.ftp.writepermission=true
ftpserver.user.ftp.maxloginnumber=0
ftpserver.user.ftp.maxloginperip=0
ftpserver.user.ftp.idletime=0
ftpserver.user.ftp.uploadrate=0
ftpserver.user.ftp.downloadrate=0
---------------end-----------------------------------
后台启动
nohup /usr/local/ftpserver/bin/ftpd.sh res/conf/ftpd-typical.xml 2>&1 > /dev/null &
开机启动,在/etc/rc.d/rc.local中添加命令
-------------/etc/rc.d/rc.local------------------------------
nohup /usr/local/ftpserver/bin/ftpd.sh res/conf/ftpd-typical.xml 2>&1 > /dev/null &
--------------end--------------------------------------------
7.安装memcached
wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure && make && make install
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure && make && make install
启动Memcached
/usr/local/bin/memcached -d -m 512 -u root -l 192.168.1.68 -p 11211 -c 256 -P /tmp/memcached.pid
参数说明: -d 启动为守护进程
-m <num> 分配给Memcached使用的内存数量,单位是MB,默认为64MB
-u <username> 运行Memcached的用户,仅当作为root运行时
-l <ip_addr> 监听的服务器IP地址,默认为环境变量INDRR_ANY的值
-p <num> 设置Memcached监听的端口,最好是1024以上的端口
-c <num> 设置最大并发连接数,默认为1024
-P <file> 设置保存Memcached的pid文件,与-d选择同时使用
关闭Memcached
kill `/tmp/memcached.pid`
或者
pkill -9 memcached
9.安装ffmpeg
#下载需要的解码器
wget http://liba52.sourceforge.net/files/a52dec-0.7.4.tar.gz
wget http://downloads.sourceforge.net/faac/faad2-2.6.1.tar.gz
wget http://downloads.sourceforge.net/faac/faac-1.26.tar.gz
wget http://nchc.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://www.tortall.net/projects/yasm/releases/yasm-0.7.0.tar.gz
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20101207-2245.tar.bz2
wget http://downloads.xvid.org/downloads/xvidcore-1.1.3.tar.gz
wget http://down1.chinaunix.net/distfiles/libdts-0.0.2.tar.gz
#解压
for i in *.tar.gz; do tar -xzvf "$i"; done
for i in *.tar.bz2; do tar -xjvf "$i"; done
#安装的参数
a52dec: ./configure --enable-shared=PKGS && make && make install
faac & faad2: ./bootstrap && ./configure && make && make install
xvidcore: cd build/generic; ./configure && make && make install
libx264: ./configure && make && make install
lame & yasm: ./configure && make && make install
#编译安装
./configure --enable-gpl --enable-postproc --enable-nonfree --enable-postproc --enable-libfaad --enable-swscale --enable-avfilter --enable-pthreads --enable-libxvid --enable-libx264 --enable-libmp3lame --enable-libfaac --disable-ffserver --disable-ffplay
#设置环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib
#检查是否安装成功,如下命令查看支持的文件格式
ffmpeg -formats
#如果出现没有权限的错误,执行如下命令
chcon -t texrel_shlib_t xxxx.so.xx
#转换成480x320尺寸大小的h.264格式视频
ffmpeg -i source.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -s 480x320 -vpre slow -crf 22 -threads 0 newfile.mp4
10.Nginx双机故障转移shell脚本
------------nginx_ha1.sh-------------------------------
#!/bin/sh
LANG=C
date=$(date -d "today" +"%Y-%m-%d %H:%M:%S")
#虚拟IP1
vip1=192.168.1.40
#虚拟IP2
vip2=192.168.1.41
#广播IP
broadcast_ip=192.168.1.255
#真实IP1
real_ip1=192.168.1.35
#真实IP2
real_ip2=192.168.1.36
#网关IP
gw_ip=192.168.1.1
#绑定虚拟IP1
function_bind_vip1()
{
/sbin/ifconfig eth0:ha1 ${vip1} broadcast ${broadcast_ip} netmask 255.255.255.0 up
/sbin/route add -host ${vip1} dev eth0:ha1
}
#绑定虚拟IP2
function_bind_vip2()
{
/sbin/ifconfig eth0:ha2 ${vip2} broadcast ${broadcast_ip} netmask 255.255.255.0 up
/sbin/route add -host ${vip2} dev eth0:ha2
}
#重启Nginx
function_restart_nginx(){
pkill -9 nginx
/usr/local/nginx/sbin/nginx
}
#移除虚拟IP1
function_remove_vip1()
{
/sbin/ifconfig eth0:ha1 ${vip1} broadcast ${broadcast_ip} netmask 255.255.255.0 down
}
#移除虚拟IP2
function_remove_vip2()
{
/sbin/ifconfig eth0:ha2 ${vip2} broadcast ${broadcast_ip} netmask 255.255.255.0 down
}
#虚拟IP1 ARPing
function_vip_arping1()
{
/sbin/arping -I eth0 -c 3 -s ${vip1} ${gw_ip} > /dev/null 2>&1
}
#虚拟IP1 ARPing
function_vip_arping2()
{
/sbin/arping -I eth0 -c 3 -s ${vip2} ${gw_ip} > /dev/null 2>&1
}
bind_time_vip1="N";
bind_time_vip2="N";
while true
do
httpcode_rip1='/usr/bin/curl -o /dev/null -s -w %{http_code} http://${real_ip1}'
httpcode_rip2='/usr/bin/curl -o /dev/null -s -w %{http_code} http://${real_ip2}'
if [x$httpcocde_rip1 == "x200" ];
then
if [ $bind_time_vip1 == "N" ] ;
then
function_bind_vip1
function_vip_arping1
function_restart_nginx
bind_time_vip1="Y"
fi
function_vip_arping1
else
if [ $bind_time_vip1 == "Y" ] ;
then
function_remove_vip1
bind_time_vip1="N"
fi
fi
if [x$httpcocde_rip2 == "x200" ];
then
if [ $bind_time_vip2 == "Y" ] ;
then
function_remove_vip2
bind_time_vip1="N"
fi
else
if [ $bind_time_vip2 == "N" ] ;
then
function_bind_vip2
function_vip_arping2
function_restart_nginx
bind_time_vip2="Y"
fi
function_vip_arping2
fi
sleep 5
done
--------------end----------------------------------------------------
nginx_ha2.sh的内容,只需要交换vip1和vip2的地址
分别在2台Nginx服务器上运行脚本,如下为使脚本后台运行的命令
nohup /path/nginx_ha1.sh 2>&1 > /dev/null &