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 > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Make JAVA running environment image
My basic image is based on the official website centos 7.2.It can not be downloaded in advance.
# docker pull docker.io/centos
[root@R210] # mkdir-p / opt/Dockerfile/JRE1.7
[root@R210 ~] # cd / opt/Dockerfile/JRE1.7
[root@R210 jre1.7] # ls
Dockerfile server-jre-7u80-linux-x64.tar.gz
[root@R210 jre1.7] # cat Dockerfile
FROM centos:latest
MAINTAINER yy ENV JAVA_VERSION "7u80" ENV JDK_VERSION "1.7.080" RUN rpm-- rebuilddb\ & & yum-- setopt=tsflags=nodocs-y install\ net-tools\ & & rm-rf / var/cache/yum/* & & yum clean all#RUN rpm-- import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7\ # & & yum update & & yum install net-tools-y\ RUN mkdir-p / usr/lib / jvm COPY server-jre-$ {JAVA_VERSION}-linux-x64.tar.gz / usr/lib/jvm/server-jre-$ {JAVA_VERSION}-linux-x64.tar.gz RUN cd / usr/lib/jvm\ & & tar-zxvf server-jre-$ {JAVA_VERSION}-linux-x64.tar.gz\ & & rm-rf / usr/lib/jvm/server-jre-$ {JAVA_VERSION}-linux-x64.tar.gz\ & & ln- S / usr/lib/jvm/jdk$ {JDK_VERSION} / bin/java / bin/\ & & cd / usr/lib/jvm/jdk$ {JDK_VERSION}\ & & find. -type f-name'* .html'- delete\ & & find. -type f-name 'COPYRIGHT'-delete\ & & find. -type f-name 'LICENSE'-delete\ & & find. -type f-name 'NOTICE'-delete\ & & find. -type f-name '3RDPARTY'-delete\ & & find. -type f-name'* .txt'- delete\ & & find. -type f-name'* .bat'- delete\ # jre package can be streamlined again
two。 Make Tomcat image of production environment
[root@R210] # mkdir-p / opt/Dockerfile/tomcat7
[root@R210 ~] # cd / opt/Dockerfile/tomcat7
[root@R210 tomcat7] # ls
Apache-tomcat-7.0.70.tar.gz Dockerfile
[root@R210 tomcat7] # cat Dockerfile
FROM java7:7u80MAINTAINER yyENV TOMCAT_VERSION 7.0.70ENV CATALINA_HOME / tomcatENV APP_DIR ${CATALINA_HOME} / webapps/RUN rpm-- rebuilddb\ & & yum-- setopt=tsflags=nodocs-y install\ apr tomcat-native\ & & rm-rf / var/cache/yum/* & & yum clean all#RUN wget-Q https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat -${TOMCAT_MINOR_VERSION} .tar.gz # https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gzCOPY apache-tomcat-$ {TOMCAT_VERSION} .tar.gz apache-tomcat- {TOMCAT_VERSION} .tar.gzRun tar zxf apache-tomcat-*.tar.gz & &\ rm apache-tomcat-*.tar.gz & &\ mv apache-tomcat* tomcat & &\ rm-rf tomcat/webapps/* & &\ sed-I'/ protocol= "AJP\ / 1.3" / d' / tomcat/conf/server.xml EXPOSE 8080 ENTRYPOINT ["/ tomcat/bin/catalina.sh" "run"] ONBUILD ADD. ${APP_DIR}
Make a mirror image
[root@R210 tomcat7] # docker build-t tomcat7:7.0.70.
Launch a tomcat container from the image, deploy the test program to / www/app1/webapps and access it from the browser
[root@R210] # docker run-d-p 8002 name mytomcat7 8080-- name mytomcat7-v / www/app1/webapps/:/tomcat/webapps tomcat7:7.0.70
3. Make database mariadb mirror
[root@XSMM mk_mariadb] # ls
Dockerfile mariadb-func.sh mariadb.repo run.sh
[root@XSMM-WEB mk_mariadb] # cat Dockerfile
FROM centos:latestMAINTAINER yyENV TZ "Asia/Shanghai" ENV TERM xtermCOPY mariadb.repo / etc/yum.repos.d/ RUN\ yum update-y &\ yum install-y epel-release & &\ yum install-y MariaDB-server hostname net-tools pwgen & &\ yum clean all & &\ rm-rf / var/lib/mysql/* & &\ rm-rf / var/cache/yum/*COPY mariadb-func.sh / COPY run. Sh / RUN chmod 755 * .shVOLUME ["/ var/lib/mysql"] EXPOSE 3306CMD ["/ run.sh"]
[root@XSMM-WEB mk_mariadb] # cat mariadb-func.sh
The #! / bin/sh### loop detects whether the database process starts normally, Whether the service is available # function wait_for_db () {set + e echo "wait for the database to start..." While true; do if grep "ready for connections" $ERROR_LOG; then break Else echo "continues to wait for database startup to complete" & & sleep 1 fi done set-e} # shut down the database process # # # function terminate_db () {local pid=$ (cat $VOLUME_HOME/mysql.pid) echo "capture the process signal & shut down the database process." Kill-TERM $pid while true; do if tail $ERROR_LOG | grep-s-E "mysqld. +? ended" $ERROR_LOG; then break; else sleep 0.5; fi done}
# if the data directory is empty Call the mysql_install_db script to generate the default library # global variable: # $VOLUME_HOME# $ERROR_LOG###function install_db () {if [!-d $VOLUME_HOME/mysql] Then echo "= > data directory $VOLUME_HOME is empty and the database is not initialized." Echo "= > installing MariaDB..." Mysql_install_db-- user=mysql > / dev/null 2 > & 1 echo "= > MariaDB installation is complete!" Else echo "= > use data catalog files that already exist." Fi # remove log files left by container operation Keep the logs generated by the current container # if [- f $ERROR_LOG] Then echo "- Previous error log -" tail-n 20 $ERROR_LOG echo "- Previous error log ends -" & & echo mv-f $ERROR_LOG "${ERROR_LOG} .old" Fi touch $ERROR_LOG & & chown mysql $ERROR_LOG} # create user # variable: # $MARIADB_USER# $MARIADB_PASS## # # function create_mysql_user () {echo "Creating DB admin user..." & & echo local users=$ (mysql-s-e "SELECT count (User) FROM mysql.user WHERE User='$MARIADB_USER'") if [[$users= = 0]] Then echo "= > Creating MariaDB user'$MARIADB_USER' with'$MARIADB_PASS' password." Mysql-uroot-e "CREATE USER' $MARIADB_USER'@'%' IDENTIFIED BY'$MARIADB_PASS'" else echo "= > User'$MARIADB_USER' exists, updating its password to'$MARIADB_PASS'" mysql-uroot-e "SET PASSWORD FOR'$MARIADB_USER'@'%' = PASSWORD ('$MARIADB_PASS')" fi Mysql-uroot-e "GRANT ALL PRIVILEGES ON *. * TO'$MARIADB_USER'@'%' WITH GRANT OPTION" echo "= =" echo "can connect to MariaDB Server using the following command:" echo "mysql-u$MARIADB_USER-p$MARIADB_PASS-h" echo " "echo" for security reasons The above password should be changed. Root can log in locally without a password. It is recommended to set the password "echo" = = "} # display the database status # # # # function show_db_status () {echo "Showing DB status..." & & echo mysql-uroot-e "status"} # Clean the database Delete test Library and password-less user # function secure_and_tidy_db () {echo "Delete test Library and password-less user." Mysql-uroot-e "DROP DATABASE IF EXISTS test" mysql-uroot-e "DELETE FROM mysql.user where User =''" # set root users to login only locally # # # mysql-uroot-e "DELETE FROM mysql.user where User = 'root' AND Host NOT IN (' 127.0.0.1' ': 1') "mysql-uroot-e" DELETE FROM mysql.proxies_priv where User =' root' AND Host NOT IN ('127.0.0.1) setting root users can only log in locally! "}
[root@XSMM-WEB mk_mariadb] # cat run.sh
#! / bin/bashset-eset-usource. / mariadb-func.sh# user specifies the database user name and does not provide the default mysql And randomly generate the password MARIADB_USER=$ {MARIADB_USER:= "mysql"} MARIADB_PASS=$ {MARIADB_PASS:-$ (pwgen-s 121)} # specify other necessary environment variables VOLUME_HOME= "/ var/lib/mysql" ERROR_LOG= "$VOLUME_HOME/$HOSTNAME.err" MYSQLD_PID_FILE= "$VOLUME_HOME/$HOSTNAME.pid" # Trap INT and TERM signals to do clean DB shutdowntrap terminate_db SIGINT SIGTERM# call the install_db function install_db# to output all Information to the terminal tail-F $ERROR_LOG & # launch the database to run in the background and record PID/usr/bin/mysqld_safe & MYSQLDdata SAFEmatching PIDs running in the background and recording the script for database process mysqld_safe exiting wait $MYSQLD_SAFE_PID normally
[root@XSMM-WEB mk_mariadb] # cat mariadb.repo
# MariaDB 10.1 CentOS repository list-created 2016-01-06 02:19 UTC# http://mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.1/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
# create an image
[root@XSMM mk_mariadb] # docker build-t mariadb10.
# docker run-- name mydb-d-p 3306purl 3306-v / mydata/mysql/:/var/lib/mysql mariadb10
... > Running in 35b0398fbeb8-> d353c6e1e33bRemoving intermediate container 35b0398fbeb8Step 12: CMD / run.sh-> Running in 7248c5e14559-> 538b64e6987dRemoving intermediate container 7248c5e14559Successfully built 538b64e6987d
[root@XSMM] # docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED SIZEmariadb10 latest 538b64e6987d 4 minutes ago 1.111 GBcentos7-ssh latest 104c3f5a710c 7 days ago 504.1 MBcentos6 latest ba7961b610e2 7 days ago 194.6 MBdocker.io/tomcat latest 3c90608ca58a 8 days ago 357.4 MBdocker.io/centos/redis latest a4b79297fc55 2 weeks ago 405.6 MBdocker.io/centos latest 970633036444 5 weeks ago 196.7 MB
# generate a mariadb container from the image
[root@XSMM] # docker run-- name mydb-d-p 3306 purl 3306-v / mydata/mysql/:/var/lib/mysql mariadb10
7eb4b284406bfb497ee0addf8cda153ab91013f3f9fc3357d856c68ea8a6e658
# View the container log
[root@XSMM] # docker logs mydb
Use existing data catalog files. Wait for the database to start. Continue waiting for database startup to complete... 160910 01:07:05 mysqld_safe Logging to'/ var/lib/mysql/7eb4b284406b.err'.160910 01:07:05 mysqld_safe Starting mysqld daemon with databases from / var/lib/mysql...2016-09-10 1:07:06 139756268353664 [Note] / usr/sbin/mysqld: ready for connections.Version: '10.1.17 MariaDB' socket:'/ var/lib/mysql/mysql.sock' port: 3306 MariaDB Server2016-09-10 1:07:06 139756268353664 [Note] / usr/sbin/mysqld: ready for connections. Delete test libraries and password-less users. Setting root users can only be done from local login! Showing DB status...Creating DB admin user...= > Creating MariaDB user 'mysql' with' tMEpSbAy0lIK' password.==== can connect to MariaDB Server using the following command: mysql-umysql-ptMEpSbAy0lIK-h For security reasons The above password should be changed. Root can log in locally without a password. It is recommended to set the password.
[root@XSMM] # mysql-umysql-ptMEpSbAy0lIK
ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/ var/lib/mysql/mysql.sock' (2)
# connection data testing
[root@XSMM] # mysql-- protocol=tcp-umysql-ptMEpSbAy0lIK
Welcome to the MariaDB monitor. Commands end with; or\ g.Your MariaDB connection id is 10Server version: 10.1.17-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.MariaDB [(none)] > show databases;+-+ | Database | +-+ | information_schema | | mysql | | performance_schema | +-+ 3 rows in set [(none)] >
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.