myserver

notebook
**********************************************************
1.环境为centos7.4 中文 安装jdk
安装目录约定为/opt
/opt/jdk8/jdk1.8.0_152/bin/java
2.安装nginx   80   已设置开机启动
http://nginx.org/download/nginx-1.13.9.tar.gz




安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。


一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:


yum install gcc-c++
二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:


yum install -y pcre pcre-devel
三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。


yum install -y zlib zlib-devel
四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。


yum install -y openssl openssl-devel
官网下载
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html


nginx.png


2.使用wget命令下载(推荐)。


wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
nginx-wget.png


我下载的是1.10.1版本,这个是目前的稳定版。


解压
依然是直接命令:


tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置


./configure
2.自定义配置(不推荐)


./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录


编译安装
make
make install
查找安装路径:


whereis nginx
nginx-whereis.png


启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。


查询nginx进程:


ps aux|grep nginx
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:


./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload


启动成功后,在浏览器可以看到这样的页面:


nginx-welcome.png


开机自启动
即在rc.local增加启动代码就可以了。


vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:


chmod 755 rc.local
nginx-rclocal.png


到这里,nginx就安装完毕了,启动、停止、重启操作也都完成了,当然,你也可以添加为系统服务,我这里就不在演示了。




Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library


  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"






3.安装tomcat  8080
/usr/jdk8/jdk1.8.0_152/bin/java
已设置开机启动


[Unit]
Description=tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
   
[Service]
Type=forking
Environment='JAVA_HOME=/usr/jdk8/jdk1.8.0_152'
Environment='CATALINA_PID=/usr/tomcat/apache-tomcat-8.5.24/bin/tomcat.pid'
Environment='CATALINA_HOME=/usr/tomcat/apache-tomcat-8.5.24/'
Environment='CATALINA_BASE=/usr/tomcat/apache-tomcat-8.5.24/'
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'


WorkingDirectory=/usr/tomcat/apache-tomcat-8.5.24


ExecStart=/usr/tomcat/apache-tomcat-8.5.24/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
   
[Install]
WantedBy=multi-user.target


C,设置为开启机启动:systemctl enable tomcat7






4,启停服务


A,启动服务:systemctl start tomcat7


B,停止服务:systemctl stop tomcat7


C,重启服务:systemctl restart tomcat7






检查状态:systemctl status tomcat7








4.安装Apache httpd server   9880  yum安装的 加入systemctl服务了
已设置开机启动


/opt/tomcat/apache-tomcat-8.5.24








*******************************************************************************************************************




用yum快速搭建LAMP平台
 
实验环境:
[root@nmserver-7 html]# cat  /etc/redhat-release 
CentOS release 7.3.1611 (AltArch) 
[root@nmserver-7 html]# uname -a
Linux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux
1、安装apache
  1.1 安装apache
[root@nmserver-7 ~]# yum install httpd httpd-devel
  1.2 启动apache服务
[root@nmserver-7 ~]# systemctl start  httpd
  1.3 设置httpd服务开机启动
[root@nmserver-7 ~]# systemctl enable  httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  1.4 查看服务状态
复制代码
[root@nmserver-7 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2017-07-21 17:21:37 CST; 6min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2449 (httpd)
   Status: "Total requests: 11; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2449 /usr/sbin/httpd -DFOREGROUND
           ├─2450 /usr/sbin/httpd -DFOREGROUND
           ├─2451 /usr/sbin/httpd -DFOREGROUND
           ├─2452 /usr/sbin/httpd -DFOREGROUND
           ├─2453 /usr/sbin/httpd -DFOREGROUND
           ├─2454 /usr/sbin/httpd -DFOREGROUND
           ├─2493 /usr/sbin/httpd -DFOREGROUND
           ├─2494 /usr/sbin/httpd -DFOREGROUND
           └─2495 /usr/sbin/httpd -DFOREGROUND


7月 21 17:21:35 nmserver-7.test.com systemd[1]: Starting The Apache HTTP Server...
7月 21 17:21:36 nmserver-7.test.com httpd[2449]: AH00558: httpd: Could not reliably determine the server's fully q...ssage
7月 21 17:21:37 nmserver-7.test.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
复制代码
  1.5 防火墙设置开启80端口
[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=http
success
[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=https
success
[root@nmserver-7 ~]# firewall-cmd --reload
success
  1.6确认80端口监听中
复制代码
[root@nmserver-7 ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN      1486/master         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN      1486/master         
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd   
复制代码
  1.8 查服务器IP
复制代码
[root@nmserver-7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.9/24 brd 192.168.8.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe56:bccf/64 scope link 
       valid_lft forever preferred_lft forever
3: bridge0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff
复制代码
  1.9 浏览器登陆




 


2、安装mysql
  2.1安装mysql
[root@nmserver-7 ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel
 


root@nmserver-7 ~]# rpm -qa |grep maria
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686
 


  2.2 开启mysql服务,并设置开机启动,检查mysql状态
复制代码
[root@nmserver-7 ~]# systemctl start  mariadb 
[root@nmserver-7 ~]# systemctl enable  mariadb 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nmserver-7 ~]# systemctl status  mariadb 
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2017-07-22 21:19:20 CST; 21s ago
 Main PID: 9603 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─9603 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─9760 /usr/libexec/mysqld --basedir=/usr --datadir=/v...


7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: ...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21...
7月 22 21:19:20 nmserver-7.test.com systemd[1]: Started MariaDB ...
复制代码
 


复制代码
[root@nmserver-7 ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN      1084/sshd           
tcp        0      0 0.0.0.0:mysql           0.0.0.0:*               LISTEN      9760/mysqld         
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1084/sshd           
tcp6       0      0 [::]:http               [::]:*                  LISTEN      2449/httpd          
udp        0      0 localhost:323           0.0.0.0:*                           592/chronyd         
udp6       0      0 localhost:323           [::]:*                              592/chronyd 
复制代码
  2.3 数据库安全设置
复制代码
[root@nmserver-7 ~]# mysql_secure_installation 


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.


Enter current password for root (enter for none): 
OK, successfully used password, moving on...


Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.


Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!




By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.


Remove anonymous users? [Y/n] y
 ... Success!


Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] n
 ... skipping.


By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.


Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!


Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.


Reload privilege tables now? [Y/n] y
 ... Success!


Cleaning up...


All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.


Thanks for using MariaDB!
复制代码
 


  2.4 登陆数据库测试
复制代码
[root@nmserver-7 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.52-MariaDB MariaDB Server


Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)


MariaDB [(none)]> 
复制代码
 


3、安装PHP
  3.1 安装php
[root@nmserver-7 ~]# yum -y install php
[root@nmserver-7 ~]# rpm -ql php
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session
 


  3.2 将php与mysql关联起来
复制代码
[root@nmserver-7 ~]# yum install php-mysql
[root@nmserver-7 ~]# rpm -ql php-mysql
/etc/php.d/mysql.ini
/etc/php.d/mysqli.ini
/etc/php.d/pdo_mysql.ini
/usr/lib/php/modules/mysql.so
/usr/lib/php/modules/mysqli.so
/usr/lib/php/modules/pdo_mysql.so
复制代码
 


  3.3 安装常用PHP模块
[root@nmserver-7 ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
 


  3.4 测试PHP
复制代码
[root@nmserver-7 ~]# cd  /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php


<?php
        phpinfo();
?>
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                            
:wq
复制代码
 


  3.5重启apache服务器
[root@nmserver-7 html]# systemctl restart http
  3.6测试PHP

  在自己电脑浏览器输入 192.168.8.9/info.php,你可以看到已经安装的模块;

VMware 2017 v14.x 永久许可证激活密钥
FF31K-AHZD1-H8ETZ-8WWEZ-WUUVA
CV7T2-6WY5Q-48EWP-ZXY7X-QGUWD


***************************************************************************************************


192.168.1.28
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"








***************************************************************************************************




[root@192-168-1-28 system]# systemctl list-unit-files | grep "httpd.service"
httpd.service                                 enabled 
[root@192-168-1-28 system]# systemctl disable httpd.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@192-168-1-28 system]# systemctl list-unit-files | grep "httpd.service"
httpd.service                                 disabled
[root@192-168-1-28 system]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@192-168-1-28 system]# systemctl list-unit-files | grep "httpd.service"
httpd.service                                 enabled 
[root@192-168-1-28 system]# 






***************************************************************************************************


打开  /etc/httpd/conf/httpd.conf  文件
 
修改两个地方
    #Listen 12.34.56.78:80
    Listen 80
    #把80改为你设置的端口,我设置端口为5555
    Listen 5555
 
    NameVirtualHost *:80
    #把80改为你设置的端口,我设置端口为5555
    NameVirtualHost *:5555
保存修改,退出。
 
    semanage port -a -t http_port_t -p tcp 5555       #输入这个命令 要不httpd 会启动失败。
    /etc/rc.d/init.d/httpd start        #启动httpd






***************************************************************************************************




CentOS7使用firewalld打开关闭防火墙与端口
1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed


3.配置firewalld-cmd


查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息:  firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent






***************************************************************************************************

















 

猜你喜欢

转载自blog.csdn.net/f522011649/article/details/80550921