In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to build a server in CentOS7+node.js+nginx+MySQL". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Tools
Install git
Execute:
Sudo yum install git
Install nodejs
View the latest version
download
First go to the / usr/src folder, which is usually used to store the software source code:
Cd / usr/local/src/wget https://nodejs.org/dist/v4.6.0/node-v4.6.0.tar.gz
The version replaces itself.
Decompression
Tar zxvf node-v4.6.0.tar.gz
Compilation and installation
Cd node-v4.6.0/./configure / / execute the script that comes with the node.js installation package and modify the relevant system configuration files
If an error is found, it is prompted that the c compiler is not installed in the system, then install the c compiler first.
Install gcc
Yum install gcc
Install glossy +
Yum install gcc-c++
Install gfortran
Yum install gcc-gfortran
Re-execute:
Cd node-v4.6.0/./configure / / execute the script that comes with the node.js installation package, modify the relevant system configuration file make / / and compile the c source code into an executable linux program
It's so slow. Is it the reason why I bought the minimum configuration?
Finally finished the run, the whole journey takes about ten minutes, so everyone should wait patiently.
Sudo make install / / installation file node-version / / View the version of installation node npm-v / / View the version of npm
Now that node.js is installed, you are ready to deploy the application. First install express middleware and forever (a very useful module to ensure that the application starts and restart when needed) using node.js 's module manager npm, where the g parameter is to install express to the nodejs's lib directory, and the d parameter means to install the dependent module package at the same time:
Npm install-gd express-generator forever
Establish a test project and execute it
Execute under the / home folder:
Express testappcd testappnpm installnpm start
Above, the first command is to create a common express framework project, the third command is to install the dependency package, and the fourth command is to execute.
Execute:
Cat package.json [object Object]
The fourth command is equivalent to executing node. / bin/www.
So it works.
But when we close the terminal, the process will end, and now the newly installed forever comes in handy. Forever allows the process to continue to run after the terminal shuts down:
Forever start. / bin/www
We can use the following command to view the programs that forever is running:
Forever list
Now we can access our program by typing: public ip +: 3000 in the browser.
If we want to modify port 3000, we can modify the field in the. / bin/www file about listening on port 3000.
Stop running:
Forever stop 0 / / 0 represents the preceding [0], which is the id of the current process
Stop all:
Forever stopall
Second, install nginx
The http request is port 80, but the port below 1024 cannot be used for non-root permissions on linux, and for security reasons, it is best not to log in to the server with root permission, so you cannot listen to port 80 directly with the node.js program. So we need to use nginx as a reverse proxy to node.js, pointing port 80 to the port on which the application listens (such as node.js default port 3000).
Add nginx Warehouse
Yum install epel-release
Download nginx
Yum install nginx
Enable the nginx service
Service nginx start
Add boot boot
Systemctl enable nginx
Modify nginx configuration file
Vim / etc/nginx/nginx.conf / / install using lnpm comments, nginx directory: / usr/local/nginx/
Add:
Server {listen 80; server_name jakexin.top,www.jakexin.top; # bound domain location / {proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header host $http_host; proxy_set_header x-nginx-proxy true; proxy_set_header connection "; proxy_http_version 1.1; proxy_pass http://127.0.0.1:3000; # corresponding nodejs program port} access_log / mnt/log/www/jakexin_access.log; # website access log}
Test whether the configuration file runs correctly
Nginx-t [object Object]
This means the configuration is successful.
Restart nginx
Service nginx restart
Now enter our configured domain name directly into the browser and you can access our project.
Third, install mysql
View available version
Yum list | grep mysql
You cannot use yum-y install mysql mysql-server mysql-devel installation in centos 7, which installs mysql's branch mariadb by default.
Mariadb database management system is a branch of mysql, which is mainly maintained by the open source community and licensed by gpl.
It is fully compatible with mysql, including api and the command line, making it an easy replacement for mysql.
Correct installation method
As we all know, the repo that comes with the linux system does not automatically update the latest version of each software (basically the later stable version), so it is impossible to install the advanced version of mysql through yum. So we need to install the rpm package with the currently available mysql5 series community edition resources.
Rpm-uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpmyum repolist enabled | grep "mysql.-community." / / View the currently available resources
As you can see from the list above, mysql56-community/x86_64 and mysql 5.6community server can be used.
Therefore, we can install the mysql5.6 version directly in yum.
Yum-y install mysql-community-server
Mysql basic configuration
Systemctl enable mysqld / / add to boot systemctl start mysqld / / enable process mysql_secure_installationnote: running all parts of this script is recommended for all mysql servers in production use! Please read each step carefully!in order to log into mysql to secure it, we'll need the currentpassword for the root user. If you've just installed mysql, andyou 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 mysqlroot user without the proper authorisation.set root password? [YSEO] y [set root user password] new password: re-enter new password: password updated fully loaded reloading privilege tables.. ... Success!by default, a mysql installation has an anonymous user, allowing anyoneto log into mysql without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.remove anonymous users? [yAssociation] y [Delete anonymous users]... Properly normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.disallow root login remotely? [YPAPO] y [prohibit root remote login]. Thanks by default, mysql comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.remove test database and access to it? [] y [delete test database]-dropping test database...error 1008 (hy000) at line 1: can't drop database 'test'; database doesn't exist... Failed! Not critical, keep moving... -removing privileges on test database... ... Success!reloading the privilege tables will ensure that all changes made so farwill take effect immediately.reload privilege tables now? [yAssociation] y [refresh permissions]. Success! All done! If you've completed all of the above steps, your mysqlinstallation should now be secure.thanks for using mysql! Cleaning up...
4. Operate mysql
Configure remote connection
Grant all privileges on. To 'root'@'%' identified by' password 'with grant option; / / add authorized user flush privileges; / / refresh the database
Check whether port 3306 is open
Netstat-tunlp [object Object]
After seeing that port 3306 is open, we can use the local client to access the database remotely
This is the end of the content of "how to build a server in CentOS7+node.js+nginx+MySQL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.