One, deploy jdk environment
1. Check whether the system comes with JDK
java -version
2. View related java files
rpm -qa | grep java
3. Switch root permissions
su root
4. Delete java related files
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
5. Download JDK
Download link http://www.oracle.com/technetwork/java/javase/downloads/index.html
6. Unzip and install JDK
tar -zxvf jdk-8u271-linux-x64.tar.gz
7. Configure JDK environment variables
Type the command vim /etc/profile to modify the configuration file, remember to modify it under root authority
Enter i to enter the editing state, and then move the cursor to the last line, paste the following content, JAVA_HOME=/usr/jdk1.8.0_211 should be set according to your own decompression directory
#java environment
export JAVA_HOME=/usr/local/jdk1.8.0_171
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
The effect is as follows
Click esc to enter the command mode and enter: wq! Save the modified information
Then type the command source /etc/profile to make the configuration file effective
8. Test the installation effect
Enter the command java -version to get the following result indicating that the installation was successful
Two, deploy tomcat
1. Download the Tomcat8 compressed package
Enter http://tomcat.apache.org/download-80.cgi
Switch to cd /usr/local/ to create the tomcat directory mkdir tomcat
View the firewall command: firewall-cmd --state or systemctl status firewallld
Turn on the firewall: systemctl start firewalld
Turn off the firewall: systemctl stop firewalld
Restart the firewall: firewall-cmd --reload
2. Unzip tomcat
tar -zxvf apache-tomcat-8.0.53.tar.gz
Rename the file to tomcat
mv apache-tomcat-8.0.50 tomcat8
3. Modify environment variables
Add the following configuration at the end of vim /etc/profile
CATALINA_BASE=/usr/local/tomcat/apache-tomcat-8.5.24 PATH=$PATH:$CATALINA_BASE/bin
#export 使上述配置⽣效
export CATALINA_BASE PATH
Reload the environment variable
source /etc/profile
4. Configure the firewall and open port 8080
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
5. Start tomcat
cd to the bin directory of tomcat8
cd /usr/local/java/tomcat8/bin
Startup and Shutdown Tomcat
./startup.sh start
./shutdown.sh Close
Three, deploy Mysql5.7
1. Download and install the official Yum Repository of MySQL
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Use the above command to directly download the Yum Repository for installation, which is about 25KB, and then you can directly install it with Yum.
yum -y install mysql57-community-release-el7-10.noarch.rpm
After that, install the MySQL server.
yum -y install mysql-community-server
2. MySQL database settings
First start MySQL
systemctl start mysqld.service
Check the running status of MySQL, as shown in the figure:
systemctl status mysqld.service
At this time MySQL has started to run normally, but if you want to enter MySQL, you must first find out the password of the root user at this time. You can find the password in the log file by using the following command:
grep "password" /var/log/mysqld.log
Enter the database with the following command:
mysql -uroot -p
Enter the initial password (no;e!5>>alfg at the end of the picture above), you can't do anything at this time, because MySQL must modify the password before operating the database by default:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Among them, replace'new password' with the password you want to set. Note: The password setting must be uppercase and lowercase alphanumeric and special symbols (,/';: etc.), otherwise the configuration cannot be successful
If you want to change to a weak password like root, you need to configure the following:
View password policy
show variables like '%password%';
Modify password policy
vi /etc/my.cnf
add validate_password_policy configuration
Choose one of 0 (LOW), 1 (MEDIUM), 2 (STRONG), choose 2 to provide a password dictionary file
#添加validate_password_policy配置
validate_password_policy=0
#关闭密码策略
validate_password = off
Restart the mysql service for the configuration to take effect
systemctl restart mysqld
Then you can change it to a weak password
3 Turn on remote access to mysql
Execute the following command to enable remote access restriction (note: the IP enabled by the following command is 192.168.0.1, if you want to enable all, use% instead of IP):
grant all privileges on *.* to 'root'@'172.15.2.42' identified by 'password' with grant option;
Then enter the following two lines of commands
flush privileges;
exit;
4 Add an open port for firewalld
Add mysql port 3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
Then reload
firewall-cmd --reload
5 Modify the character encoding of mysql (not modifying it will cause Chinese garbled problems)
Display the original code:
show variables like '%character%';
Modify /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
Restart the database
Fourth, deploy nginx
1. gcc installation
To install nginx, you need to compile the source code downloaded from the official website. The compilation depends on the gcc environment. If there is no gcc environment, you need to install:
yum install gcc-c++
2. PCRE pcre-devel installation
PCRE (Perl Compatible Regular Expressions) is a Perl library, including Perl compatible regular expression libraries. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux. pcre-devel is a secondary development library developed using pcre. Nginx also needs this library. command:
yum install -y pcre pcre-devel
3. zlib installation
The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the content of the http package, so you need to install the zlib library on Centos.
yum install -y zlib zlib-devel
4. OpenSSL installation
OpenSSL is a powerful secure socket layer cryptographic library, including main cryptographic algorithms, commonly used key and certificate packaging management functions and SSL protocols, and provides a wealth of applications for testing or other purposes.
Nginx not only supports the http protocol, but also supports https (that is, HTTP is transmitted over the ssl protocol), so you need to install the OpenSSL library in Centos.
yum install -y openssl openssl-devel
Official website download
1. Download the .tar.gz
installation package directly , address: https://nginx.org/en/download.html
2. Use wget
command to download (recommended). Make sure that wget has been installed on the system. If it is not installed, execute yum install wget to install it.
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
I downloaded version 1.12.0, which is the current stable version.
Unzip
Still a direct command:
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
Configuration
In fact, in the nginx-1.12.0 version, you don't need to configure related things, the default is fine. Of course, if you want to configure the directory yourself, it is also possible.
1. Use the default configuration
./configure
2. Custom configuration (not recommended)
./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
Note: Specify the temporary file directory as /var/temp/nginx, you need to create temp and nginx directories under /var
Compile and install
make
make install
Find the installation path:
whereis nginx
Start and stop nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
启动时报80端口被占用:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
解决办法:1、安装net-tool 包:
yum install net-tools
./nginx -s quit
: The stop step in this way is to stop when the nginx process finishes processing tasks.
./nginx -s stop
: This method is equivalent to first finding out the nginx process id and then using the kill command to forcefully kill the process.
Query the nginx process:
ps aux|grep nginx
Restart nginx
1. Stop and then start (recommended):
Restarting nginx is equivalent to stopping and then starting, that is, execute the stop command first and then execute the start command. as follows:
./nginx -s quit
./nginx
2. reload the configuration file:
After modifying the configuration file nginx.conf ngin x, to want a profile take effect need to restart nginx, use -s reload
without first stopping ngin x nginx restart to take effect in nginx configuration information as follows:
. /nginx -s reload
After successful startup, you can see this page in the browser:
Auto start at boot
That is, just rc.local
add the startup code.
vi /etc/rc.local
Add a line /usr/local/nginx/sbin/nginx
to set execute permissions:
chmod 755 rc.local
At this point, nginx is installed, and the start, stop, and restart operations are also completed. Of course, you can also add it as a system service