Linux-组件安装

安装命令

程序安装

[root@master ~]$ rpm -ivh your-package.rpm

程序查看

[root@master ~]$ rpm –qa

程序卸载

[root@master ~]$ rpm –e --nodeps

安装依赖文件

Linux安装JDK/Tomcat/MySql过程中,需要从网上下载部分支持包才可以安装使用,所以在安装前,需要下载对应的依赖文件。

 [root@master ~]$ yum install glibc.i686
 [root@master ~]$ yum –y install libiao.so.1
 [root@master ~]$ yum install gcc gcc-c++ autoconf automake
 [root@master ~]$ yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel 

JDK安装

卸载之前的JDK

  • 查看是否安装JDK
    #查看是否安装JDK
    [root@master ~]$ java -version
    openjdk version "1.8.0_262"
    OpenJDK Runtime Environment (build 1.8.0_262-b10)
    OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
    
  • 查看筛选Java相关的程序

    #查看筛选Java相关的程序
    [root@master ~]$ rpm -qa | grep -i java
    java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
    python-javapackages-3.4.1-11.el7.noarch
    tzdata-java-2020a-1.el7.noarch
    java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
    java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
    javapackages-tools-3.4.1-11.el7.noarch
    java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
    
  • 卸载之前的版本

    [root@master ~]$ rpm -e --nodeps java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
    [root@master ~]$ rpm -e --nodeps java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
    [root@master ~]$ rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
    [root@master ~]$ rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
    

安装

上传JDK文件

将下载好的jdk上传到 /usr/local/java下(java文件夹需要提前创建)

[root@master ~]$ cd /usr/local/java/
[root@master java]$ ls
jdk-8u311-linux-x64.tar.gz

解压

[root@master java]$ tar -zxvf jdk-8u311-linux-x64.tar.gz 
[root@master java]$ ls
jdk1.8.0_311  jdk-8u311-linux-x64.tar.gz

配置环境变量

[root@master java]$ vi /etc/profile
#在最后面添加环境信息
export JAVA_HOME=/usr/local/java/jdk1.8.0_311
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

重新加载环境

[root@master java]$ source /etc/profile

查看PATH信息

[root@master java]$ echo $PATH
/usr/local/java/jdk1.8.0_311/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

检查是否安装成功

[root@master java]$ java -version
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)

MySQL安装

安装

创建并进入mysql文件夹

[root@master ~]$ cd /usr/local/
[root@master local]$ mkdir mysql
[root@master local]$ ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src

下载mysql源安装包

[root@master local]$ cd mysql/
[root@master mysql]$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
[root@master mysql]$ ls
mysql57-community-release-el7-8.noarch.rpm

安装mysql源

[root@master mysql]$ yum localinstall mysql57-community-release-el7-8.noarch.rpm
......
已安装:
  mysql57-community-release.noarch 0:el7-8                                                           
完毕!  #安装完成

检查mysql源是否安装成功

[root@master mysql]$ yum repolist enabled | grep "mysql.*-community.* "
......
mysql-connectors-community/x86_64       MySQL Connectors Community           221
mysql-tools-community/x86_64            MySQL Tools Community                135
mysql57-community/x86_64                MySQL 5.7 Community Server           544

安装mysql

[root@master mysql]$ yum install mysql-community-server
......
已安装:
  mysql-community-libs.x86_64 0:5.7.36-1.el7       mysql-community-libs-compat.x86_64 0:5.7.36-1.el7       mysql-community-server.x86_64 0:5.7.36-1.el7      
作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.36-1.el7                                  mysql-community-common.x86_64 0:5.7.36-1.el7                                 
替代:
  mariadb-libs.x86_64 1:5.5.68-1.el7                                          
完毕!

启动mysql并查看状态

[root@master mysql]$ systemctl start mysqld
[root@master mysql]$ systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2022-01-11 11:01:19 CST; 7s ago
   ......
1月 11 11:01:14 master systemd[1]: Starting MySQL Server...
1月 11 11:01:19 master systemd[1]: Started MySQL Server.

设置开机自启

[root@master mysql]$ systemctl enable mysqld
[root@master mysql]$ systemctl daemon-reload

开放端口

开放端口(选择性使用),否则浏览器访问失败

firewall-cmd --list-ports	#查看已经开放的端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent		#开启端口
firewall-cmd --reload 		#重启
firewall systemctl stop firewalld.service 		#停止
firewall systemctl disable firewalld.service 	#禁止firewall开机启动
systemctl stop firewalld && systemctl disable firewalld	#关闭并重启防火墙

登录

查看mysql密码

[root@master mysql]$ grep 'temporary password' /var/log/mysqld.log
2022-01-11T03:01:16.983069Z 1 [Note] A temporary password is generated for root@localhost: oJ45iff4Vm&c

登录mysql

[root@master mysql]$ mysql -uroot -p
Enter password: 
......
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

设置密码的验证策略等级

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

修改密码长度

mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)

修改密码

mysql> ALTER USER USER() IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

授权

查看mysql库的user表的host字段信息

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

修改权限

#Host字段的localhost表示只允许本机访问,想要远程连接将root用户的host值改成%,
#表示允许任意host访问,如果需要设置只允许特定ip访问,则应改为对应的ip
mysql> update user set host="%" where user="root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

配置刷新生效

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Tomcat

创建目录存放文件

[root@master ~]$ cd /usr/local/
[root@master local]$ mkdir tomcat
[root@master local]$ ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src  tomcat

上传tomcat文件

[root@master tomcat]$ ls
apache-tomcat-8.0.45.tar.gz

解压

[root@master tomcat]$ tar -zxvf apache-tomcat-8.0.45.tar.gz 

端口设置

firewall-cmd --zone=public --add-port=8080/tcp --permanent

修改sh权限

chmod u+x *.sh

启动

进入bin目录运行start:开启

[root@master bin]$ ./startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-8.0.45
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-8.0.45
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.0.45/temp
Using JRE_HOME:        /usr/local/java/jdk1.8.0_311
Using CLASSPATH:       /usr/local/tomcat/apache-tomcat-8.0.45/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.0.45/bin/tomcat-juli.jar
Tomcat started.

关闭

进入bin目录运行shutdown:关闭

[root@master bin]$ ./shutdown.sh 
Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-8.0.45
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-8.0.45
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.0.45/temp
Using JRE_HOME:        /usr/local/java/jdk1.8.0_311

Tomcat+solr

修改文件

修改引用solr引用地址

修改F:\Tools_JAR\apache-tomcat-8.5.60\apache-tomcat-8.5.60 - linux\webapps\solr\WEB-INF\web.xml文件

    <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>/usr/local/tomcat/solr/solr_home</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

修改数据库文件

  <dataSource type="JdbcDataSource" 
              driver="com.mysql.jdbc.Driver" 
              url="jdbc:mysql://localhost:3306/solr" 
              user="root" 
              password="123456"/> 

创建目录存放文件

创建一个目录,存放tomcat和solr文件:/usr/local/tomcat

[root@master ~]$ cd /usr/local/
[root@master local]$ ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src
[root@master local]$ mkdir tomcat
[root@master local]$ ls
bin  etc  games  include  java  lib  lib64  libexec  mysql  sbin  share  src  tomcat
[root@master local]$ cd tomcat/
[root@master tomcat]$ pwd
/usr/local/tomcat

上传文件

将window上tomcat+solr文件复制到该目录下

[root@master tomcat]$ ls
apache-tomcat-8.5.60 - linux  solr

修改sh文件权限

[root@master ~]$ cd /usr/local/tomcat/apache-tomcat-8.5.60\ -\ linux/bin/
[root@master bin]$ ls
bootstrap.jar       ciphers.bat                   configtest.bat  digest.sh         shutdown.sh      tomcat-native.tar.gz  version.sh
catalina.bat        ciphers.sh                    configtest.sh   setclasspath.bat  startup.bat      tool-wrapper.bat
catalina.sh         commons-daemon.jar            daemon.sh       setclasspath.sh   startup.sh       tool-wrapper.sh
catalina-tasks.xml  commons-daemon-native.tar.gz  digest.bat      shutdown.bat      tomcat-juli.jar  version.bat
[root@master bin]$ chmod u+x *.sh

运行tomcat

[root@master bin]$ ./startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-8.5.60 - linux
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-8.5.60 - linux
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.5.60 - linux/temp
Using JRE_HOME:        /usr/local/java/jdk1.8.0_311
Using CLASSPATH:       /usr/local/tomcat/apache-tomcat-8.5.60 - linux/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.60 - linux/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

查看日志文件

[root@master bin]$ cd ../logs/
[root@master logs]$ ls
catalina.2022-01-11.log  catalina.out  host-manager.2022-01-11.log  localhost.2022-01-11.log  localhost_access_log.2022-01-11.txt  manager.2022-01-11.log
[root@master logs]$ cat catalina.2022-01-11.log 

Nginx

安装

安装Nginx源

[root@master ~]$ rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
获取http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
警告:/var/tmp/rpm-tmp.qy0P0J: 头V4 RSA/SHA1 Signature, 密钥 ID 7bd9bf62: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:nginx-release-centos-7-0.el7.ngx ################################# [100%]

源文件位置

[root@master nginx]$ cd /etc/yum.repos.d/
[root@master yum.repos.d]$ ll
-rw-r--r--. 1 root root  113 7月  15 2014 nginx.repo

安装Nginx

[root@master yum.repos.d]$ yum install -y nginx
已加载插件:fastestmirror, langpacks
......
已安装:
  nginx.x86_64 1:1.20.2-1.el7.ngx                                                                                                                     
完毕!

查找nginx文件位置

[root@master yum.repos.d]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
  • Nginx配置路径:/etc/nginx/
  • PID目录:/var/run/nginx.pid
  • 错误日志:/var/log/nginx/error.log
  • 访问日志:/var/log/nginx/access.log
  • 默认站点目录:/usr/share/nginx/html

启动nginx

[root@master yum.repos.d]# nginx

关闭防火墙

[root@master yum.repos.d]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

nginx重启

[root@master yum.repos.d]# nginx -s reload

nginx停止

[root@master yum.repos.d]# nginx -s stop

查看服务PID

[root@master yum.repos.d]# ps -ef |grep nginx
root       2353      1  0 16:31 ?        00:00:00 nginx: master process nginx
nginx      2357   2353  0 16:31 ?        00:00:00 nginx: worker process is shutting down
nginx      2445   2353  0 16:31 ?        00:00:00 nginx: worker process
nginx      2446   2353  0 16:31 ?        00:00:00 nginx: worker process
nginx      2447   2353  0 16:31 ?        00:00:00 nginx: worker process
nginx      2448   2353  0 16:31 ?        00:00:00 nginx: worker process
root       2459   2168  0 16:32 pts/0    00:00:00 grep --color=auto nginx

反向代理

  1. 编辑 /etc/nginx/conf.d/default.conf文件

    server {
        listen       80;
        server_name  localhost;
    	......
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        
     	location /jd {
                proxy_pass https://www.jd.com/;
      	}
    
     	location /bd {
                proxy_pass https://www.baidu.com/;
      	}
    
  2. 重启

    [root@master docker]# nginx -s reload
    
  3. 访问

在这里插入图片描述

集群负载均衡

  1. 先创建三个tomcat(此处使用数据卷+docker创建:便捷)

    [root@master docker]# docker run -it -d --name tomcat-8081 -p 8081:8080 -v /opt/exam/:/usr/local/tomcat/webapps/exam tomcat
    8d609b198c29f5381bc392de021711647f9ff325258fcddbd0a05a41a871b157
    [root@master docker]# docker run -it -d --name tomcat-8082 -p 8082:8080 -v /opt/exam/:/usr/local/tomcat/webapps/exam tomcat
    c49d25b504165ea76c593a52d91104ba34db91b15d834fea9fcac00533b44bf1
    [root@master docker]# docker run -it -d --name tomcat-8083 -p 8083:8080 -v /opt/exam/:/usr/local/tomcat/webapps/exam tomcat
    925714222be6bcd9879fa2f3fe5e37bac25bf37eb831b5c3688b9fef56c2e068
    
  2. 访问服务是否正常

在这里插入图片描述

  1. 编辑/etc/nginx/nginx.conf文件

    	......
        #gzip  on;
        upstream nginxCluster{
            server 127.0.0.1:8081;
            server 127.0.0.1:8082;
            server 127.0.0.1:8083;
    	}
        include /etc/nginx/conf.d/*.conf;
    
  2. 编辑/etc/nginx/conf.d/default.conf文件

        location / {
            #root   /usr/share/nginx/html;
            #index  index.html index.htm;
            proxy_pass http://nginxCluster;  
        }
    
  3. 重启nginx

    [root@master docker]# nginx -s reload
    
  4. 访问服务

在这里插入图片描述

  1. 因为服务使用数据卷,导致看不出差异,下面在容器的内部直接创建页面,区分服务(在数据卷的外面创建,否则修改的还是数据卷)

    [root@master ~]# docker exec -it tomcat-8081 bash
    root@c49d25b50416:/usr/local/tomcat# cd /usr/local/tomcat/webapps
    root@c49d25b50416:/usr/local/tomcat/webapps# mkdir ts
    root@c49d25b50416:/usr/local/tomcat/webapps# cd ts/
    root@c49d25b50416:/usr/local/tomcat/webapps/ts# echo '8081' >> text.html 
    root@c49d25b50416:/usr/local/tomcat/webapps/ts# cat text.html 
    8081
    root@c49d25b50416:/usr/local/tomcat/webapps/ts# exit
    exit
    ......(相同操作修改另外两个容器)
    
  2. 访问服务

在这里插入图片描述

不出差异,下面在容器的内部直接创建页面,区分服务(在数据卷的外面创建,否则修改的还是数据卷)

```sh
[root@master ~]# docker exec -it tomcat-8081 bash
root@c49d25b50416:/usr/local/tomcat# cd /usr/local/tomcat/webapps
root@c49d25b50416:/usr/local/tomcat/webapps# mkdir ts
root@c49d25b50416:/usr/local/tomcat/webapps# cd ts/
root@c49d25b50416:/usr/local/tomcat/webapps/ts# echo '8081' >> text.html 
root@c49d25b50416:/usr/local/tomcat/webapps/ts# cat text.html 
8081
root@c49d25b50416:/usr/local/tomcat/webapps/ts# exit
exit
......(相同操作修改另外两个容器)
```
  1. 访问服务

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值