CentOS下Tomcat7+Solr3的安装配置

Standard

下载

wget http://mirror.bjtu.edu.cn/apache/lucene/solr/3.1.0/apache-solr-3.1.0.tgz
wget http://labs.renren.com/apache-mirror/tomcat/tomcat-7/v7.0.12/bin/apache-tomcat-7.0.12.tar.gz
tar zxvf apache-solr-3.1.0.tgz
tar zxvf apache-tomcat-7.0.12.tar.gz
mv apache-solr-3.1.0 /usr/local/solr
mv apache-tomcat-7.0.12 /usr/local/tomcat

配置

vi /etc/profile
#加在最底下
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk
export CLASSPATH=.:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export TOMCAT_HOME=/usr/local/tomcat
export JAVA_OPT="$JAVA_OPTS -Dsolr.solr.home=/usr/local/solr/example/solr"
cp /usr/local/solr/dist/apache-solr-3.1.0.war /usr/local/tomcat/webapps/solr.war
 
vi /usr/local/tomcat/conf/Catalina/localhost/solr.xml
<Context docBase="/usr/local/tomcat/webapps/solr.war" debug="0" crossContext="true">
    <Environment name="solr/home" type="java.lang.String" value="/usr/local/solr/example/solr" override="true" />
</Context>
vi /usr/local/solr/example/solr/conf/solrconfig.xml
#初始
<dataDir>${solr.data.dir:}</dataDir>
#修改为
<dataDir>${solr.data.dir:/usr/local/solr/example/solr/data}</dataDir>
vi /usr/local/tomcat/conf/tomcat-users.xml
#去掉注释块,加入以下内容
  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <user username="tomcat" password="s3cret" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>

启动
/usr/local/tomcat/bin/startup.sh

浏览
http://localhost:8080/manager/status

http://localhost:8080/solr/

转载请注明出处:http://yemaosheng.com

换一个国内的yum源

Standard

默认的那个太慢了,几K几K走的,汗…

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-One-Base.repo

wget http://centos.ustc.edu.cn/CentOS-Base.repo
wget http://mirrors.shlug.org/CentOS-SHLUG.repo

yum install yum-fastestmirror
装了这个以后它会自动选择快的那个源

CentOS iSCSI登陆FreeNAS iSCSI Server

Standard

FreeNAS:
192.168.0.2
FreeNAS具体配置iSCSI的步骤
Disks->Management 添加新的磁盘
Disks->Format 格式化磁盘
Disks->Mount Point 建立磁盘分区
Services->iSCSI Target->Extent 增加扩展区
Services->iSCSI Target-> Target中增加登录点

CentOS:
yum install iscsi-initiator-utils
service iscsid start

搜索target

iscsiadm --mode discovery --type sendtargets --portal 192.168.0.2

显示target name

iscsiadm --mode node

192.168.0.2:3260,1 iqn.1994-04.org.netbsd.iscsi-target:target0
登录target

iscsiadm --mode node --targetname iqn.1994-04.org.netbsd.iscsi-target:target0 --portal 192.168.0.2:3260 --login

#记得将登录target放到启动自运行里面

fdisk -l
fdisk /dev/sdb #依次选p n 1 w
mkfs -t ext3 /dev/sdb1

挂载
mkdir /iscsi
mount /dev/sdb1 /iscsi

设自动挂载
vi /etc/fstab
/dev/sdb1 /iscsi ext3 _netdev 0 0

转载请注明出处:http://yemaosheng.com

CentOS HeartBeat 配置

Standard

Gateway:192.168.0.1
A:
eth0:192.168.0.216
eth0:0: 192.168.0.210
eth1:10.0.0.216
hostname:svr1
B:
eth0:192.168.0.217
eth0:0: 192.168.0.210
eth1:10.0.0.217
hostname:svr2

A:
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.0.216 srv1 HA01
10.0.0.216 HA01
10.0.0.217 HA02
192.168.0.217 svr2

B:
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.0.217 srv2 HA02
10.0.0.217 HA02
10.0.0.216 HA01
192.168.0.216 svr1

—————————————
A & B:
vi /etc/rc.local
ipvsadm -A -t 192.168.0.210:80 -s rr
ipvsadm -a -t 192.168.0.210:80 -r 192.168.0.216:80 -m
ipvsadm -a -t 192.168.0.210:80 -r 192.168.0.217:80 -m

yum -y install heartbeat
cd /usr/share/doc/heartbeat-2.1.3/
cp authkeys ha.cf haresources /etc/ha.d/

—————————————
A:
cd /etc/ha.d/
vi authkeys

auth 1
1 crc

chmod 600 authkeys

vi ha.cf
logfile /var/log/ha_log/ha-log.log
bcast eth1
keepalive 2 # 2 seconds or keepalive 100ms
warntime 10
deadtime 30
initdead 120
hopfudge 1
udpport 694
auto_failback on
node svr1
node svr2
ping 192.168.0.1
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root

vi haresources
svr1 IPaddr::192.168.0.210 ipvsadm httpd

B:
cd /etc/ha.d/
vi authkeys

auth 1
1 crc

chmod 600 authkeys

vi ha.cf
logfile /var/log/ha_log/ha-log.log
bcast eth1
keepalive 2
warntime 10
deadtime 30
initdead 120
hopfudge 1
udpport 694
auto_failback on
node svr1
node svr2
ping 192.168.0.1
respawn root /usr/lib/heartbeat/ipfail
apiauth ipfail gid=root uid=root

vi haresources
svr2 IPaddr::192.168.0.210 ipvsadm httpd
—————————————
A & B:
Service heartbeat start
Service httpd start

http对外访问IP:192.168.0.210

转载请注明出处:http://yemaosheng.com

CentOS rsync同步

Standard

A:192.168.0.1
B:192.168.0.2

A:
yum -y install xinetd
vi /etc/xinetd.d/rsync

将“disable = no
chkconfig xinetd on
service xinetd start
vi /etc/rsyncd.conf

[site] #name
path = /var/www/html #copied directory
hosts allow = 192.168.0.2
hosts deny = *
list = true
uid = root
gid = root

B:
vi /etc/rsync_exclude.lst #Write directory or files you don’t want to copy.
no.txt
nono.txt

rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.1::site /home/backup

crontab -e

00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.1::site /home/backup

CentOS DNS简单配置

Standard

yum install bind bind-utils bind-libs

vi /etc/named.conf

options {
  directory "/etc";
  pid-file "/var/run/named/named.pid";
};
zone "."{
  type hint;
  file "/var/named/named.ca";
};
zone "localhost"{
  type master;
  file "/var/named/localhost.zone";
};
zone "0.0.127.in-addr.arpa"{
  type master;
  file "/var/named/localhost.rev";
};
zone "yemaosheng.com" {
  type master;
  file "/var/named/yemaosheng.com.zone";
};
zone "1.168.192.in-addr.arpa" {
  type master;
  file "/var/named/yemaosheng.com.rev";
};

vi /var/named/localhost.zone

$TTL    86400
@   IN   SOA   localhost. root.localhost. (
  42 ; serial (d. adams)
  3H ; refresh
  15M ; retry
  1W ; expiry
  1D ; ) minimum
IN NS           localhost.
IN A            127.0.0.1

vi /var/named/localhost.rev

$TTL   86400
@   IN   SOA   localhost. root.localhost. (
  1
  28800
  14400
  3600000
  86400
)
IN   NS   localhost.
1   IN   PTR   localhost.

vi /var/named/yemaosheng.com.zone

$TTL   86400
@   IN   SOA   ns.yemaosheng.com. root.localhost. (
  1
  28800
  14400
 3600000
  86400
)
IN   NS   ns.yemaosheng.com.
ns.test.com   IN   MX   10   ns.yemaosheng.com.  ;指定邮件交换记录
ns                IN   A           192.168.1.123

vi /var/named/yemaosheng.com.rev

$TTL   86400
@   IN   SOA   ns.yemaosheng.com. root.localhost. (
  1
  28800
  14400
  3600000
  86400
)
IN     NS          ns.yemaosheng.com.
123   IN   PTR   ns.yemaosheng.com. ;反向解析IP地址

Install ZendOptimizer and eaccelerator in Linux

Standard

正在帮同学的服务器装ZendOptimizer和eaccelerator,边装边写.

先装ZendOptimizer,这个没什么好写的,运行 ./install.sh 后有提示,照着做就行了.

eaccelerator有些地方需要注意的,就是先要确定是否有php-devel和gcc,前者包含phpize(用来编译扩展库的),后者不用我多说了吧.

yum install php-devel
yum install gcc
tar xvf eaccelerator-0.9.5.3.tar.tar
cd eaccelerator-0.9.5.3
export PHP_PREFIX="/usr"
$PHP_PREFIX/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
make
make install
 
vi /etc/php.ini
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/httpd/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
 
mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

eAccelerator 应用程序接口(API)

eaccelerator_put($key, $value, $ttl=0)
将 $value 存储在共享内存中,并存储 $tll 秒。

eaccelerator_get($key)
从共享内存中返回 eaccelerator_put() 函数所存储的缓存数值,如果不存在或者已经
过期,则返回 null。

eaccelerator_rm($key)
从共享内存中删除 $key。

eaccelerator_gc()
删除所有过期的键(keys)

eaccelerator_lock($lock)
创建一个指定名称的锁(lock)。该锁可以通过 eaccelerator_unlock() 函数解除,在请求
结束时也会自动解锁。例如:
<?php
eaccelerator_lock(“count”);
eaccelerator_put(“count”,eaccelerator_get(“count”)+1));
?>

eaccelerator_unlock($lock)
解除指定名称的锁(lock)。

eaccelerator_set_session_handlers()
安装 eAccelerator session 句柄。
从 PHP 4.2.0 以后,您可以通过设置 php.ini 中的 “session.save_handler=eaacelerator”
安装 eAccelerator 句柄。

eaccelerator_cache_output($key, $eval_code, $ttl=0)
在共享内存中缓存 $eval_code 的输出,缓存 $ttl 秒。
可以调用 mmcach_rm() 函数删除相同 $key 的输出。例如:
<?php eaccelerator_cache_output(‘test’, ‘echo time(); phpinfo();’, 30); ?>

eaccelerator_cache_result($key, $eval_code, $ttl=0)
在共享内存中缓存 $eval_code 的结果,缓存 $ttl 秒。
可以调用 mmcach_rm() 函数删除相同 $key 的结果。例如:
<?php eaccelerator_cache_output(‘test’, ‘time().” Hello”;’, 30); ?>

eaccelerator_cache_page($key, $ttl=0)
缓存整个页面,且缓存 $ttl 秒。例如:
<?php
eaccelerator_cache_page($_SERVER[‘PHP_SELF’].’?GET=’.serialize($_GET),30);
echo time();
phpinfo();
?>

eaccelerator_rm_page($key)
从缓存中删除由 eaccelerator_cache_page() 函数创建的相同 $key 的页。

eaccelerator_encode($filename)
返回 $filename 文件经过编译后的编码。

eaccelerator_load($code)
加载被 eaccelerator_encode() 函数编码过的脚本。

范例

1
2
3
4
5
6
7
8
9
10
11
12
13
//加裁内存  1.php
$sql="select id,songname,singer from DB_SONG where urlstatus=1";
$query=$dbmysql->Query($sql);
while($row=$dbmysql->FetchObject($query))
{
$songid=$row->id;
$keyname=$row->songname;
eaccelerator_put ($keyname, $songid);
}
 
//读内存 2.php
$key=$_GET['name'];
$song_id=eaccelerator_get($key);

Yum升级最新版软件

Standard

同学搬了台机器去机房,让我帮忙管一下. ssh上去花了十多分钟把web、ftp、mysql都弄好了,结果他就是不想要默认的版本,非要都装最新版. 和他解释并非新版就好也听不进呀. 算啦,只好都升极喽:)

先是要把PHP从5.1升到5.2. 结果 yum update php 后发现系统默认的rpm仓库里没有最新版的. 网上查了查再加了个仓库进去,这里面东西到非常新.

rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
 
vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

之后再用 yum update phpyum update mysql 就都能找着最新版本了.

SVN on CentOS

Standard

1) Installation:
The first thing to do is to install the packages I mentioned above. If you don’t have Apache installed already, it’ll go ahead and drag that down as well.
[root@lucifer ~]# yum install mod_dav_svn subversion

2) Configurations:

a) Apache:

b) Subversion’s Apache configs:
The next step is to setup some settings within Apache so Subversion and Apache play nice together. Get yourself to the example configuration file Subversion installed for you.
[root@lucifer ~] cd /etc/httpd/conf.d/
[root@lucifer ~] vim subversion.conf

# Make sure you uncomment the following if they are commented out
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

# Add the following to allow a basic authentication and point Apache to where the actual
# repository resides.
<Location /repos>
DAV svn
SVNPath /var/www/svn/repos
AuthType Basic
AuthName “Subversion repos”
AuthUserFile /etc/svn-auth-conf
Require valid-user
</Location>

The location is what Apache will pass in the URL bar. For instance: http://yourmachine/repos points to the SVNPath that you have specified. My examples are just that, so feel free to put things where you want. Make sure you save the file when you are finished editing.
Next we have to actually create the password file that you specified in the previous step. Initially you’ll use the -cm arguments. This creates the file and also encrypts the password with MD5. If you need to add users make sure you simply use the -m flag, and not the -c after the initial creation.
[root@lucifer ~] htpasswd -cm /etc/svn-auth-conf yourusername
New password:
Re-type new password:
Adding password for user yourusername
[root@lucifer ~] htpasswd -m /etc/svn-auth-conf anotherusername
New password:
Re-type new password:
Adding password for user anotherusername

c) Configure your repository
The next thing you need to do is to create the actual repository from which you will check in and out your files. This is simple to do with some of the included svn tools.
[root@lucifer ~] cd /var/www/ — Or wherever you placed your path above
[root@lucifer ~] mkdir svn
[root@lucifer ~] cd svn
[root@lucifer ~] svnadmin create repos
[root@lucifer ~] chown -R apache.apache repos
[root@lucifer ~] service httpd restart

Go test out whether or not you can access your repository from a web browser: http://yourmachine/repos. You should get a popup box asking for a username and password. If so, type in your credentials and you should be displayed with a Revision 0:/ page. If so, that’s it for setting up a repo. If you want multiple repos, check out the docs from the links provides above. This sets up one repository and shows you how to start using them. Speaking of, let’s move on to just that.

3) Using Subversion:

a) Layout Your Repo:
If all went well above, you’re now ready to start using the repository that you created. Subversions svn tool is the command line client that you will use to talk to the database. To see the use of the tool:
[root@lucifer ~] svn –help
The most common arguments you will most likely be using are: svn import, svn commit (ci), and svn checkout (co). With these you will initially import files into your repository with import, you’ll check them out to work on them with checkout, and you’ll commit the changes back into the database with commit. It’s pretty simple once you see them in use a few times.
Before I continue I’d like to explain about directory structure layouts. Almost all of the documentation talks about creating a certain layout for your directories. They specifically mention about making sure you have a branches, tags, and trunk underneath the root directory structure, where trunk holds all your files. For instance:
.
|– project1
| |– branches
| |– tags
| `– trunk
`– project2
|– branches
|– tags
`– trunk
The book explains why in a bit more detail, and I mainly don’t bother using this type of layout…because I’m not doing coding and maintaining “projects” per se. I’m mainly using it to store configuration files, and text items that aren’t as complex. Set things up for whatever works for you.
As an example, I’m going to just create some dummy directories and throw some files in them. This is from the actual SVN server. Play along.
[root@lucifer ~] cd /tmp
[root@lucifer ~] mkdir mytestproj
[root@lucifer ~] cd mytestproj
[root@lucifer ~] mkdir configurations options main
[root@lucifer ~] vim configurations/testconf1.cfg — Add whatever you want to these files.
[root@lucifer ~] vim options/testopts1.cfg
[root@lucifer ~] vim main/mainfile1.cfg

Keep in mind that you can layout anything anyway you’d like. Once you have the initial layout of what you want, let’s go ahead and import this up to Subversion.

b) Importing:
[root@lucifer ~] svn import /tmp/mytestproj/ file:///var/www/svn/repos/mytestproj -m “Initial repository layout for mytestproj”
Adding /tmp/mytestproj/main
Adding /tmp/mytestproj/main/mainfile1.cfg
Adding /tmp/mytestproj/configurations
Adding /tmp/mytestproj/configurations/testconf1.cfg
Adding /tmp/mytestproj/options
Adding /tmp/mytestproj/options/testopts1.cfg

c) Checking Out:
Now, just to check it out across the web browser: http://yourmachine/repos. You’ll get whatever you have imported showing up to peruse. Once you upload your original layout from the local SVN server, you’re now free to use it remotely on another machine. As long as you are connecting to the Subversion server with the user account(s) that you created earlier. Let’s give it a shot.
[me@mylappy ~] mkdir mytestproj
[me@mylappy ~] svn co
http://yoursvnserver/repos/mytestproj
Authentication realm: <http://yoursvnserver:80> Subversion repos
Password for ‘youruser’:
A mytestproj/main
A mytestproj/main/mainfile1.cfg
A mytestproj/configurations
A mytestproj/configurations/testconf1.cfg
A mytestproj/options
A mytestproj/options/testopts1.cfg
Checked out revision 1.

d) Edit & Commit
As you can see, you’ve checked out revision 1 from the Subversion server. Now you can edit some things and commit the changes back to the Subversion server.
[me@mylappy ~] cd mytestproj
[me@mylappy ~] vim configurations/testconf1.cfg — Add or delete something and save.
[me@mylappy ~] svn commit -m “Added a line to testconf1.cfg.”
Sending configurations/testconf1.cfg
Transmitting file data .
Committed revision 2.

The nice thing about this then, is that you can delete all of the directories that you just checked out on your machine. The only reason you checked them out, was to edit them, and then send them back up the line. Web browse to your server to check out the different files.

e) Adding/Deleting Items
Now this is all fine and dandy, but how do you add more files to an already existing repo directory? Easy, with the add argument. Go ahead and checkout your latest and greatest, copy a file over to a directory, add, then commit the changes.
[me@mylappy ~] svn co http://yoursvnserver/repos/mytestproj
A mytestproj/main
A mytestproj/main/mainfile1.cfg
A mytestproj/configurations
A mytestproj/configurations/testconf1.cfg
A mytestproj/options
A mytestproj/options/testopts1.cfg
Checked out revision 2.

[me@mylappy ~] cd mytestproj
[me@mylappy ~] cp /etc/yum.repos.d/CentOS-Base.repo configurations/
[me@mylappy ~] svn add configurations/CentOS-Base.repo
A configurations/CentOS-Base.repo

[me@mylappy ~] svn commit -m “Added the CentOS Yum repo file.”
Adding configurations/CentOS-Base.repo
Transmitting file data .
Committed revision 3.

To delete items simply use delete instead of add. Commit your changes back up, and you’re good to go. It’s as simple as that. Go back over to your web browser again and you’ll notice the revision number should say 3. You’ll be able to click through the files to pick our your differences as well.

f) Reverting Back:
Ok, this is all great but how do I revert back to an older revision…isn’t this the point of Subversion? Yep, it’s easy. If you’re not sure as to what revision you’re at…check out the log command. This is why you put a message in every commit. Short and to the point, but enough information to ring a bell that you perhaps forgot about.
[me@mylappy ~] svn log http://yoursvnserver/repos — For the entire repository
[me@mylappy ~] svn log
http://yoursvnserver/repos/mytestproj — For the specific project
You’ll get a nice complete list of revision numbers along with the comments, like I mentioned above. This allows you to pick which revision you want to check back out now.
[me@mylappy ~] svn co -r 1 http://yoursvnserver/repos/mytestproj
This command will drag down revision number 1.

4) Access control lists
Usually, you don’t want to give every user access to every repository. You can restrict repository access per user by using ACLs. ACLs can be enabled with the AuthzSVNAccessFile file option, which takes a file name as its parameter. For instance:
AuthzSVNAccessFile /etc/svn-acl-conf
You can add this to the relevant Location section:
<Location /repos>
DAV svn
SVNParentPath /var/www/svn/repos
AuthzSVNAccessFile /etc/svn-acl-conf
AuthType Basic
AuthName “Subversion repos”
AuthUserFile /etc/svn-auth-conf
Require valid-user
</Location>

You can then create /etc/svn-acl-conf. This file consist of sections of the following form:
[reponame:repopath]
user = access

Where access can be r (read), rw (read-write), or empty (no access at all). The default ACL is to give users no access to a repository. Suppose that there is a repository named framework to which you would like to give john read access, and joe read and write access. You could then add the following section:
[framework:/]
john = r
joe = rw

It is also possible to create groups in a section named groups, groups are then prefixed with the ‘at’ sign (@) in the access control lists. For instance:
[groups]
staff = joe, george

[framework:/]
john = r
@staff = rw

If you would like to make all repositories readable to all users, you can add a section for the root directory of every repository:
[/]
* = r