3.16 lnmt部署&tomcat

文章目录

  • 1. lnmt简介
    • 1.1 nginx安装
    • 1.2 安装mysql
    • 1.3 tomcat部署
      • 1.3.1 java环境安装
      • 1.3.2 tomcat部署
      • 1.3.3 tomcat访问控制
  • 2. jenkins部署

1. lnmt简介

lnmt: 表示的是 linux + nginx + mysql + tomcat 的简称

  • Apache 为HTML页面服务,而Tomcat实际上运行JSP页面和Servlet,Tomcat实际上运行JSP页面和Servlet,Tomcat处理静态HTML的能力不如Apache服务器

1.1 nginx安装

1.创建系统用户nginx
[root@130 ~]# useradd -r -M -s /sbin/nologin nginx

2.安装依赖环境
[root@130 ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@130 ~]# yum -y groups mark install 'Development Tools'

3.创建日志存放目录
[root@130 ~]# mkdir -p /var/log/nginx
[root@130 ~]# chown -R nginx.nginx /var/log/nginx

4下载nginx至/usr/src/
[root@130 src]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

5.解压
[root@130 src]# tar xf nginx-1.16.1.tar.gz
[root@130 src]# cd nginx-1.16.1 
[root@130 nginx-1.16.1]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README

6.编译安装
[root@130 nginx-1.16.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_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@130 nginx-1.16.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

7.添加环境变量
[root@130 nginx-1.16.1]# ls /usr/local/nginx/sbin/
nginx  nginx.old
[root@130 nginx-1.16.1]# echo 'export PATH=/usr/local/nginx/sbin/:$PATH'>/etc/profile.d/nginx.sh
[root@130 nginx-1.16.1]# . /etc/profile.d/nginx.sh
[root@130 nginx-1.16.1]# nginx
[root@130 nginx-1.16.1]# ss -anlt
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                         :::*

1.2 安装mysql

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@localhost src]# groupadd -r -g 306 mysql
[root@localhost src]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql


//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

//解压软件至/usr/local/
[root@localhost src]# ls
debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.22-linux-glibc2.12-x86_64  share
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root   6 Mar 10  2016 bin
drwxr-xr-x. 2 root root   6 Mar 10  2016 etc
drwxr-xr-x. 2 root root   6 Mar 10  2016 games
drwxr-xr-x. 2 root root   6 Mar 10  2016 include
drwxr-xr-x. 2 root root   6 Mar 10  2016 lib
drwxr-xr-x. 2 root root   6 Mar 10  2016 lib64
drwxr-xr-x. 2 root root   6 Mar 10  2016 libexec
lrwxrwxrwx  1 root root  36 Aug 14 16:00 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x  9 root root 129 Aug 14 00:16 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 Mar 10  2016 sbin
drwxr-xr-x. 5 root root  49 Jun 13 19:03 share
drwxr-xr-x. 2 root root   6 Mar 10  2016 src


//修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 Aug 14 16:00 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/



//添加环境变量
[root@localhost ~]# ls /usr/local/mysql
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin



//建立数据存放目录
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/
[root@localhost mysql]# ll /opt/
total 0
drwxr-xr-x 2 mysql mysql 6 Aug 14 16:54 data

//初始化数据库
[root@localhost ~]# /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: jtBzkkb=r5ik
//请注意,这个命令的最后会生成一个临时密码,此处密码是jtBzkkb=r5ik
//再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到


//配置mysql
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig      

//生成配置文件
[root@localhost ~]# cat > /etc/my.cnf <
[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
Starting MySQL.. SUCCESS!  
[root@localhost ~]# ps -ef|grep mysql
root       1521      1  0 01:58 pts/0    00:00:00 /bin/sh /usr/local/mysql/binmysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql      1699   1521  0 01:58 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root       1734   1301  0 01:59 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# 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      128        :::22                     :::*
LISTEN      0      100       ::1:25                     :::*
LISTEN      0      80         :::3306                   :::* 
 
//修改密码
//使用临时密码登录
[root@localhost ~]# mysql -uroot -p
Enter password:
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> 

//设置新密码
mysql> set password = password('wangqing123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye

1.3 tomcat部署

1.3.1 java环境安装

1.安装jdk环境
[root@130 ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

2.查看安装版本
[root@130 ~]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

1.3.2 tomcat部署

1.下载tomcat
[root@130 ~]# cd /usr/src/
[root@130 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.30.tar.gz

2.解压
[root@130 src]# tar xf apache-tomcat-9.0.30.tar.gz

3.绿色软件,解压后即可使用,无需编译
[root@130 src]# tar xf apache-tomcat-9.0.30.tar.gz -C /usr/local/

4.创建软链接,便于使用
[root@130 src]# cd /usr/local/
[root@130 local]# ls
apache-tomcat-9.0.30  games    lib64    mysql-5.7.22-linux-glibc2.12-x86_64  share
bin                   include  libexec  nginx                                src
etc                   lib      mysql    sbin
[root@130 local]# ln -sv apache-tomcat-9.0.30 tomcat
"tomcat" -> "apache-tomcat-9.0.30"
[root@130 local]# ll -d tomcat
lrwxrwxrwx. 1 root root 20 1月   8 10:29 tomcat -> apache-tomcat-9.0.30

5.测试,写一个hello world的java页面
[root@130 ~]# vim index.jsp
[root@130 ~]# cat index.jsp
<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
            out.println("Hellow World");
        %>
</body>
</html>
[root@130 ~]# vim index.jsp
[root@130 ~]# mkdir /usr/local/tomcat/webapps/test
[root@130 ~]# cp index.jsp /usr/local/tomcat/webapps/test/.
[root@130 ~]# ll /usr/local/tomcat/webapps/test/
总用量 4
-rw-r--r--. 1 root root 141 1月   8 10:33 index.jsp

6.启动tomcat
[root@130 conf]# /usr/local/tomcat/bin/catalina.sh start 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@130 conf]# ps -ef | grep tomcat
root      53239      1 17 10:37 pts/2    00:00:03 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root      53283  31091  0 10:37 pts/2    00:00:00 grep --color=auto tomcat
[root@130 conf]# ss -anlt
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      100            :::8080                       :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      1        ::ffff:127.0.0.1:8005                       :::*                  
LISTEN      0      100            :::8009                       :::*                  
LISTEN      0      80             :::3306                       :::* 

7.启动效果
3.16 lnmt部署&tomcat_第1张图片

1.3.3 tomcat访问控制

3.16 lnmt部署&tomcat_第2张图片
点击Server Status/Manager App/Host Manager按钮会出现报错提示,根据提示配置tomcat
3.16 lnmt部署&tomcat_第3张图片

1.在tomcat服务conf/tomcat-users.xml添加用户及设置权限
[root@130 ~]# cd /usr/local/tomcat/conf/
[root@130 conf]# ls
Catalina             context.xml           logging.properties  tomcat-users.xsd
catalina.policy      jaspic-providers.xml  server.xml          web.xml
catalina.properties  jaspic-providers.xsd  tomcat-users.xml
[root@130 conf]# vim tomcat-users.xml 
[root@130 conf]# tail tomcat-users.xml
......//以上配置省略
  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <user username="tomcat" password="123456" roles="admin-gui,manager-gui"/>
</tomcat-users>

2.设置允许访问ip
[root@130 conf]# cd /usr/local/tomcat/
[root@130 tomcat]# ls
bin           conf             lib      logs    README.md      RUNNING.txt  webapps
BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
[root@130 tomcat]# cd
[root@130 ~]# cd /usr/local/tomcat/webapps/
[root@130 webapps]# ls
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT  test
[root@130 webapps]# cd manager/
[root@130 manager]# ls
images  index.jsp  META-INF  status.xsd  WEB-INF  xform.xsl
[root@130 manager]# vim META-INF/context.xml
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.168\.80\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.
[root@130 manager]# vim ../host-manager/META-INF/context.xml
  "
         allow="192\.168\.80\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  3.16 lnmt部署&tomcat_第4张图片
3.16 lnmt部署&tomcat_第5张图片
3.16 lnmt部署&tomcat_第6张图片
3.16 lnmt部署&tomcat_第7张图片

2. jenkins部署

1.下载jenkins
[root@130 ~]#  wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

2.将jenkins.war拷贝至tomcat服务下的webapps目录下,自动解压,部署完成
[root@130 ~]# cp jenkins.war /usr/local/tomcat/webapps/
[root@130 ~]# ls /usr/local/tomcat/webapps/
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT  test

3.16 lnmt部署&tomcat_第8张图片

根据提示获取密码
[root@130 ~]# cat /root/.jenkins/secrets/initialAdminPassword
570b0eb5e49b49b3a04f33f5754c02e3

进入jenkins
3.16 lnmt部署&tomcat_第9张图片

你可能感兴趣的:(Linux服务管理)