变废为宝。
服务器没怎么用,但是偶尔又想访问下文档或者redmine,狠狠心咬咬牙最后把x64上的迁移到了树莓派2: Raspbian GNU/Linux 9 (stretch) 。
温故下原来redmine的安装过程: Redmine部署以及插件安装
过程中涉及到了docker的重新编译,这其中主要使用ubuntu apt源码在本地arm上进行再编译。其中涉及的镜像有:
备份
redmine直接整个目录打包 /srv/docker/redmine/redmine 。数据库的要备份出来,架构不同不兼容。
这是编译后arm postgres直接用x64的/srv/docker/redmine/postgresql的报错信息:
1
2
3
4
5
6
7
8
9
10
root@raspberrypi:~# docker run --rm -ti --entrypoint="bash" -v /srv/docker/redmine/postgresql:/var/lib/postgresql sameersbn/postgresql:9.6-2
root@8f39c2904607:/var/lib/postgresql# sudo -HEu postgres /usr/lib/postgresql/9.6/bin/pg_ctl -D /var/lib/postgresql/9.6/main -w start
waiting for server to start....FATAL: database files are incompatible with server
DETAIL: The database cluster was initialized with USE_FLOAT8_BYVAL but the server was compiled without USE_FLOAT8_BYVAL.
HINT: It looks like you need to recompile or initdb.
LOG: database system is shut down
stopped waiting
pg_ctl: could not start server
Examine the log output.
编译ubuntu镜像
直接使用最新的trusty发布版镜像。由于低版本的可能会没有 linux/arm/v7 : https://hub.docker.com/_/ubuntu/?tab=tags&page=1&name=trusty
1
2
3
4
5
root@raspberrypi:~/docker-ubuntu# vi Dockerfile
FROM ubuntu:trusty
docker build -t sameersbn/ubuntu:14.04.20170123 .
docker tag sameersbn/ubuntu:14.04.20170123 sameersbn/ubuntu:14.04.20170711
编译postgres镜像
由于postgresql apt的库中没有armhf的deb,需要先手动编译好对应的deb。先运行一个容器,再里面编译好postgres。
1
2
3
4
5
6
7
8
9
10
11
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb-src http://mirrors.zju.edu.cn/postgresql/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list \
&& sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list \
&& apt-get update
root@7d55994af11e:/# apt-get build-dep dh-exec postgresql-common pgdg-keyring
root@7d55994af11e:/# apt-get source --compile dh-exec postgresql-common pgdg-keyring
root@7d55994af11e:/# apt-get build-dep postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} dh-exec
root@7d55994af11e:/# apt-get source --compile postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION}
再测试安装一下这些deb:
1
2
3
4
5
6
7
8
9
10
11
12
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb-src http://mirrors.zju.edu.cn/postgresql/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list \
&& sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list \
&& apt-get update
apt-get install -y acl \
libpipeline1 debhelper ssl-cert libxml2 libedit2 libxslt1.1 libperl5.18 libpython2.7 libpython3.4 libtcl8.6
dpkg -i pgdg-keyring_2018.2_all.deb postgresql-common_201.pgdg14.04+1_all.deb postgresql-client-common_201.pgdg14.04+1_all.deb
dpkg -i libpq5_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-9.6_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-client-9.6_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-contrib-9.6_9.6.13-1.pgdg14.04+1_armhf.deb
修改Dockerfile,直接通过dpkg安装postgresql的deb:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@raspberrypi:~/docker-postgresql# less Dockerfile
...
COPY deb/ /tmp/psql/
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb-src http://mirrors.zju.edu.cn/postgresql/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list \
&& sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y acl \
libpipeline1 debhelper ssl-cert libxml2 libedit2 libxslt1.1 libperl5.18 libpython2.7 libpython3.4 libtcl8.6 \
&& cd /tmp/psql \
&& dpkg -i pgdg-keyring_2018.2_all.deb postgresql-common_201.pgdg14.04+1_all.deb postgresql-client-common_201.pgdg14.04+1_all.deb \
&& dpkg -i libpq5_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-9.6_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-client-9.6_9.6.13-1.pgdg14.04+1_armhf.deb postgresql-contrib-9.6_9.6.13-1.pgdg14.04+1_armhf.deb \
&& rm -rf /tmp/psql \
...
root@raspberrypi:~/docker-postgresql# docker build -t sameersbn/postgresql:9.6-2 .
编译redmine镜像
redmine主要是缺少ruby2.3的包,跟上面的步骤类似。先编译出arm的ruby2.3,再编译镜像。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list \
&& sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
apt-get build-dep ruby${RUBY_VERSION} ruby${RUBY_VERSION}-dev
apt-get source --compile ruby${RUBY_VERSION} ruby${RUBY_VERSION}-dev
root@raspberrypi:~/docker-redmine# vi Dockerfile
...
COPY deb/ /tmp/ruby/
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv E1DD270288B4E6030699E45FA1715D88E1DF1F24 \
&& echo "deb http://ppa.launchpad.net/git-core/ppa/ubuntu trusty main" >> /etc/apt/sources.list \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv 80F70E11F0F0D5F10CB20E62F5DA5F09C3173AA6 \
&& echo "deb http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu trusty main" >> /etc/apt/sources.list \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv 8B3981E7A6852F782CC4951600A6F0A3C300EE8C \
&& echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main" >> /etc/apt/sources.list \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb-src http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list \
&& sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y supervisor logrotate nginx mysql-client postgresql-client \
imagemagick subversion git cvs bzr mercurial darcs rsync locales openssh-client \
gcc g++ make patch pkg-config gettext-base libc6-dev zlib1g-dev libxml2-dev \
libmysqlclient18 libpq5 libyaml-0-2 libcurl3 libssl1.0.0 uuid-dev xz-utils \
libxslt1.1 libffi6 zlib1g gsfonts \
libgmpxx4ldbl libgmp-dev libtk8.5 libxft2 libxrender1 libxss1 x11-common libtcl8.5 rubygems-integration \
&& dpkg -i /tmp/ruby/*.deb \
&& rm -rf /tmp/ruby \
&& update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
&& gem install --no-document --version '< 2.0' bundler \
&& rm -rf /var/lib/apt/lists/*
...
root@raspberrypi:~/docker-redmine# docker build -t sameersbn/redmine:3.4.6 .
如果docker构建失败,可以通过以下两种方式来进行调试:
1
2
3
4
5
6
7
8
# 1
docker commit $container-id image-id
docker run -ti $image-id bash
# 2
失败也会有前一步骤的镜像已经提交,再次基础上检查后面的步骤
The last successful step is 2. It produced an image a3acfa4ab179. Now you start a container
docker run -it a3acfa4ab179 bash
结合原有数据进行迁移
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 备份
psql -U postgres -cC --if-exists -d redmine_production >redmine.dump
# 安装compose
root@raspberrypi:~/redmine/bin# python -m pip install --upgrade pip
root@raspberrypi:~/redmine/bin# pip install docker-compose
# 启动
root@raspberrypi:~/redmine/bin# docker-compose up -d
# 数据库还原
docker cp redmine.dump e472d9ec3124:/var/lib/postgresql/
psql -U postgres <redmine.dump
# redmine修复
root@3f0774db222d:/home/redmine/redmine# apt-get install libmysqlclient-dev
https://stackoverflow.com/questions/13086073/rails-install-pg-cant-find-the-libpq-fe-h-header
root@3f0774db222d:/home/redmine/redmine# apt-get install libpq-dev
https://stackoverflow.com/questions/38200015/package-magickcore-was-not-found-in-the-pkg-config-search-path
root@3f0774db222d:/home/redmine/redmine# apt-get install libmagickwand-dev
root@3f0774db222d:/home/redmine/redmine# bundle install
后面就直接安装docker-compose.yml中的端口映射配置访问即可。
–END