概述
lnmt 架构搭建
- lnmt 架构
- 1.nginx 安装
- 2.mysql 安装
- 3.tomcat 安装
- 4.nginx 配置与验证
lnmt 架构
1.nginx 安装
//首先请确保本地仓库可用
//创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
//安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
[root@localhost ~]# yum -y groups mark install 'Development Tools'
//创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
//编译安装
[root@localhost src]# tar xf nginx-1.14.0.tar.gz
[root@localhost src]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-debug --with-http_ssl_module --with-http_realip_module --withhttp_gunzip_module
--with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log
--error-log-path=/var/log/nginx/error.log
……过程略
[root@localhost nginx-1.14.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) &&make install
……过程略
//配置
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' >/etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
[root@localhost ~]# nginx
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
2.mysql 安装
//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-deve
……下载过程略
//创建用户与组
[root@localhost ~]# cd /usr/src/
[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
//下载mysql二进制安装包
[root@localhost src]# wget https://downloads.mysql.com/archives/get/file/mysql5.7.22-linux-glibc2.12-x86_64.tar.gz
……下载过程略
//解压软件至/usr/local
[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
//创建软连接
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
//添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
//初始化数据库 注意这个命令后会生成临时密码 要记住 !!!!
[root@lanzhiyong ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2018-08-15T07:57:46.168380Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-15T07:57:50.542516Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-15T07:57:50.927286Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-15T07:57:51.071260Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e8600890-a060-11e8-b1a2-000c294c50b4.
2018-08-15T07:57:51.074566Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-15T07:57:51.078089Z 1 [Note] A temporary password is generatedfor root@localhost: hfGdwnViq6,,
// 请注意,这个命令的最后会生成一个临时密码,此处密码是hfGdwnViq6,,
//配置mysql
//创建软连接
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig -v
//生成配置文件
[root@localhost ~]# cat > /etc/my.cnf << EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
//配置服务启动脚本
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#⧵1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#⧵1/opt/data#g' /etc/init.d/mysqld
//启动mysql
[root@localhost ~]# service mysqld start
[root@localhost ~]# ps -ef |grep mysql
[root@localhost ~]#ss -antl
//修改密码 使用临时密码登入然后修改密码!!!!
[root@localhost ~]# mysql -uroot -p'hfGdwnViq6,,'
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> set password = password('12345');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
//使用新密码登录
[root@localhost ~]# mysql -uroot -p12345
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
3.tomcat 安装
//关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
**//将第六行中的 enforcing 改为 disabled**
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@localhost ~]# setenforce 0
//安装之前请确保本地仓库可用
//安装jdk环境
[root@localhost ~]# yum -y install java-1.8.0*
……下载过程略
[root@localhost src]# cd /usr/local/
[root@localhost local]# mkdir tomcat
//下载tomcat
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
……下载过程略
[root@localhost src]# ls
apache-tomcat-9.0.35.tar.gz debug kernels
//部署项目一
[root@localhost src]# tar xf apache-tomcat-9.0.35.tar.gz
[root@localhost src]# ls
apache-tomcat-9.0.35 apache-tomcat-9.0.35.tar.gz debug kernels
[root@localhost src]# mv apache-tomcat-9.0.35 tomcat1
[root@localhost src]# mv tomcat1 /usr/local/tomcat/
//部署项目二
[root@localhost src]# tar xf apache-tomcat-9.0.35.tar.gz
[root@localhost src]# ls
apache-tomcat-9.0.35 apache-tomcat-9.0.35.tar.gz debug kernels
[root@localhost src]# mv apache-tomcat-9.0.35 tomcat2
[root@localhost src]# mv tomcat2 /usr/local/tomcat/
[root@localhost src]# cd /usr/local/tomcat/
[root@localhost tomcat]# ls
tomcat1 tomcat2
//分别在两个项目中进行测试
//tomcat1
[root@localhost tomcat]# cd tomcat1/webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT
//创建测试文档
[root@localhost webapps]# mkdir test
[root@localhost webapps]# cd test/
//编写一个java页面进行测试
[root@localhost test]# vim index.jsp
[root@localhost test]# cat index.jsp
<html>
<head>
<title>test</title>
</head>
<body>
<%
out.println("Hellow World");
%>
</body>
</html>
//在tomcat2中的操作与tomcat1中相同
[root@localhost tomcat]# cd tomcat2/webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT
//创建测试文档
[root@localhost webapps]# mkdir test
[root@localhost webapps]# cd test/
//编写一个java页面进行测试
[root@localhost test]# vim index.jsp
[root@localhost test]# cat index.jsp
<html>
<head>
<title>test</title>
</head>
<body>
<%
out.println("I Love china");
%>
</body>
</html>
//启动tomcat
//启动tomcat1,端口为8080和8005
[root@localhost ~]# /usr/local/tomcat/tomcat1/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat/tomcat1
Using CATALINA_HOME: /usr/local/tomcat/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat1/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/tomcat1/bin/bootstrap.jar:/usr/local/tomcat/tomcat1/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
//tomcat2无法与tomcat1一样启动,因为他们的服务端口是一样的,如果再启动tomcat2就会有冲突。
//要想启动tomcat2,需要更改tomcat2的服务端口
[root@localhost ~]# cd /usr/local/tomcat/tomcat2/conf/
[root@localhost conf]# ls
catalina.policy context.xml jaspic-providers.xsd server.xml tomcat-users.xsd
catalina.properties jaspic-providers.xml logging.properties tomcat-users.xml web.xml
[root@localhost conf]# vim server.xml
.......
//将prot后的8005端口改为你想改的。
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
.......
.......
//将prot后的8080端口改为你想改的。
//将redirectPort后的8443端口改为你想改的。
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8445" />
.......
//改完后就可以启动tomcat2
[root@localhost ~]# /usr/local/tomcat/tomcat2/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat/tomcat2
Using CATALINA_HOME: /usr/local/tomcat/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat2/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/tomcat2/bin/bootstrap.jar:/usr/local/tomcat/tomcat2/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 100 :::8080 :::*
LISTEN 0 100 :::8081 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8006 :::*
4.nginx 配置与验证
//添加下面模块(负载均衡,轮询)
upstream tomcat {
server 192.168.206.130:8080;
server 192.168.206.130:8081;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
//单独在添加一个location模块(反向代理,tomcat动态访问)
location ~*.(do|jsp)$ {
proxy_pass http://tomcat;
}
..........
..........
[root@super ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@super ~]# nginx -s reload
[root@super ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 100 :::8081 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8006 :::*
LISTEN 0 80 :::3306 :::*
在浏览器上验证输入:192.168.206.130/test/index.jsp
然后可以刷新看效果。
刷新
最后
以上就是感动睫毛膏为你收集整理的lnmt 架构搭建lnmt 架构的全部内容,希望文章能够帮你解决lnmt 架构搭建lnmt 架构所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复