`
AILIKES
  • 浏览: 178039 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

服务器搭建安装

阅读更多

 服务器安装手册V2.0

修订记录:

1,在此版安装手册中去掉了缓存的内容:

    一些动态文件命名会被nginx识别为静态文件并缓存,因此暂时不启用缓存。

2Nginx中加入检查后端服务器失效检测配置:

   check interval=3000 rise=2 fall=5 timeout=1000

 

注:

以两台CentOS-6.6-x86_64-minimal服务器为例,示例IP地址如下:

192.168.56.101

192.168.56.102

 

远程拷贝:

scp dirSrc root@192.168.100.239:/opt/usr/tomcat/apache-tomcat-7.0.57

<!--[if !supportLists]-->1.<!--[endif]-->系统基本配置

<!--[if !supportLists]-->1.1.  <!--[endif]-->linux系统

linux系统参数优化配置:

#放开tcp允许打开的最大文件数

ulimit -u 20000 

 

#TCP端口可以重复使用,防止linux 端口被占满

net.ipv4.tcp_tw_reuse = 1 

net.ipv4.tcp_tw_recycle = 1

 

<!--[if !supportLists]-->1.2.  <!--[endif]-->安装基础依赖包

执行如下命令:

yum install -y redhat-lsb unzip vim

<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="图片_x0020_28" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:415.5pt;height:254.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

执行成功后如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_49" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:415.5pt;height:268.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

<!--[if !supportLists]-->1.3.    <!--[endif]-->设置 iptables相应端口的策略

 

开启Nginx监听端口、thrift服务端口、Redis端口

<!--[if gte vml 1]><v:shape id="图片_x0020_55" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:332.25pt;height:21.75pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if gte vml 1]><v:shape id="图片_x0020_54" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:414.75pt;height:167.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if gte vml 1]><v:shape id="图片_x0020_57" o:spid="_x0000_i1029" type="#_x0000_t75" style='width:415.5pt;height:21pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image009.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if gte vml 1]><v:shape id="图片_x0020_56" o:spid="_x0000_i1030" type="#_x0000_t75" style='width:366pt;height:23.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image011.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

注:9999端口属于中台端口、6379端口属于Redis端口,需要公网硬件防火墙屏蔽,不对公网暴露。

 

 

 

<!--[if !supportLists]-->1.4.  <!--[endif]-->修改环境变量

输入如下命令:

vi /etc/profile

在最后一行添加如下代码:

alias vi=vim

保存后执行如下命令:

source /etc/profile

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_7" o:spid="_x0000_i1031" type="#_x0000_t75" style='width:415.5pt;height:209.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image013.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->1.5.  <!--[endif]-->安装上传组件

执行如下命令:

yum install lrzsz

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_46" o:spid="_x0000_i1032" type="#_x0000_t75" style='width:415.5pt;height:245.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image015.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->1.6.  <!--[endif]-->opt目录下创建soft目录,用于存放安装文件

执行如下命令:

mkdir /opt/soft

输入如下命令,将安装包上传到/opt/soft目录下:

rz

<!--[if gte vml 1]><v:shape id="图片_x0020_52" o:spid="_x0000_i1033" type="#_x0000_t75" style='width:414.75pt;height:138.75pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image017.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

<!--[if !supportLists]-->2.<!--[endif]-->mysql安装(适用于Mysql安装环境)

<!--[if !supportLists]-->2.1.  <!--[endif]-->mysql安装大纲

安装依赖

清理相关垃圾数据

配置安装参数

安装编译

初始化运行数据

修改配置文件

mysql启动停止

<!--[if !supportLists]-->2.2.  <!--[endif]-->mysql安装详细步骤

<!--[if !supportLists]-->2.2.1.    <!--[endif]-->删除系统默认的mysql文件

执行如下命令(确保系统内无mysql的遗留信息):

rm –rf /etc/my.cnf

userdel mysql

groupdel mysql

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_37" o:spid="_x0000_i1034" type="#_x0000_t75" style='width:318.75pt;height:83.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image019.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->2.2.2.    <!--[endif]-->安装centos依赖

执行如下命令:

yum install gcc gcc-c++ ncurses-devel zip make cmake

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_22" o:spid="_x0000_i1035" type="#_x0000_t75" style='width:415.5pt;height:213pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image021.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

opt目录下分别创建如下目录:

/usr/mysql:存放mysql的安装程序

/data/mysql:存储mysql的数据文件

/log/mysql:存储mysql的日志信息

建议:将三个目录创建到不同硬盘上

执行如下命令:

mkdir –p /opt/usr/mysql

mkdir –p /opt/data/mysql

mkdir –P /opt/log/mysql

注:-p 递归创建

<!--[if !supportLists]-->2.2.3.    <!--[endif]-->mysql编译安装

切换到/opt/soft目录执行如下命令:

tar –zxvf mysql-5.6.22.tar.gz

如下图所示:

<!--[if gte vml 1]><v:shape id="_x0000_i1036" type="#_x0000_t75" style='width:415.5pt;height:253.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image023.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

进入到mysql-5.6.22目录下执行如下命令:

cmake -DCMAKE_INSTALL_PREFIX=/opt/usr/mysql/mysql-5.6.22 \

-DMYSQL_DATADIR=/data0/search/mysql/data \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1如下图所示:

 

<!--[if gte vml 1]><v:shape id="图片_x0020_61" o:spid="_x0000_i1037" type="#_x0000_t75" style='width:415.5pt;height:250.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image025.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

成功后进行编译安装,执行如下命令:

make –j2 && make install –j2

注:-j8:代表8线程同时进行,可根据机器实际情况进行修改

此处时间较长,可以优先准备my.cnf文件(具体配置信息参见附件)

<!--[if gte vml 1]><v:shape id="图片_x0020_64" o:spid="_x0000_i1038" type="#_x0000_t75" style='width:414.75pt; height:266.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image027.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

/opt/usr/mysql/mysql-5.6.22路径下创建tmpetc目录,执行如下命令:

mkdirtmpetc

将上传的my.cnf转移到tmp目录下,执行如下命令:

mv my.cnf ../usr/mysql/mysql-5.6.22/tmp/

进入到/scripts目录下初始化数据、日志文件,执行如下命令:

./mysql_install_db --basedir=/opt/usr/mysql/mysql-5.6.22 --datadir=/opt/data/mysql --user=root --defaults-file=/opt/usr/mysql/mysql-5.6.22/tmp/my.cnf

<!--[if gte vml 1]><v:shape id="图片_x0020_1" o:spid="_x0000_i1039" type="#_x0000_t75" style='width:414.75pt;height:268.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image029.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

删除mysql根目录下的my.cnf

rm –rf my.cnf

tmp下的my.cnf移动到etc

mv my.cnf ../etc

拷贝support-files下的mysql.server拷贝到根目录下

cp mysql.server ../

编辑mysql.server283行,添加参数:--user="root"

可以使用:set nu查看行号

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_4" o:spid="_x0000_i1040" type="#_x0000_t75" style='width:414.75pt; height:186pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image031.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->2.3.  <!--[endif]-->主主集群大纲

修改serverid

建立复制账号,供slave同步使用

记录服务器日志偏移量

配置从库并启动复制

主从同步检查

 

<!--[if !supportLists]-->2.4.  <!--[endif]-->主主集群详细

<!--[if !supportLists]-->Ø  <!--[endif]-->删除data_dir目录下的auto.cnf删除

进入到/opt/data/mysql目录下,执行如下命令:

rm –rf auto.cnf (防止相同的UUID

<!--[if !supportLists]-->Ø  <!--[endif]-->修改主库/opt/usr/mysql/mysql-5.6.22/etc/my.cnf文件里的serverid,建议使用当前服务器IP的最后一位

<!--[if !supportLists]-->Ø  <!--[endif]-->修改从库/opt/usr/mysql/mysql-5.6.22/etc/my.cnf文件里的serverid,建议使用当前服务器IP的最后一位

<!--[if !supportLists]-->Ø  <!--[endif]-->在主库的/opt/usr/mysql/mysql-5.6.22/etc/my.cnf文件中[mysqld]下面添加如下命令:

auto_increment_increment=2 (步进值为2使得两条绝对同时插入的纪录不产生冲突)

auto_increment_offset=1(偏移量为1

log_slave_updates=1

<!--[if !supportLists]-->Ø  <!--[endif]-->在从库的/opt/usr/mysql/mysql-5.6.22/etc/my.cnf文件中[mysqld]下面添加如下命令:

auto_increment_increment=2

auto_increment_offset=2(偏移量为2

log_slave_updates=1

<!--[if !supportLists]-->Ø  <!--[endif]-->启动主库、从库

sh mysql.server start

<!--[if !supportLists]-->Ø  <!--[endif]-->主库上拷贝授权账号(只有授权的从库才能进行同步)

GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl';(注意自己所在网段,末尾用%代替)

<!--[if gte vml 1]><v:shape id="Picture_x0020_14" o:spid="_x0000_i1041" type="#_x0000_t75" style='width:414.75pt;height:200.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image033.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->从库上拷贝授权账号(只有授权的从库才能进行同步)

GRANT REPLICATION SLAVE ON *.* to 'repl'@'192.168.1.%' identified by 'repl';

<!--[if gte vml 1]><v:shape id="图片_x0020_10" o:spid="_x0000_i1042" type="#_x0000_t75" style='width:414.75pt;height:190.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image035.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->查看主库的偏移量

show master status

记录fileposition变量

<!--[if gte vml 1]><v:shape id="图片_x0020_13" o:spid="_x0000_i1043" type="#_x0000_t75" style='width:414.75pt; height:159.75pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image037.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

生成如下命令并将如下命令在从库上执行:

change master to

master_host='192.168.56.101',#代表主库的IP

master_user='repl',

master_password='repl',

master_log_file='mysql-bin.000004',#file

master_log_pos=334;#position

将该命名在从库上执行

<!--[if gte vml 1]><v:shape id="图片_x0020_16" o:spid="_x0000_i1044" type="#_x0000_t75" style='width:415.5pt; height:128.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image039.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->查看从库的偏移量

show master status

记录fileposition变量

<!--[if gte vml 1]><v:shape id="Picture_x0020_18" o:spid="_x0000_i1045" type="#_x0000_t75" style='width:414.75pt;height:151.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image041.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

生成如下命令并将如下命令在主库上执行:

change master to

master_host='192.168.56.102', #代表主库的IP

master_user='repl',

master_password='repl',

master_log_file='mysql-bin.000004', #file

master_log_pos=120; #position

<!--[if gte vml 1]><v:shape id="Picture_x0020_19" o:spid="_x0000_i1046" type="#_x0000_t75" style='width:339.75pt; height:147pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image043.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->主库上执行启动命令

start slave;

<!--[if gte vml 1]><v:shape id="Picture_x0020_20" o:spid="_x0000_i1047" type="#_x0000_t75" style='width:324.75pt; height:70.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image045.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->从库上执行命令

start slave;

<!--[if gte vml 1]><v:shape id="图片_x0020_31" o:spid="_x0000_i1048" type="#_x0000_t75" style='width:304.5pt; height:55.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image047.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->Ø  <!--[endif]-->验证主主配置状态

show slave status \G;

<!--[if gte vml 1]><v:shape id="图片_x0020_42" o:spid="_x0000_i1049" type="#_x0000_t75" style='width:390pt;height:371.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image049.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if gte vml 1]><v:shape id="图片_x0020_43" o:spid="_x0000_i1050" type="#_x0000_t75" style='width:414.75pt;height:233.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image051.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

<!--[if !supportLists]-->2.5.  <!--[endif]-->创建数据库

create database sso;(如果主主成功,在主库创建后,从库自动复制)

<!--[if !supportLists]-->2.6.  <!--[endif]-->创建用户sso和密码sso_123并赋权

grant all privileges on sso.* to sso@'%'  identified by 'sso_123'; 

 

<!--[if !supportLists]-->2.7.  <!--[endif]-->常见问题排查

先检查change master to 命令所指定的ip、用户等信息是否正确;然后确认防火墙已关闭(Service iptables stop);然后检查mysql.enf中增加的配置是否有误。

<!--[if !supportLists]-->3.<!--[endif]-->oracle安装

  DBA补充

<!--[if !supportLists]-->4.<!--[endif]-->Redis安装

<!--[if !supportLists]-->4.1.  <!--[endif]-->解压redis安装包

执行如下命令:

tar -zxvf redis-2.8.17.tar.gz

<!--[if !supportLists]-->4.2.  <!--[endif]-->编译安装

进入到解压后的目录,执行如下命令:

make  (此时会生成几个可执行文件)

make PREFIX=/opt/usr/redis/redis-2.8.17 MALLOC=libc install

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_67" o:spid="_x0000_i1051" type="#_x0000_t75" style='width:415.5pt;height:264pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image053.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->4.3.  <!--[endif]-->创建目录

mkdir -p /opt/usr/redis/redis-2.8.17/etc
mkdir -p /opt/usr/redis/redis-2.8.17/tmp
mkdir -p /opt/usr/redis/redis-2.8.17/run

mkdir –p /opt/data/redis

mkdir –p /opt/log/redis

 

<!--[if !supportLists]-->4.4.  <!--[endif]-->拷贝文件

拷贝配置文件,执行如下命令:

cp *.conf /opt/usr/redis/redis-2.8.17/etc

拷贝哨兵配置文件,进入到/opt/soft/redis-2.8.17/src目录下执行如下命令:

cpredis-sentinel /opt/usr/redis/redis-2.8.17/bin/

 

<!--[if !supportLists]-->4.5.  <!--[endif]-->修改配置文件

进入到/opt/usr/redis/redis-2.8.17/etc目录下,打开redis.conf

<!--[if gte vml 1]><v:shape id="图片_x0020_70" o:spid="_x0000_i1052" type="#_x0000_t75" style='width:415.5pt;height:317.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image055.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

修改第41行代码:

/opt/usr/redis/redis-2.8.17/tmp/redis.pid

修改第348行增加密码:(开发暂时不加)

修改第187行,修改持久化目录:

<!--[if gte vml 1]><v:shape id="图片_x0020_73" o:spid="_x0000_i1053" type="#_x0000_t75" style='width:402.75pt;height:117pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image057.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

/opt/data/redis

修改第103行,修改日志存储路径

<!--[if gte vml 1]><v:shape id="图片_x0020_76" o:spid="_x0000_i1054" type="#_x0000_t75" style='width:393.75pt;height:177.75pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image059.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

/opt/log/redis/redis.log

 

<!--[if !supportLists]-->4.6.  <!--[endif]-->启动停止redis

启动redis,在bin目录下执行:

./redis-server ../etc/redis.conf &

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_79" o:spid="_x0000_i1055" type="#_x0000_t75" style='width:366.75pt;height:45pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image061.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

停止redis,在bin目录下执行:

./redis-cli shutdown

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_82" o:spid="_x0000_i1056" type="#_x0000_t75" style='width:393.75pt;height:51pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image063.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

修改系统参数,执行如下命令:

vi /etc/sysctl.conf

在最后一行添加

vm.overcommit_memory=1

刷新配置使之生效

sysctl –p

重启redis,显示启动信息如下:

<!--[if gte vml 1]><v:shape id="图片_x0020_85" o:spid="_x0000_i1057" type="#_x0000_t75" style='width:415.5pt;height:247.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image065.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

测试

<!--[if gte vml 1]><v:shape id="图片_x0020_44" o:spid="_x0000_i1058" type="#_x0000_t75" style='width:294.75pt;height:122.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image067.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->4.7.  <!--[endif]-->Redis主从配置

修改主redis服务器,打开etc目录下redis.conf文件,找到45行,修改port如下

<!--[if gte vml 1]><v:shape id="图片_x0020_45" o:spid="_x0000_i1059" type="#_x0000_t75" style='width:178.5pt;height:53.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image069.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

修改备redis服务器,打开etc目录下redis.conf文件,找到45行,修改port如下

<!--[if gte vml 1]><v:shape id="图片_x0020_47" o:spid="_x0000_i1060" type="#_x0000_t75" style='width:126.75pt;height:50.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image071.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

找到205行,修改如下

<!--[if gte vml 1]><v:shape id="图片_x0020_53" o:spid="_x0000_i1061" type="#_x0000_t75" style='width:184.5pt;height:49.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image073.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

打开etc目录下sentinel.conf文件53

<!--[if gte vml 1]><v:shape id="Picture_x0020_36" o:spid="_x0000_i1062" type="#_x0000_t75" style='width:261.75pt;height:41.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image075.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

使用客户端连接时需要加端口号

<!--[if gte vml 1]><v:shape id="图片_x0020_50" o:spid="_x0000_i1063" type="#_x0000_t75" style='width:234pt;height:34.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image077.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

<!--[if !supportLists]-->4.8.  <!--[endif]-->主从切换

<!--[if !supportLists]-->1.<!--[endif]-->如果主机停止工作,在从机执行redis-cli -p 6380 slaveof NO ONE从机将变为主机。

<!--[if gte vml 1]><v:shape id="_x0000_i1064" type="#_x0000_t75" style='width:414.75pt;height:124.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image079.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->2.<!--[endif]-->原主机恢复正常,则将现在的主机数据进行保存,然后将现在主机数据文件(在目录/opt/data/redis/dump.rdb)拷贝到原主机并覆盖原主机数据文件(在目录/opt/data/redis/dump.rdb),启动原来主机,将现有主机切换为从机(命令redis-cli -p 6380 slaveof 主机IP)。

<!--[if gte vml 1]><v:shape id="_x0000_i1065" type="#_x0000_t75" style='width:412.5pt;height:175.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image081.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->4.9.  <!--[endif]-->参数优化

redis内存限制为512M

<!--[if gte vml 1]><v:shape id="_x0000_i1066" type="#_x0000_t75" style='width:138pt;height:35.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image083.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

 

<!--[if !supportLists]-->5.<!--[endif]-->jdk安装

<!--[if !supportLists]-->5.1.  <!--[endif]-->创建目录

mkdir –p /opt/usr/java

<!--[if !supportLists]-->5.2.  <!--[endif]-->解压安装文件

tar -zxvf jdk-7u71-linux-x64.tar.gz

将解压好的目录转移到/opt/usr/java目录下

mv jdk1.7.0_71 /opt/usr/java

 

<!--[if !supportLists]-->5.3.  <!--[endif]-->修改环境变量

vi ~/.bashrc

将如下代码添加到最后一行

export JAVA_HOME=/opt/usr/java/jdk1.7.0_71

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

更新环境变量

source ~/.bashrc

验证

java –version

出现如下界面:

<!--[if gte vml 1]><v:shape id="图片_x0020_88" o:spid="_x0000_i1067" type="#_x0000_t75" style='width:415.5pt;height:268.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image085.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->6.<!--[endif]-->nginx安装

<!--[if !supportLists]-->6.1.  <!--[endif]-->安装依赖包

执行如下命令:

yum -y install make gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel

<!--[if gte vml 1]><v:shape id="图片_x0020_91" o:spid="_x0000_i1068" type="#_x0000_t75" style='width:414.75pt;height:289.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image087.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->6.2.  <!--[endif]-->解压nginxcheck

解压nginx,执行如下命令:

tar -zxvf nginx-1.7.9.tar.gz

解压nginx健康检查模块,执行如下命令:

unzip nginx_upstream_check_module-master.zip

进入到nginx解压路径下/opt/soft/nginx-1.7.9,执行如下命令:

patch -p1 < /opt/soft/nginx_upstream_check_module-master/check_1.7.5+.patch

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_94" o:spid="_x0000_i1069" type="#_x0000_t75" style='width:415.5pt;height:76.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image089.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->6.3.  <!--[endif]-->设置安装参数

执行如下命令:

./configure \

  --prefix=/opt/usr/nginx/nginx-1.7.9 \

  --add-module=/opt/soft/nginx_upstream_check_module-master

<!--[if gte vml 1]><v:shape id="图片_x0020_97" o:spid="_x0000_i1070" type="#_x0000_t75" style='width:414.75pt;height:267pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image091.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->6.4.  <!--[endif]-->编译并安装

执行如下命令:

make  && make install

<!--[if gte vml 1]><v:shape id="图片_x0020_100" o:spid="_x0000_i1071" type="#_x0000_t75" style='width:416.25pt;height:285pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image093.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->6.5.  <!--[endif]-->参数优化

进入到/opt/usr/nginx/nginx-1.7.9/conf目录下打开nginx.conf,修改如下信息:

第三行,修改线程数,参考当前CPU数量

worker_processes  2;

worker_cpu_affinity 01 10;

worker_rlimit_nofile 1000000;

<!--[if gte vml 1]><v:shape id="图片_x0020_112" o:spid="_x0000_i1072" type="#_x0000_t75" style='width:303pt;height:101.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image095.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

修改第15行的event,添加如下代码:

use epoll;

<!--[if gte vml 1]><v:shape id="图片_x0020_115" o:spid="_x0000_i1073" type="#_x0000_t75" style='width:308.25pt;height:71.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image097.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

 

参数优化:

开启Gzip压缩

 

gzip on;

   gzip_min_length  3k;

   gzip_buffers     4 16k;

   #gzip_http_version 1.0;

   gzip_comp_level 4;

   gzip_types       text/plain application/javascript application/x-javascript text/css application/xml text/javascript  ;

   gzip_vary on;

   gzip_disable "MSIE [1-6].";

 

 

Upstream要放在httpserver外;

upstream server1 {

        server 127.0.0.1:81;

        server 127.0.0.1:82;

        check interval=3000 rise=2 fall=1 timeout=1000;

}

Location放在server

配置反向代理

location / {   //注意这里要写项目名称ynp-web

        proxy_pass      http://server1/ynp-web;

        proxy_redirect  off;

        proxy_set_header   Host             $host;

        proxy_set_header        X-Forwarded-For $http_x_forwarded_for;

        proxy_set_header   X-Real-IP        $remote_addr;

        proxy_set_header   REMOTE-HOST      $remote_addr;

}

 

监控

location /nstatus {

    check_status;

    access_log off;

}

 

 

<!--[if !supportLists]-->6.6.  <!--[endif]-->启动ngixn

进入到sbin目录下,执行如下命令:

./nginx

启动成功,如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_118" o:spid="_x0000_i1074" type="#_x0000_t75" style='width:414pt;height:162.75pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image099.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

停止nginx

./nginx -s stop

 

Nginx自动启动脚本

#!/bin/sh

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/nginx.pid

 

# Source function library.

. /etc/rc.d/init.d/functions

 

# Source networking configuration.

. /etc/sysconfig/network

 

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

 

nginx="/opt/usr/nginx/nginx-1.7.9/sbin/nginx"

prog=$(basename $nginx)

 

NGINX_CONF_FILE="/opt/usr/nginx/nginx-1.7.9/conf/nginx.conf"

 

lockfile=/var/lock/subsys/nginx

 

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

 

restart() {

configtest || return $?

stop

start

}

 

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

 

force_reload() {

restart

}

 

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

 

rh_status() {

status $prog

}

 

rh_status_q() {

rh_status >/dev/null 2>&1

}

 

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

 

以上脚本命名为nginx 放入/etc/init.d/

执行

chmod +x /etc/init.d/nginx

/sbin/chkconfig nginx on

sudo /sbin/chkconfig --list nginx

测试调用命令如下:

调用命令如下

service nginx start

service nginx stop

service nginx restart

service nginx reload

service nginx status

 

 

 

<!--[if !supportLists]-->7.<!--[endif]-->SVN安装

执行如下命令

yum install subversion

如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_121" o:spid="_x0000_i1075" type="#_x0000_t75" style='width:415.5pt;height:274.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image101.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->8.<!--[endif]-->Maven安装

<!--[if !supportLists]-->8.1.  <!--[endif]-->解压安装包

创建目录

mkdir –p /opt/usr/maven

将安装包解压到/opt/usr/maven目录下:

tar -zxvf apache-maven-3.2.5-bin.tar.gz

将解压的目录转移到/opt/usr/maven目录下:

mv apache-maven-3.2.5 /opt/usr/maven/

<!--[if !supportLists]-->8.2.  <!--[endif]-->添加bin的环境变量

将以下代码添加到~/.bashrc

vi ~/.bashrc

export PATH=$PATH:/opt/usr/maven/apache-maven-3.2.5/bin

source ~/.bashrc

验证

mvn –version

<!--[if gte vml 1]><v:shape id="图片_x0020_124" o:spid="_x0000_i1076" type="#_x0000_t75" style='width:415.5pt;height:89.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image103.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->8.3.  <!--[endif]-->修改配置文件

conf下备份setting.xml,执行如下命令:

cp settings.xml settings.xml.bak

修改maven/conf/settings.xml配置文件

<settings>节点下添加入下命令:

<localRepository>/opt/tmp/.m2/repository</localRepository>
如下图所示:

<!--[if gte vml 1]><v:shape id="图片_x0020_127" o:spid="_x0000_i1077" type="#_x0000_t75" style='width:415.5pt; height:115.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image105.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

<!--[if !supportLists]-->8.4.  <!--[endif]-->工程打包

创建目录:

mkdir –p /opt/usr/src

进入到src目录下,迁出代码,执行如下命令:

svn co <!--[if gte vml 1]><v:shape id="图片_x0020_130" o:spid="_x0000_i1078" type="#_x0000_t75" style='width:15pt;height:11.25pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image107.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->https://182.92.167.67:18443/svn/YNC365-SSO/trunk

第一个root回车

后面输入svn的用户名密码

<!--[if gte vml 1]><v:shape id="图片_x0020_132" o:spid="_x0000_i1079" type="#_x0000_t75" style='width:415.5pt;height:283.5pt'> <v:imagedata src="file:///C:\Users\ailikes\AppData\Local\Temp\msohtmlclip1\01\clip_image109.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->

进入到主pom目录下,即sso-pom执行打包命令:

mvn clean package -U -Dmaven.test.skip=true -T 1C -Pdev

-U:强制更新依赖

-Dmaven.test.skip=true:忽略单元测试

-T 1C11线程

-Pdev:以开发环境变量打包

<!--[if !supportLists]-->9.<!--[endif]-->tomcat安装

<!--[if !supportLists]-->9.1.  <!--[endif]-->创建目录

执行如下命令

mkdir –p /opt/usr/tomcat

<!--[if !supportLists]-->9.2.  <!--[endif]-->解压安装

tomcat压缩包解解压到/opt/usr/tomcat目录下

<!--[if !supportLists]-->9.3.  <!--[endif]-->参数优化

共享session配置

conf/context.xml添加

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

         host="192.168.99.1"

         port="6379"

         database="0"

         maxInactiveInterval="60" />

jedis-2.5.2.jarcommons-pool2-2.2.jartomcat-redis-session-manager1.2.jar放到lib目录下

 

系统启动脚本如下:

#!/bin/bash

 

#

# Startup script for the tomcat

#

# chkconfig: 345 80 15

# description: Tomcat is a Servlet+JSP Engine.

export JDK_HOME=/opt/usr/java/jdk1.7.0_71

export JAVA_HOME=/opt/usr/java/jdk1.7.0_71

# Source function library.

. /etc/rc.d/init.d/functions

start(){

if [ -z $(/sbin/pidof java) ]; then

echo "Starting tomcat"

/opt/usr/tomcat/apache-tomcat-7.0.57/bin/startup.sh

touch /var/lock/subsys/tomcat

else

echo "tomcat allready running"

fi

}

stop(){

if [ ! -z $(/sbin/pidof java) ]; then

echo "Shutting down tomcat"

/opt/usr/tomcat/apache-tomcat-7.0.57/bin/shutdown.sh

until [ -z $(/sbin/pidof java) ]; do :; done

rm -f /var/lock/subsys/tomcat

else

echo "tomcat not running"

fi

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

status)

/opt/usr/tomcat/apache-tomcat-7.0.57/bin/catalina.sh version

;;

*)

echo "Usage: $0 {start|stop|restart|status}"

esac

 

exit 0

 

将以上脚本命名为tomcat放入/etc/rc.d/init.d

执行
chmod +x /etc/init.d/tomcat

chkconfig --add tomcat

内存设置

修改TOMCAT_HOME/bin/catalina.sh 
位置cygwin=false

export JAVA_OPTS="-server -Xms1400M -Xmx1400M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:PermSize=128M -XX:MaxPermSize=256M -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m  -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true "

注:红字字体部分要根据部署机器实际情况调整。

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics