#本操作是在root用户下操作的;按照一行一行执行就好了
yum -y install wget
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' >/etc/timezone
#安装jdk
cd /usr/local
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
tar -xvf jdk-8u131-linux-x64.tar.gz
rm -rf /usr/local/jdk-8u131-linux-x64.tar.gz*
mv jdk1.8.0_131 jdk
echo "export JAVA_HOME=/usr/local/jdk" >> ~/.bashrc
echo "export JRE_HOME=\${JAVA_HOME}/jre" >> ~/.bashrc
echo "export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib:\$CLASSPATH" >> ~/.bashrc
echo "export JAVA_PATH=\${JAVA_HOME}/bin:\${JRE_HOME}/bin" >> ~/.bashrc
echo "export PATH=\$PATH:\${JAVA_PATH}" >> ~/.bashrc
source ~/.bashrc
echo "export JAVA_HOME=/usr/local/jdk" >> /etc/profile
echo "export JRE_HOME=\${JAVA_HOME}/jre" >> /etc/profile
echo "export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib:\$CLASSPATH" >> /etc/profile
echo "export JAVA_PATH=\${JAVA_HOME}/bin:\${JRE_HOME}/bin" >> /etc/profile
echo "export PATH=\$PATH:\${JAVA_PATH}" >> /etc/profile
source /etc/profile
#安装nginx
yum -y install gcc automake autoconf libtool make
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
cd /usr/local
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
cd nginx-1.13.7
./configure
make
make install PREFIX=/usr/local/nginx-1.13.7
cd /usr/local/nginx
rm -rf ./nginx-1.13.7*
touch /usr/lib/systemd/system/nginx.service
chmod 755 /usr/lib/systemd/system/nginx.service
echo "[Unit]" >> /usr/lib/systemd/system/nginx.service
echo "After=network.target remote-fs.target nss-lookup.target" >> /usr/lib/systemd/system/nginx.service
echo "[Service]" >> /usr/lib/systemd/system/nginx.service
echo "Type=forking" >> /usr/lib/systemd/system/nginx.service
echo "ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /usr/lib/systemd/system/nginx.service
echo "[Install]" >> /usr/lib/systemd/system/nginx.service
echo "WantedBy=multi-user.target" >> /usr/lib/systemd/system/nginx.service
chmod 644 /usr/lib/systemd/system/nginx.service
systemctl enable nginx.service
systemctl start nginx.service
#安装mysql
#默认自带MariaDB,先删除掉
rpm -qa|grep mariadb
yum -y remove mariadb
yum -y remove mariadb-libs
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/
yum -y install libaio
yum -y install numactl
cd /usr/local
wget https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
rm -rf /usr/local/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz*
mv mysql-5.7.35-linux-glibc2.12-x86_64 mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
echo "export MYSQL_HOME=/usr/local/mysql" >> ~/.bashrc
echo "export MYSQL_PATH=\${MYSQL_HOME}/bin" >> ~/.bashrc
echo "export PATH=\$PATH:\${MYSQL_PATH}" >> ~/.bashrc
source ~/.bashrc
echo "export MYSQL_HOME=/usr/local/mysql" >> /etc/profile
echo "export MYSQL_PATH=\${MYSQL_HOME}/bin" >> /etc/profile
echo "export PATH=\$PATH:\${MYSQL_PATH}" >> /etc/profile
source /etc/profile
touch /usr/local/mysql/my-default.ini
chmod 755 /usr/local/mysql/my-default.ini
echo "[mysqld]" >> /usr/local/mysql/my-default.ini
echo "basedir = /usr/local/mysql" >> /usr/local/mysql/my-default.ini
echo "datadir = /usr/local/mysql/data" >> /usr/local/mysql/my-default.ini
echo "bind-address = 0.0.0.0" >> /usr/local/mysql/my-default.ini
/usr/local/mysql/bin/mysqld --initialize
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
touch /usr/lib/systemd/system/mysql.service
chmod 755 /usr/lib/systemd/system/mysql.service
echo "[Unit]" >> /usr/lib/systemd/system/mysql.service
echo "After=network.target remote-fs.target nss-lookup.target" >> /usr/lib/systemd/system/mysql.service
echo "[Service]" >> /usr/lib/systemd/system/mysql.service
echo "Type=forking" >> /usr/lib/systemd/system/mysql.service
echo "ExecStart=/usr/local/mysql/support-files/mysql.server start" >> /usr/lib/systemd/system/mysql.service
echo "[Install]" >> /usr/lib/systemd/system/mysql.service
echo "WantedBy=multi-user.target" >> /usr/lib/systemd/system/mysql.service
chmod 644 /usr/lib/systemd/system/mysql.service
systemctl enable mysql.service
#新建设置root密码为123456,允许远程连接的脚本,启动进入容器后可执行/usr/local/mysql/UpdateRootPassword.sh
touch /usr/local/mysql/UpdateRootPassword.sh
chmod 755 /usr/local/mysql/UpdateRootPassword.sh
echo "#UpdateRootPassword.sh" >> /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \#!/bin/bash' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \DB_Root_Password="123456"' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \echo "Stoping mysql..."' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \/usr/local/mysql/support-files/mysql.server stop' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \sleep 5' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \echo "Starting mysql with skip grant tables"' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \/usr/local/mysql/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \sleep 5' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \echo "update mysql root password...start..."' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \/usr/local/mysql/bin/mysql -u'\''root'\'' << EOF' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \use mysql;' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \update user set authentication_string=password('\''\${DB_Root_Password}'\'') where user='\''root'\'';' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \flush privileges;' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \EOF' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \sleep 5' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \ps aux|grep mysqld|awk '\''{print \$2}'\''|xargs kill -9' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \sleep 5' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \/usr/local/mysql/support-files/mysql.server start' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \sleep 5' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \/usr/local/mysql/bin/mysql -u'\''root'\'' -p\${DB_Root_Password} --connect-expired-password << EOF' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \set password for '\''root'\''@'\''localhost'\'' = '\''\${DB_Root_Password}'\'';' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \grant all privileges on *.* to '\''root'\''@'\''%'\'' identified by '\''\${DB_Root_Password}'\'' with grant option;' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \flush privileges;' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \EOF' /usr/local/mysql/UpdateRootPassword.sh
sed -i '$a \echo "update \mysql root password...end..."' /usr/local/mysql/UpdateRootPassword.sh
sed -i '1d' /usr/local/mysql/UpdateRootPassword.sh
/usr/local/mysql/UpdateRootPassword.sh
ps aux|grep mysql|awk '{print $2}'|xargs kill -9
systemctl start mysql.service
#安装redis
yum -y install gcc automake autoconf libtool make
cd /usr/local
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
tar -xvf redis-4.0.8.tar.gz
rm -rf /usr/local/redis-4.0.8.tar.gz*
mv redis-4.0.8 redis
cd /usr/local/redis
make
make install PREFIX=/usr/local/redis
sed -i "s/daemonize no/daemonize yes/g" /usr/local/redis/redis.conf
sed -i "s/# requirepass foobared/requirepass 123456/g" /usr/local/redis/redis.conf
sed -i "s/protected-mode yes/protected-mode no/g" /usr/local/redis/redis.conf
sed -i "s/bind 127.0.0.1/#bind 127.0.0.1/g" /usr/local/redis/redis.conf
sed -i 's/dir .\//dir \/usr\/local\/redis\/data/g' /usr/local/redis/redis.conf
sed -i "s/appendonly no/appendonly yes/g" /usr/local/redis/redis.conf
mkdir /usr/local/redis/data
chmod -R 755 /usr/local/redis
touch /usr/lib/systemd/system/redis.service
chmod 755 /usr/lib/systemd/system/redis.service
echo "[Unit]" >> /usr/lib/systemd/system/redis.service
echo "After=network.target remote-fs.target nss-lookup.target" >> /usr/lib/systemd/system/redis.service
echo "[Service]" >> /usr/lib/systemd/system/redis.service
echo "Type=forking" >> /usr/lib/systemd/system/redis.service
echo "ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf" >> /usr/lib/systemd/system/redis.service
echo "[Install]" >> /usr/lib/systemd/system/redis.service
echo "WantedBy=multi-user.target" >> /usr/lib/systemd/system/redis.service
chmod 644 /usr/lib/systemd/system/redis.service
systemctl enable redis.service
systemctl start redis.service
#开放端口
firewall-cmd --list-all
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --reload
centos7.x安装jdk,nginx,mysql,redis
最新推荐文章于 2023-04-02 22:32:44 发布