Upgrade Postgresql from 9.6 to 11 with different data directory
You can specify a custom data_directory as an optional parameter to the command pg_upgradecluster:

pg_upgradecluster [-v newversion] oldversion name [newdatadir]


So for your case, it should be:

sudo pg_upgradecluster -m upgrade 9.6 main /opt/postgresql/11/main


Note that you must first remove any existing cluster at the specified location (/opt/postgresql/11/main) and create an empty directory with the correct owner before running pg_upgradecluster:

sudo pg_dropcluster --stop 11 main
sudo mkdir -p /opt/postgresql/11/main
sudo chown postgres:postgres /opt/postgresql/11/main