安装docker & docker-compose
1. Install docker
Ubuntu install Docker
sudo apt-get install docker.io
add docker group
#Add your user to docker group $ sudo usermod -aG docker ubuntu (username)
Restart the server after adding
#reboot
2. Install docker-compose
https://docs.docker.com/compose/install/ which curl # apt-get install curl -y #### libcurl3 libcurl3-dev php5-curl -y # apt-get install python-pip python-dev -y # pip install -U docker-compose
Note: If the following error is prompted, retry the above command with the root account
Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1235, in prepare_files req_to_install.assert_source_matches_version() File "/usr/lib/python2.7/dist-packages/pip/req.py", line 465, in assert_source_matches_version % (display_path(self.source_dir), version, self)) File "/usr/lib/python2.7/dist-packages/pip/util.py", line 70, in display_path if path.startswith(os.getcwd() + os.path.sep): UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 11: ordinal not in range(128) Storing debug log for failure in /home/ccid/.pip/pip.log
Or can also be added in the following way
$sudo curl -L https://github.com/docker/compose/releases/download/1.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose $sudo chmod +x /usr/local/bin/docker-compose $sudo docker-compose --v
Note: If the docker-compose version is prompted such as "docker-compose version 1.7.1, build 6c29830", the installation is successful
. Note: If you get a "Permission denied" error message during installation, it means that your /usr/local/ The bin directory is not writable, you need to use superuser to install.
Run sudo -i , then run the two commands above, then exit.
Install and configure Docker private registry
Docker is first installed successfully;
Create a directory to hold the image and certificate:
$sudo mkdir -p /opt/docker/registry/data $sudo mkdir -p /opt/docker/registry/certs
Docker's private registry requires https access. Need to generate ssl certificate.
$cd /opt/docker/registry/ $which openssl $ sudo apt-get install openssl libssl-dev (libssl-dev:openssl development library) $openssl genrsa -out registry_tr_com.key 2048 $openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/registry_tr_com.key -x509 -days 365 -out certs/registry_tr_com.crt
Here is the output, some information needs to be filled in:
Generating a 4096 bit RSA private key ........................................++ ..........................................++ writing new private key to 'certs/registry_tr_com.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:BeiJing Locality Name (eg, city) []:BeiJing Organization Name (eg, company) [Internet Widgits Pty Ltd]:TR Organizational Unit Name (eg, section) []:TR Common Name (e.g. server FQDN or YOUR name) []:registry.tr.com Email Address []:
Note: The Common Name in the above prompt must add the full domain name
Edit /opt/docker/registry/docker-compose.yml with an editor, the content is as follows:
docker/registry is the docker_registry of the source document) registry: container_name : tr_registry restart : always image : registry:2 ports: - 443:5000 environment: REGISTRY_HTTP_TLS_CERTIFICATE: /certs/registry_tomhat_com.crt REGISTRY_HTTP_TLS_KEY: /certs/registry_tr_com.key volumes: - /opt/docker/registry/data:/var/lib/registry - /opt/docker/registry/certs:/certs
Note: text format;
Install docker-compose
Start the registry container with docker-compose.
# docker-compose up -d
Note: Use the root user to execute the command in the directory where docker-compose.yml is located
The following is the correct prompt
Pulling registry (registry:2)... 2: Pulling from library/registry efd26ecc9548: Pull complete a3ed95caeb02: Pull complete 39091a8d8094: Pull complete c5ad04c01f33: Pull complete e441cc69d374: Pull complete Digest: sha256:5206f99cc4d06dedc6d291324935ef134001f30fe05bf47e8d0b58d7e93e3843 Status: Downloaded newer image for registry:2 Creating cops_registry
Copy the certificate to other nodes;
# scp /opt/docker_registry/certs/registry_tr_com.crt user@ip address:/rootPlease switch to the node, install the certificate and restart the docker service.
# mkdir -p /etc/docker/certs.d/registry.tr.com # cp /root/registry_tomhat_com.crt /etc/docker/certs.d/registry.tr.com # service docker restartPush tomcat mirror to private library
method is 1. Pull the tomcat image locally from our company's private library. Add the company's private library (ip registry.tr.com) to hosts, and put the private library key in the /etc/docker/certs.d/registry.tr.com/ directory 2. Modify the tag of the tomcat image 3. Push the tomcat image to the self-built warehouse Since the private library (registry.tr.com) created in this document has the same name as our company's private library, node1 and jenkins resolve registry.tr.com in the /etc/hosts file to be private for the private network address library, and the tomcat image required here is in my company's private library (public network address). So the operation should be performed on the gitlab node (the secret key and hosts file to access our company's private warehouse are configured on the gitlib node) The specific operations are as follows # docker pull registry.tr.com/tomcat $sudo docker images Get the image id of the tomcat image here is 660259e51042 # docker tag 660259e51042 registry.tr.com/tomcat Modify the hosts file to change the resolution of registry.tr.com to the private network address (127.0.0.1) and replace the /etc/docker/certs.d/registry.tr.com/registry_tr_com.crt file (this file can be downloaded from the same directory of the node1 node) obtained below) Restart docker after placing registry.tr.com.crt # sudo service docker restart # docker push registry.tr.com/tomcat push image to private repository Visit https://127.0.0.1/v2/_catalog through a browser to check whether the image is pushed successfully.Visit: http://ip/v2/_catalog
Install gitlab server
1. Install certificate and pull image
Docker first installed successfully
First configure the host
and configure the registry's host. The
command is as follows
#echo "ip registry.ecloud.com.cn" >> /etc/hosts`############There is an installation certificate here, provided by development ###########
Install the certificate to /etc/docker/certs.d/registry.tr.com/
The commands and methods are as follows
Upload the certificate file to the server. The winscp tool can be used under Windows, and this method can be used under Linux .
"#Scp -i wendangmiyao.pem registry_tr_com.crt [email protected]: / home / ubuntu"
.crt, is the certificate file, and .pem is the key file used to log in to the server.
Create a certificate storage directory on the server and copy the certificate into it
# mkdir -p /etc/docker/certs.d/registry.tr.com # cp /home/ubuntu/registry_tr_com.crt /etc/docker/certs.d/registry.tr.com/restart the docker service
# service docker restart
Next pull the images of gitlab.
# docker pull registry.tr.com/sameersbn/gitlab:8.2.0 # docker pull registry.tr.com/sameersbn/redis:latest # docker pull registry.tr.com/mysql:5.7
Install docker-compose.
Check the installation method above;
Create data directories for MySQL and gitlab
$sudo mkdir -p /opt/data/mysql $sudo mkdir -p /opt/data/gitlab
Create a new file docker-compose.yml with the following content:
mysql: container_name: mysql image: registry.tr.com/mysql:5.7 environment: #mysql password:mysql - MYSQL_ROOT_PASSWORD=mysql volumes: - /opt/data/mysql:/var/lib/mysql say again: # container_name: redis image: registry.tr.com/sameersbn/redis:latest gitlab: image: registry.tr.com/sameersbn/gitlab:8.2.0 command: app:start container_name: gitlab ports: - "80:80" - "8443:443" environment: #project url http://GITLAB_HOST/project/xxxx.git - GITLAB_HOST=gitlab.tr.com - DB_USER=gitlab - DB_PASS=1q2w3e4r - DB_NAME=gitlabhq_production - GITLAB_TIMEZONE=Beijing - GITLAB_GRAVATAR_ENABLED=false - GITLAB_BACKUPS=daily - NGINX_MAX_UPLOAD_SIZE=100m - "UNICORN_TIMEOUT=120" - GITLAB_SECRETS_DB_KEY_BASE=fvXhxg7tthcg4jpxpfg9MbrWJbbHTqsRj3xpLNxdrMpsWmgnMNjRdhc73qX7dsgz - DEBUG=1 volumes: - /opt/data/gitlab:/home/git/data links: - mysql:mysql - redis:redisio
start the container
# docker-compose up -d
If it doesn't start up, it means that the format of the file you just configured is wrong. Please adjust the format of the configuration file.
Log in to the mysql container, create the required database , and add authorization.
$sudo docker exec -it mysql bash $mysql -u root -pmysql
The password of the mysql root user is mysql.
Then execute the following SQL.
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'%' IDENTIFIED BY '1q2w3e4r'; FLUSH PRIVILEGES; #exit exit the mysql container
Login to the Gitlab container
# docker exec -it gitlab bash
Execute the following command in the container to initialize Gitlab.
$ /sbin/entrypoint.sh app:rake gitlab:setup
After the initialization is completed, the prompt is as follows:
login.........root password......5iveL!fe
This is the admin login user of gitlab.
Use this user to log in to gitlab, the first login will ask to change the password (here is changed to tr.com).
Access through the host ip such as http://ip/users/sign_in
The following is used by jenkins to
log gitlab homepage, click Profile settings->Account, the private token of the current user will be displayed here, please save this value to a text file, which will be used later in Jenkins (here is CVufh7Bs82ohsaWEa6mv).
Gitlab data migration and upgrade
Tip: Before deploying gitlab data migration, first check the version number of gitlab on host A.
The host A shown below is the original host. Host B is the migration destination host.
The gitlab version of host A is 8.2.2.
Data migration must ensure that the gitlab version numbers of host A and host B are the same.
data migration
Operate on host A:
1. There is no automatic backup configuration when deploying the gitlab container. Create a backup first. ubuntu@gitlab ~ $: docker stop gitlab stops the currently running gitlab container eg: docker stop gitlab Note: gitlab is the name of the container. 2. ubuntu@gitlab ~ $: docker rm gitlab delete the currently existing gitlab container eg: docker rm gitlab Note: gitlab is the name of the container
Note: Please ignore the next step if automatic backup is set when the gitla container is created. Directly export the most recent backup file under /opt/data/gitlab/backup/.
3. ubuntu@gitlab ~ $: docker run --name gitlab --rm -ti -p 80:80 -p 8443:443 --link mysql:mysql --link redis:redisio -e "DB_USER=gitlab" -e "DB_PASS=1q2w3e4r" -e "DB_NAME=gitlabhq_production" -e "GITLAB_HOST=gitlab.dev.ecloud.com.cn" -e "GITLAB_TIMEZONE=Beijing" -e "GITLAB_GRAVATAR_ENABLED=false" -e 'GITLAB_BACKUPS=daily' -e "NGINX_MAX_UPLOAD_SIZE=100m" -e "UNICORN_TIMEOUT=120" -e "GITLAB_SECRETS_DB_KEY_BASE=fvXhxg7tthcg4jpxpfg9MbrWJbbHTqsRj3xpLNxdrMpsWmgnMNjRdhc73qX7dsgbackup:v /opt/gitlab/data:/home/git/data app:rake run create gitlab:/home/git/data app:rake bn/gitlab: This command will generate the compressed file as shown below in the /opt/data/gitlab/backup directory mounted when the gitlab container is created.
-p 80:80 open port 80 mapping host port 80 -p 8443:443 open port 443 mapping host port 8443 --name gitlab container name is gitlab -rm removes the container when the container is stopped. --link mysql:mysql Connect to the mysql container mysql: mysql is the container name. --link redis:redisio Connect to the redis container redis: redis is the container name. -e "DB_USER=gitlab" environment variable DB_USER gitlab is the mysql user name. -e "DB_PASS=1q2w3e4r" environment variable DB_PASS 1q2w3e4r is the password of the gitlab username. -e "DB_NAME=gitlabhq_production" environment variable DB_NAME gitlabhq_production is the database name. -e "GITLAB_HOST=gitlab.dev.ecloud.com.cn" environment variable GITLAB_HOST gitlab.dev.ecloud.com.cn is the access address, customized. -e 'GITLAB_BACKUPS=daily' environment variable GITLAB_BACKUP daily for daily backup. sameersbn/gitlab:8.2.2 Image name.Operation on host B:
Copy the files in this backup directory to the directory of the host you need to migrate. Create gitlab: 8.2.2 container, and build the environment of gitlab on the host machine. Tip: For detailed steps, please refer to the above deployment: 3. Install Gitlab server
Copy the backup file migrated from host A to /opt/data/gitlab/baskup, and run the following command to restore the backup. ubuntu@gitlab ~ $:docker run --name gitlab --rm -ti -p 80:80 -p 8443:443 --link mysql:mysql --link redis:redisio -e "DB_USER=gitlab" -e "DB_PASS=1q2w3e4r" -e "DB_NAME=gitlabhq_production" -e "GITLAB_HOST=gitlab.dev.ecloud.com.cn" -e "GITLAB_TIMEZONE=Beijing" -e "GITLAB_GRAVATAR_ENABLED=false" -e 'GITLAB_BACKUPS=daily' -e "NGINX_MAX_UPLOAD_SIZE=100m" -e "UNICORN_TIMEOUT=120" -e "GITLAB_SECRETS_DB_KEY_BASE=fvXhxg7tthcg4jpxpfg9MbrWJbbHTqsRj3xpLNxdrMpsWmgnMNjRdhc73qX7dsgz" -v /opt/gitlab/data:/home/git/data sameersbn/gitlab:8.2.2 app:rake gitlab:backup:restore Or the following command: ubuntu@gitlab ~ $:docker run --name gitlab -it --rm [OPTIONS] IMAGE:8.2.2 app:rake gitlab:backup:restore BACKUP=1417624827 The specific content is as above.
Note: 1417624827 is the file in the /opt/data/gitlab/backup
directory: 1417624827_gitlab_back.tar
4. Run the gitlab container: ubuntu@gitlab ~ $: docker run --name gitlab -d [OPTIONS] IMAGE: 8.2.2 This container is the gitlab container that has been migrated. The specific content is as above.
upgrade
Run steps 1 and 2 to stop and delete the gitlab container. ubuntu@gitlab ~ $:docker run --name gitlab -d [OPTIONS] IMAGE:8.8.5 The specific content is as above.
ok,
it has been successful,
if you have any questions, please ask and share