1. 需要有阿里云服务器
2. 使用 XShell 连接阿里云服务器
3. 登录阿里云服务器
ssh root@服务器公网 IP
4. 配置源配置
- 备份:mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 配置 Centos6: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
- 生成缓存:yum makecache
5. 新建一个带有 sudo 权限的用户,这样就可以不用 root 进行连接了
- useradd -d /usr/yyh -m yyh (为用户创建主目录)
- cd /usr/yyh/ (进入 yyh 用户的目录)
- passwd yyh (重置用户的密码,不会显示你输入的密码)
- sudo vim /etc/sudoers (编辑这个文件,来给用户创建 sudo 权限)
- /root (输完按回车,可以高亮显示 root) 找到
- :noh(取消高亮)
按一下 i 键进行插入(yyh ALL=(ALL) ALL)
- 编写完,按下 ESC, 输入 :wq! 强制保存
- exit (退出 root 登录的用户)
- ssh yyh@服务器公网 IP (使用创建的用户重新连接服务器)
6. 安装 jdk 1.8
- rpm -qa | grep jdk (查看 centos 是否安装了 jdk)
- sudo yum remove jdk-1.8-1.8.0_190-fcs.x86_64 (如果有就删除,没有就不用执行这条)
- cd / (进入根目录)
- sudo mkdir developer (创建一个文件夹)
- cd developer/ (进入 developer 文件夹)
- sudo mkdir setup (创建一个文件夹)
- cd setup/ (进入 setup 文件夹)
- 从官网下载 jdk ,首先要先获取链接
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
然后就可以回到 XShell 继续配置了- sudo wget https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm?AuthParam=1540776915_5aeaf93ae2b4fdb68fb4d055efc5aa2c (后面这个地址每个人都是不一样的,不能直接复制)
- sudo mv jdk-8u191-linux-x64.rpm?AuthParam=1540776915_5aeaf93ae2b4fdb68fb4d055efc5aa2c jdk-8u191-linux-x64.rpm (因为下载好的 jdk 名字是有带参数的,所以需要重命名)
- sudo chmod 777 jdk-8u191-linux-x64.rpm (给所有用户赋予读写权限)
- sudo rpm -ivh jdk-8u191-linux-x64.rpm (安装 jdk)
- cd /usr/java/ (进入 java 安装的目录)
- sudo vim /etc/profile (进入 profile 文件配置环境变量)
来到最下面进行编辑,添加以下内容:
export JAVA_HOME=/usr/java/jdk1.8.0.191
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export MAVEN_HOME=/developer/apache-maven-3.5.4
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/bin
- source /etc/profile (使配置生效)
- java -version (查看版本信息, 查看到 jdk 版本信息就安装成功了)
7. 安装 Tomcat 8.0
- cd /developer/ (进入 developer 文件夹)
- sudo wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz (下载 tomcat 8)
- sudo tar -zxvf apache-tomcat-8.0.53.tar.gz (解压 tomcat)
- sudo mv apache-tomcat-8.0.53.tar.gz setup/ (将压缩包移到 setup 文件夹中)
- sudo vim conf/server.xml (编辑 server.xml)
- /8080 (找到 <Connector port=“8080” … />)
- 按 i 插入(在 redirectPort=“8443” 后插入 URIEncoding=“UTF-8” , 修改字符集)
- 按 esc, 输入 :wq 保存并退出。
- cd bin (进入 tomcat 的 bin 目录)
- sudo vim /etc/profile (配置环境变量)
export CATALINA_HOME=/developer/apache-tomcat-8.0.53
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:/usr/local/bin
- source /etc/profile (使配置生效)
- sudo ./startup.sh (启动 tomcat)
- 使用浏览器测试:
8. 安装 maven 3.5.4
- sudo wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz (下载 maven 3.5.4)
- sudo tar -zxvf apache-maven-3.5.4-bin.tar.gz (解压 maven)
- sudo mv apache-maven-3.5.4-bin-tar.gz setup/ (将压缩包移到 setup 文件夹)
- sudo vim /etc/profile (配置环境变量)
export MAVEN_HOME=/developer/apache-maven-3.5.4
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$MAVEN_HOME/bin:/usr/local/bin
- source /etc/profile (使配置生效)
- mvn -version (检查 maven 版本,有信息,则安装成功)
9. 安装 vsftpd
- sudo yum -y install vsftpd (自动安装 vsftpd)
- cd / (进入根目录)
- sudo mkdir product (创建一个目录)
- cd product/ (进入 product 文件夹)
- sudo mkdir ftpfile (创建一个目录)
- cd ftpfile/ (进入 ftpfile 文件夹)
- sudo useradd ftpuser -d /product/ftpfile -s /sbin/nologin (添加一个匿名用户)
- sudo chown -R ftpuser.ftpuser ./ftpfile/ (赋予权限)
- sudo passwd ftpuser (重置 ftpuser 的消息)
- cd /etc/vsftpd/ (进入 vsftpd 文件夹)
- sudo vim chroot_list (编辑 chroot_list)
- 按 i 插入,在第一行添加 ftpuser,按 esc 退出,并 :wq 保存并退出。
- sudo vim /ets/selinux/config (查看 SELINUX 是否为 disabled, 如果不是则改为 disabled, 如果是则 :q 退出。
- sudo setsebool -P ftp_home_dir 1 (避免 550, 拒绝访问错误)
- sudo mv vsftpd.conf vsftpd.conf.bak (备份)
- sudo vim vsftpd.conf (编辑, 将以下的内容复制进去保存并退出)
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
local_root=/product/ftpfile
#chroot_local_user=YES
anon_root=/product/ftpfile
use_localtime=YES
#匿名
#anonymous_enable=YES
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to mmall FTP Server
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=NO
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
#pasv_enable=YES
pasv_min_port=61001
pasv_max_port=62000
- sudo servcie vsftpd start (启动 vsftpd )
10. 安装 nginx
- cd /developer/ (进入 developer 文件夹)
- cd setup/ (进入 setup 文件夹)
- sudo wget http://nginx.org/download/nginx-1.9.9.tar.gz (下载 nginx )
- sudo yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel (自动安装 nginx 的依赖)
- sudo tar -zxvf linux-nginx-1.9.9.tar.gz (解压 nginx)
- cd nginx-1.9.9 (进入解压好的目录)
- sudo ./configure (执行 configure 命令)
- sudo make
- sudo make install
- whereis nginx (查看 nginx 所在的目录)
- cd /usr/local/nginx/ (进入 nginx 所在的目录)
- cd conf/ (进入 conf 文件夹)
- sudo vim nginx.conf (编辑 nginx.conf)
- 找到 # HTTPS server 节点, 在节点上增加 include vhost/*.conf;, 保存并退出。
- sudo mkdir vhost (创建一个 vhost 文件夹)
- cd vhost/ (进入 vhost 文件夹)
- sudo vim img.yuu.com.conf (编辑一个 img.yuu.com.conf, 将以下内容复制进去)
server {
listen 80;
autoindex off;
server_name img.yuu.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
}
location / {
root /product/ftpfile/img/;
add_header Access-Control-Allow-Origin *;
}
}
- cd … (退出到上级目录)
- cd … (退出到上级目录)
- cd sbin/ (进入 sbin 目录)
- sudo ./nginx (执行 nginx)
- 浏览器访问服务器公网 IP
11. 安装 mysql
- sudo rpm -qa | grep mysql -server (检查是否安装 mysql)
- sudo yum -y install mysql -server (安装 mysql)
- sudo vim /etc/my.cnf (编辑 my.cnf, 修改字符集,在 user=mysql 下添加 character-set-server=utf8 default-character-set=utf8, 保存并退出)
- sudo chkconfig mysqld on (设置自启动)
- sudo chkconfig --list mysqld (查看 2、3、4、5 是 on)
- sudo service mysqld restart (重启 mysqld)
- mysql -u root (登录 mysql)
- select user,host,password from mysql.user; (查看有多少个用户)
- set password for root@localhost = password(‘rootpassword’);(设置 localhost 的密码)
- set password for root@izt24vwnqrkll8z = password(‘rootpassword’); (设置机器名的密码)
- set password for [email protected] = password(‘rootpassword’); (设置 127.0.0.1 的密码)
- exit (退出)
- mysql -u root -p (登录 mysql, 输入密码)
- delete from mysql.user where user=’’; (删除匿名用户)
- flush privileges; (刷新)
- insert into mysql.user(host,user,password) values(“localhost”, “yuumall”, password(“yuumallpassword”)); (插入一个用户)
- create database
yuumall
default character set utf8 COLLATE utf8_general_ci; (新建一个数据库)- show databases; (查看所有数据库)
- flush privileges; (刷新)
- grant all privileges on yuumall.* to yuumall@localhost identified by ‘yuumallpassword’; (赋予权限)
- exit (退出)
- cd /developer/ (进入developer 文件夹)
- sudo wget http://learning.happymmall.com/mmall.sql (下载 sql 文件)
- mysql -u root -p (登录 mysql)
- use yuumall;(使用 yuumall 数据库)
- source /developer/mmall.sql (导入sql 文件)
- select * from mall_user\G;(\G 代表格式化)
12. 安装 git
- sudo wget https://Github.com/Git/Git/archive/v2.11.0.tar.gz (下载 git)
- sudo yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils- MakeMaker (安装 git 依赖)
- sudo tar -zxvf v2.11.0.tar.gz (解压 git)
- cd git-2.11.0 (进入 git 目录)
- sudo make prefix=/usr/local/git all
- sudo make prefix=/usr/local/git install
- sudo vim /etc/profile(编辑文件, 加入以下内容,保存并退出)
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/git/bin:$CATALINA_HOME/bin:$MAVEN_HOME/bin:/usr/local/bin
- source /etc/profile (使配置生效)
- git --version (查看 git 的版本)
- git config --global user.name “yuu” (配置用户名)
- git config --global user.email "[email protected]" (配置邮箱)
- git config --global core.autocrlf false (让 git 不管换行符转换的问题)
- git config --global core.qutepath off (避免中文乱码)
- ssh-keygen -t rsa -C "[email protected]" (配置 ssh-keygen, 一直回车就好)
- ssh-add ~/.ssh/id_rsa (配置 ssh-add,如果出现 Could not open a connection to your authentication agent. 则执行 16 行,否则不用执行。)
eval `ssh-agent` (`是上面那排数字旁边的那个)
,再执行一遍 ssh-add ~/.ssh/id_rsa- cat ~/.ssh/id_rsa.pub (获得公钥)
- 复制生成的公钥添加到码云的 ssh 公钥中
13. 配置防火墙
- cd /etc/sysconfig/ (进入防火墙的目录)
- sudo iptables -P OUTPUT ACCEPT (添加防火墙规则)
- sudo service iptables save (保存)
- sudo vim iptables (编辑 iptables, 删除原有的内容,复制以下内容进去,保存并退出)
# Generated by iptables-save v1.4.7 on Fri Jan 6 16:53:09 2017
#*filter
#:INPUT ACCEPT [174:12442]
#:FORWARD ACCEPT [0:0]
#:OUTPUT ACCEPT [96:10704]
#-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
#-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
#-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
#COMMIT
# Completed on Fri Jan 6 16:53:09 2017
#------------------------------------
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#ssh port
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#vsftpd
-A INPUT -p TCP --dport 61001:62000 -j ACCEPT
-A OUTPUT -p TCP --sport 61001:62000 -j ACCEPT
-A INPUT -p TCP --dport 20 -j ACCEPT
-A OUTPUT -p TCP --sport 20 -j ACCEPT
-A INPUT -p TCP --dport 21 -j ACCEPT
-A OUTPUT -p TCP --sport 21 -j ACCEPT
#mysql port
#-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
#tomcat remote debug port
#-A INPUT -p tcp -m tcp --dport 5005 -j ACCEPT
#-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
#nginx
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
- sudo servcie iptables restart (重启防火墙)