Skip to content
VectorHo edited this page Oct 23, 2014 · 2 revisions

centos 搭建基础服务环境

目标:安装jdk, tomcat, mongodb, redis, nginx, nodejs, zookeeper, maven, git
QQ 41903645(注意:重新读入docker镜像时,每次都需要source /etc/profile)
ps:用户目录(cd ~) 建立.bashrc或.bash_profile 把需要配置到环境变量的配置都配好:eg JAVA_HOME、MVN_HOME etc.

说明

  • 环境是centos root用户,

    /chameleon/downloads 文件夹为下载存放目录(可自行设置)

    所有的解压文件都都放到/chameleon目录下,如/chameleon/jdk7

  • 命令行中复制、粘贴快捷键 ctrl+shift+c 、ctrl+shift+v

  • 很多下载url没有具体给出,需自己获取,如jdk的url

  • xxx表示的通配符,用在文件名中 或 url路径中

安装 tar wget vim net-tools

yum install -y tar wget vim net-tools

1. 安装jdk

cd /chameleon/downloads

wget http://download.oracle.com/xxx.tar.gz

tar -zxvf jdkxx.tar.gz

mv jdkxxx /chameleon/jdk7

配置环境变量,在/etc/profile末尾添加

export JAVA_HOME=/chameleon/jdk7

export PATH=$PATH:$JAVA_HOME/bin

2. 安装 apache-tomcat

wget http://path.to.download.tomcat/xxx.tar.gz

tar -zxvf tomcat.tar.gz

mv apache-tomcat /chameleon/tomcat7

启动

/chameleon/tomcat7/bin/startup.sh

测试

wget http://localhost:8080/

会得到 index.html

3. 安装nodejs

curl -sL https://rpm.nodesource.com/setup | bash -

yum install -y nodejs

测试

node -v

安装 pm2

npm install -g pm2

4. 安装 nginx

cd /chameleon/downloads

wget http://nginx.org/download/nginx-1.6.0.tar.gz

tar -zxf xxx.tar.gz

mv nginx-xxx /chameleon/nginx

安装编译工具

yum groupinstall -y "Development Tools"

安装完毕测试,运行以下三个命令

gcc -v

g++ -v

make -v

编译nginx源码

./configure --prefix=/chameleon/nginx --with-http_ssl_module --with-http_stub_status_module

如果报错 PCRE library未安装(xxxx not found),则

yum -y install pcre-devel openssl openssl-devel

./configure --prefix=/chameleon/nginx --with-http_ssl_module --with-http_stub_status_module

./configure执行后

make && make install

启动nginx

/chameleon/nginx/sbin/nginx

测试nginx

cd /chameleon/downloads

wget http://localhost:80/

得到index.html,查看是否是nginx的主页, vim index.html 即可

5.安装mongodb

cd /chameleon/downloads

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.5.tgz

tar -zxvf mongodbxxx.tgz

mv mongodbxx /chameleon/mongodb

配置mongodb

cd /chameleon/mongodb

touch mongod.conf

将以下文件放进mongod.conf

bind_ip=127.0.0.1

port=27017

fork=true

dbpath=/chameleon/mongodb/data/

logpath=/chameleon/mongodb/logs/mongodb.log

因为设定了dbpath和logpath,所以要建立这2个文件夹

mkdir /chameleon/mongodb/data

mkdir /chameleon/mongodb/logs

6. 安装redis

cd /chameleon/downloads

wget http://download.redis.io/releases/redis-2.8.17.tar.gz

tar -zxvf xx.tar.gz

mv redis-xxx /chameleon/redis

cd redis-xxx

make && make install

编辑 redis-xxx/redis.conf 文件

daemonize yes

port 6379

timeout 600

logfile /chameleon/redis/logs/redis.log

databases 16

save 900 1

save 300 10

save 60 10000

dir /chameleon/redis/data

appendonly no

maxclients 10000

maxmemory (1/2)

appendfsync everysec

建立文件夹

mkdir /chameleon/redis/data

mkdir /chameleon/redis/logs/redis.log

启动 redis

/chameleon/redis/src/redis-server /chameleon/redis/redis.conf

测试 查看redis是否已经启动,并占用了相应的端口

netstat -apn

7. 安装zookeeper

cd /chameleon/downloads

wget http://mirror.xxx/xxx/zookeeper-xxx.tar.gz

tar -zxf zookeeperxxx.tar.gz

mv zookeeperxxx /chameleon/zookeeper

修改配置

cd /chameleon/zookeeper/conf/

cp zoo_sample.cfg zoo.cfg

修改zoo.cfg的如下一行 dataDir=xxx

dataDir=/chameleon/zookeeper/data

建立文件夹,对应dataDir指定的文件夹

mkdir /chameleon/zookeeper/data

启动zookeeper

/chameleon/zookeeper/bin/zkServer.sh start

查看zookeeper状态

/chameleon/zookeeper/bin/zkServer.sh status

如果报错 , ​​有可能是java未设置,请 echo $JAVA_HOME 确认以下

多个docker中zookeeper集群,请另行参考

8.安装 open-ldap

术语: ldap = light-weight directory access protocol

cn - common name

dn - distinct name

rdn - relative distinct name

dc - domain component

8.1. 安装 berkeley db

参考

wget http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz

tar -zxvf db-xxx

cd db-xxx/build_unix

../dist/configure --prefix=/chameleon/bdb

会在 build_unix下生成一些文件

make && make install

echo '/chameleon/bdb/lib/' >> /etc/ld.so.conf

ldconfig

这2句的作用就是通知系统Berkeley DB的动态链接库在/usr/local/berkeleydb/lib/目录。

8.2 install open ldap( openldap-2.4.39.tgz)

http://better.blog.51cto.com/1886029/1285710

wget http://120.198.244.44:9999/www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.4.39.tgz

tar -zxbvf xx.tgz

cd openldap-2.4.39

./configure --prefix=/chameleon/openldap --with-tls=openssl --enable-bdb </br> CPPFLAGS="-I/chameleon/bdb/include" </br> LDFLAGS="-L/chameleon/bdb/lib" LD_LIBRARY_data-path="/chameleon/bdb/lib"

make depend

make

make test

make install

出现问题:fatal error: ltdl.h: No such file or directory

[参考](https://ask.fedoraproject.org/en/question/53550/how-can-i-find-a-needed-header-file/ ltdl.h is in the Debian package libltdl3-dev)

yum whatprovides '*/ltdl.h'

然后选择一个

yum install libtool-ltdl-devel-2.4.2-20.el7

再 make depend 以及 make && make install

vim /chameleon/openlap/etc/openldap/slapd.conf

#####添加schema

include /chameleon/openldap/etc/openldap/schema/collective.schema

include /chameleon/openldap/etc/openldap/schema/corba.schema

include /chameleon/openldap/etc/openldap/schema/cosine.schema

include /chameleon/openldap/etc/openldap/schema/duaconf.schema

include /chameleon/openldap/etc/openldap/schema/dyngroup.schema

include /chameleon/openldap/etc/openldap/schema/inetorgperson.schema

include /chameleon/openldap/etc/openldap/schema/java.schema

include /chameleon/openldap/etc/openldap/schema/misc.schema

include /chameleon/openldap/etc/openldap/schema/nis.schema

include /chameleon/openldap/etc/openldap/schema/openldap.schema

include /chameleon/openldap/etc/openldap/schema/pmi.schema

include /chameleon/openldap/etc/openldap/schema/ppolicy.schema

修改rootDn

suffix "dc=foss,dc=com"

rootdn "cn=Manager,dc=foss,dc=com"

#####启动服务先

./libexec/slapd

导入数据文件 /chameleon/openldap/data/foss.ldif

./bin/ldapadd -x -D "cn=Manager, dc=foss, dc=com" -W -f /chameleon/openldap/data/foss.ldif

问题:ldap_add: Invalid syntax (21)

可能问题是 foss.ldif中的中文字符造成的

file -i data/foss.ldif

===> 输出 data/foss.ldif: text/plain; charset=iso-8859-1

iconv -f ISO-8859-1 -t UTF-8 foss.ldif > foss1.ldif

删除foss.ldif, 重命名foss1.ldif,再导入一次

rm -f foss.lidf

mv foss1.lidf foss.lidf

./bin/ldapadd -x -D "cn=Manager, dc=foss, dc=com" -W -f /chameleon/openldap/data/foss.ldif

9.安装 maven

#####按照官网的来

cd /chameleon/downloads

wget http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.tar.gz

tar -zxf apache-xxx.tar.gz

mv apache-maven-xx /chameleon/maven

vi /etc/profile

增加 env var M2_HOME M2 PATH

export M2_HOME=/chameleon/maven

export M2=$M2_HOME/bin

export PATH=$PATH:$M2

Clone this wiki locally