lnmt

1.nginx安装与配置

1.1安装nginx

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

//安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[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 src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@localhost src]# ls
debug  kernels  nginx-1.12.0.tar.gz

//编译安装
[root@localhost src]# tar xf nginx-1.12.0.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  nginx-1.12.0  sbin  share  src
[root@localhost local]# cd nginx-1.12.0/
[root@localhost nginx-1.12.0]# ./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@localhost nginx-1.12.0]# make && make install

1.2nginx安装后的配置

//配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh

//启动nginx
[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      25                         *:514                                    *:*                  
LISTEN      0      128                       :::22                                    :::*                  
LISTEN      0      100                      ::1:25                                    :::*                  
LISTEN      0      25                        :::514                                   :::*  

//网站访问

2.mysql安装与配置

2.1安装mysql

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# 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 src]# cd /usr/local/
[root@localhost local]# ls
bin  games    lib    libexec                              nginx         sbin   src
etc  include  lib64  mysql-5.7.22-linux-glibc2.12-x86_64  nginx-1.12.0  share
[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]# ls
bin  games    lib    libexec  mysql-5.7.22-linux-glibc2.12-x86_64  nginx-1.12.0  share
etc  include  lib64  mysql    nginx                                sbin          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/
2020-01-08T01:17:10.279568Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-01-08T01:17:10.746049Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-01-08T01:17:10.804979Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-01-08T01:17:10.899793Z 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: 98673ab3-31b4-11ea-bcca-000c2900526e.
2020-01-08T01:17:10.900504Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-01-08T01:17:10.901585Z 1 [Note] A temporary password is generated for root@localhost: RD8RvivKwK%+
[root@localhost ~]# echo 'RD8RvivKwK%+' > /root/pass
[root@localhost ~]# cat /root/pass 
RD8RvivKwK%+

2.2mysql配置

//配置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 <<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
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 
[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      25                         *:514                                    *:*                  
LISTEN      0      128                       :::22                                    :::*                  
LISTEN      0      100                      ::1:25                                    :::*                  
LISTEN      0      25                        :::514                                   :::*                  
LISTEN      0      80                        :::3306                                  :::*             

//修改密码
//使用临时密码登录
[root@localhost ~]# cat /root/pass 
RD8RvivKwK%+
[root@localhost ~]# mysql -uroot -p'RD8RvivKwK%+'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye

3.部署tomcat

3.1java环境安装

//安装jdk环境
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

//查看安装的版本
[root@localhost ~]# 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)

3.2tomcat部署

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

//解压部署
[root@localhost src]# ls
apache-tomcat-9.0.30.tar.gz  debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz  nginx-1.12.0.tar.gz
[root@localhost src]# tar xf apache-tomcat-9.0.30.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-9.0.30  etc    include  lib64    mysql                                nginx         sbin   src
bin                   games  lib      libexec  mysql-5.7.22-linux-glibc2.12-x86_64  nginx-1.12.0  share
[root@localhost local]# ln -s apache-tomcat-9.0.30/ tomcat
[root@localhost local]# ls
apache-tomcat-9.0.30  games    lib64    mysql-5.7.22-linux-glibc2.12-x86_64  sbin   tomcat
bin                   include  libexec  nginx                                share
etc                   lib      mysql    nginx-1.12.0                         src

//写一个hello world的java页面
[root@localhost ~]# vim index.jsp

<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
            out.println("Hellow World");
        %>
</body>
</html>
[root@localhost ~]# mkdir /usr/local/tomcat/webapps/test
[root@localhost ~]# cp index.jsp /usr/local/tomcat/webapps/test/

//启动tomcat
[root@localhost ~]# /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@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      25                         *:514                                    *:*                  
LISTEN      0      100                       :::8080                                  :::*                  
LISTEN      0      128                       :::22                                    :::*                  
LISTEN      0      100                      ::1:25                                    :::*                  
LISTEN      0      25                        :::514                                   :::*                  
LISTEN      0      1           ::ffff:127.0.0.1:8005                                  :::*                  
LISTEN      0      100                       :::8009                                  :::*                  
LISTEN      0      80                        :::3306                                  :::*    

//网站访问

4.nginx反向代理

4.1全部反代至tomcat

//修改配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
...

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://127.0.0.1:8080;
        }

        #error_page  404              /404.html;

....
[root@localhost ~]# 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@localhost ~]# nginx -s stop
[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      25                         *:514                                    *:*                  
LISTEN      0      100                       :::8080                                  :::*                  
LISTEN      0      128                       :::22                                    :::*                  
LISTEN      0      100                      ::1:25                                    :::*                  
LISTEN      0      25                        :::514                                   :::*                  
LISTEN      0      1           ::ffff:127.0.0.1:8005                                  :::*                  
LISTEN      0      100                       :::8009                                  :::*                  
LISTEN      0      80                        :::3306                                  :::*  

//网站访问

4.2动静分离

//修改配置文件
[root@localhost test]# vim /usr/local/nginx/conf/nginx.conf
...   
      #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location ~* .(jsp|do)$ {
            proxy_pass http://127.0.0.1:8080;
}

        #error_page  404              /404.html;
...
[root@localhost html]# ls
1.jpg  50x.html  index.html
[root@localhost test]# nginx -s stop
[root@localhost test]# nginx
[root@localhost test]# 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      25                         *:514                                    *:*                  
LISTEN      0      100                       :::8080                                  :::*                  
LISTEN      0      128                       :::22                                    :::*                  
LISTEN      0      100                      ::1:25                                    :::*                  
LISTEN      0      25                        :::514                                   :::*                  
LISTEN      0      1           ::ffff:127.0.0.1:8005                                  :::*                  
LISTEN      0      100                       :::8009                                  :::*                  
LISTEN      0      80                        :::3306                                  ::

//网站访问

5.部署jenkins

//下载jenkins
[root@localhost ~]# ls
anaconda-ks.cfg  index.jsp  jenkins.war  pass

//部署jenkins
[root@localhost ~]# cp jenkins.war /usr/local/tomcat/webapps/
[root@localhost ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT  test
[root@localhost webapps]# cd jenkins
[root@localhost jenkins]# ls
bootstrap             help                         LogFileOutputStream.class      META-INF
ColorFormatter.class  images                       Main.class                     robots.txt
css                   JNLPMain.class               MainDialog$1$1.class           scripts
dc-license.txt        jsbundles                    MainDialog$1.class             WEB-INF
executable            LogFileOutputStream$1.class  MainDialog.class               winstone.jar
favicon.ico           LogFileOutputStream$2.class  Main$FileAndDescription.class

//网站访问

原文地址:https://www.cnblogs.com/liping0826/p/12163328.html