Starting from scratch - building a java application deployment environment on Alibaba Cloud Services
Preparation
Download and install FinalShell to facilitate local connection to cloud services and upload files
FinalShell download address: https://www.hostbuf.com/c/131.html
1. jdk installation and deployment
jdk official download: https://www.oracle.com/java/technologies/downloads/
1.1 Uninstall the jdk that comes with the system
Check the jdk that comes with the system: rpm -qa | grep jdk
Uninstall the built-in jdk: rpm -e --nodeps JDK to be uninstalled
1.2 Upload jdk and decompress jdk
Create an installation directory (used to be placed in the /usr/local directory): mkdir java
Upload the directory created by the jdk compressed package
Decompress the jdk compressed package: tar -zxvf jdk compressed package
1.3 Configure jdk environment variables
Edit profile file: vim /etc/profile
Add the following configuration to the last line
JAVA_HOME=/usr/local/java/jdk1.8.0_371
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
Let the configuration file take effect: source /etc/profile
Two, mydql5.7 database installation
Mysql download address: https://downloads.mysql.com/archives/community/
2.1 Uninstall mysql, Mariadb that comes with the system
View the mysql that comes with the system: rpm -qa | grep mysql
Uninstall the built-in mysql: rpm -e --nodeps file name
Query all mysql folders: whereis mysql and find / -name mysql
Delete the relative directory: rm -rf the absolute path of the file
2.2 Create mysql user group and mysql user
Check if the mysql group and user exist: cat /etc/group | grep mysql or cat /etc/passwd | grep mysql
Create a mysql user group: groupadd mysql
Create a user named mysql and join the mysql user group: useradd -g mysql mysql
Modify user password: passwd mysql
2.3 Upload and decompress the mysql compressed package, and authorize the mysql user
Decompression: tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
授权:chown mysql.mysql /usr/local/mysql -R
2.4 Add the my.cnf configuration file in the /etc directory
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/local/mysql/mysql-5.7.31
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysql-5.7.31/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
2.5 Installation and initialization
初始化mysql:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.31/mysql/ --datadir=/usr/local/mysql/mysql-5.7.31/data/
如果出现./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
You need to install libaio.so.1: yum install libaio
Copy the file: cp ./support-files/mysql.server /etc/init.d/mysqld
Authorization:
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysqld
Restart the mysql service: /etc/init.d/mysqld restart
Soft connection (login to mysql in any directory): ln -s /usr/local/mysql/mysql-5.7.31/bin/mysql /usr/bin/mysql
2.6 Set the startup
chkconfig --level 35 mysqld on
chkconfig --list mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld status
2.7 Configure environment variables
JAVA_HOME=/usr/local/java/jdk1.8.0_11
MYSQL_HOME=/usr/local/mysql/mysql-5.7.31
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin:$MYSQL_HOME/bin
export PATH JAVA_HOME CLASSPATH
2.8 Login data
Get the initialization password: **cat /root/.mysql_secret**
Log in to the database: mysql -uroot -p
Reset password: set PASSWORD = PASSWORD('root777');
Flush privileges: flush privileges;
Replace the database: use mysql;
View the database user address: select host,user from user;
Modify root user access rights: update user set host='%' where user='root';
2.9 Create a new user
Delete user: **DROP USER 'goryleee'@'%'; **
Create a user: CREATE USER 'username'@'host' IDENTIFIED BY 'password';
Authorization: GRANT ALL ON . TO 'pig'@'%'; or GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
Revoke user privileges: REVOKE privilege ON databasename.tablename FROM 'username'@'host';
Modify user password: SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
View user permissions: **SHOW GRANTS FOR 'pig'@'%'; **
3. Redis installation
Download address: http://download.redis.io/releases
3.1 Upload and decompress redis
tar -zvxf redis-6.2.5.tar.gz
3.2 Compile and install (enter the redis root directory)
Execute: make
Enter src, execute: make install
Start the service: ./redis-server …/redis.conf
3.3 Set background execution and modify password
Modify the configuration file: vim redis.conf
// 注释监听ip,不然本地无法连接redis
#bind 127.0.0.1
// 修改保护模式,不修改保护模式也是只能内网访问的 protected-mode yes 改成 protected-mode no
protected-mode no
// 设置密码,这里建议设置密码,否则可能会发生一些预料不到的事情,因为6379端口有漏洞
requirepass "你的密码"
// daemonize no 改为yes 后台一直运行
daemonize yes
3.4 Add redis to the systemctl service, and set it to start automatically
Create a new redis.service under /etc/systemd/system
Where /usr/local/redis/redis-6.2.5 is the path where you installed redis
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/redis-6.2.5/src/redis-server /usr/local/redis/redis-6.2.5/redis.conf
ExecReload=/usr/local/redis/redis-6.2.5/src/redis-server -s reload
ExecStop=/usr/local/redis/redis-6.2.5/src/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Reload the service configuration file: systemctl daemon-reload
Start redis: systemctl start redis
View redis service status: service redis status
Set boot startup: systemctl enable redis.service
systemctl disable redis.service # 取消开机自启
systemctl start redis.service # 启动redis服务
systemctl stop redis.service # 停止服务
systemctl restart redis.service # 重新启动服务
systemctl status redis.service # 查看服务当前状态
systemctl list-units --type=service # 查看所有已启动的服务
systemctl daemon-reload # 加载服务配置文件
Four, nginx installation
Download address: https://nginx.org/en/download.html
4.1 Prepare the make environment
执行:yum -y install gcc gcc-c++ automake autoconf libtool make
4.2 Prepare the nginx environment
Install pcre: yum -y install pcre pcre-devel
安装zlib:yum -y install zlib zlib-devel
安装openssl :yum -y install openssl openssl-devel
4.3 Upload and decompress nginx
Decompression: tar -zvxf nginx-1.20.2.tar.gz
Enter the nginx root directory: cd /usr/local/nginx/nginx-1.20.2
Execute: **./configure**
compile: make
Installation: **make install**
4.4 start nginx
Execute: cd /usr/local/nginx/sbin
Start the nginx service: **./nginx**
Close nginx service: ./nginx -s stop
Restart the nginx service: ./nginx -s reload
Detection configuration file: nginx -t -c ~/youSite.conf
4.5 Set nginx to start automatically at boot – preparations
Copy nginx.conf, mime.types files to /etc/nginx/: cd /usr/local/nginx/conf/
Execute: cp nginx.conf /etc/nginx/ ** cp mime.types /etc/nginx/ **
Create init.d control command, vi /etc/init.d/nginx , the content is as follows
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $prog -HUP
retval=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
Note: the following two need to be modified
nginx="/usr/local/nginx/sbin/nginx" #修改成nginx执行程序的路径。
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" #修改成nginx.conf文件的路径。
Set permissions: chmod a+x /etc/init.d/nginx
After setting, you can execute the following command
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
4.6 Set nginx to start automatically
Add to
service
, use service to control nginx: chkconfig --add /etc/init.d/nginxTo set boot up automatically, execute: chkconfig nginx on